~ubuntu-branches/ubuntu/vivid/youtube-dl/vivid

« back to all changes in this revision

Viewing changes to youtube_dl/extractor/nrk.py

  • Committer: Package Import Robot
  • Author(s): Rogério Brito
  • Date: 2015-03-01 02:12:13 UTC
  • mfrom: (44.1.24 sid)
  • Revision ID: package-import@ubuntu.com-20150301021213-8w657cue71kp77sz
Tags: 2015.02.28-1
Imported Upstream version 2015.02.28. Closes: #778765.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
import re
5
5
 
6
6
from .common import InfoExtractor
 
7
from ..compat import compat_str
7
8
from ..utils import (
8
9
    ExtractorError,
9
10
    float_or_none,
10
11
    parse_duration,
11
12
    unified_strdate,
12
13
)
13
 
from .subtitles import SubtitlesInfoExtractor
14
14
 
15
15
 
16
16
class NRKIE(InfoExtractor):
73
73
        }
74
74
 
75
75
 
76
 
class NRKTVIE(SubtitlesInfoExtractor):
 
76
class NRKTVIE(InfoExtractor):
77
77
    _VALID_URL = r'(?P<baseurl>http://tv\.nrk(?:super)?\.no/)(?:serie/[^/]+|program)/(?P<id>[a-zA-Z]{4}\d{8})(?:/\d{2}-\d{2}-\d{4})?(?:#del=(?P<part_id>\d+))?'
78
78
 
79
79
    _TESTS = [
156
156
        if self._downloader.params.get('verbose', False):
157
157
            self.to_screen('[debug] %s' % txt)
158
158
 
159
 
    def _extract_captions(self, subtitlesurl, video_id, baseurl):
 
159
    def _get_subtitles(self, subtitlesurl, video_id, baseurl):
160
160
        url = "%s%s" % (baseurl, subtitlesurl)
161
161
        self._debug_print('%s: Subtitle url: %s' % (video_id, url))
162
 
        captions = self._download_xml(url, video_id, 'Downloading subtitles')
 
162
        captions = self._download_xml(
 
163
            url, video_id, 'Downloading subtitles',
 
164
            transform_source=lambda s: s.replace(r'<br />', '\r\n'))
163
165
        lang = captions.get('lang', 'no')
164
166
        ps = captions.findall('./{0}body/{0}div/{0}p'.format('{http://www.w3.org/ns/ttml}'))
165
167
        srt = ''
168
170
            duration = parse_duration(p.get('dur'))
169
171
            starttime = self._seconds2str(begin)
170
172
            endtime = self._seconds2str(begin + duration)
171
 
            text = '\n'.join(p.itertext())
172
 
            srt += '%s\r\n%s --> %s\r\n%s\r\n\r\n' % (str(pos), starttime, endtime, text)
173
 
        return {lang: srt}
 
173
            srt += '%s\r\n%s --> %s\r\n%s\r\n\r\n' % (compat_str(pos), starttime, endtime, p.text)
 
174
        return {lang: [
 
175
            {'ext': 'ttml', 'url': url},
 
176
            {'ext': 'srt', 'data': srt},
 
177
        ]}
174
178
 
175
179
    def _extract_f4m(self, manifest_url, video_id):
176
180
        return self._extract_f4m_formats(manifest_url + '?hdcore=3.1.1&plugin=aasp-3.1.1.69.124', video_id)
243
247
            webpage, 'subtitle URL', default=None)
244
248
        subtitles = None
245
249
        if subtitles_url:
246
 
            subtitles = self._extract_captions(subtitles_url, video_id, baseurl)
247
 
        if self._downloader.params.get('listsubtitles', False):
248
 
            self._list_available_subtitles(video_id, subtitles)
249
 
            return
 
250
            subtitles = self.extract_subtitles(subtitles_url, video_id, baseurl)
250
251
 
251
252
        return {
252
253
            'id': video_id,