1 from __future__ import unicode_literals
5 from .subtitles import SubtitlesInfoExtractor
6 from .common import ExtractorError
7 from ..utils import parse_iso8601
10 class DRTVIE(SubtitlesInfoExtractor):
11 _VALID_URL = r'http://(?:www\.)?dr\.dk/tv/se/(?:[^/]+/)+(?P<id>[\da-z-]+)(?:[/#?]|$)'
14 'url': 'http://www.dr.dk/tv/se/partiets-mand/partiets-mand-7-8',
15 'md5': '4a7e1dd65cdb2643500a3f753c942f25',
17 'id': 'partiets-mand-7-8',
19 'title': 'Partiets mand (7:8)',
20 'description': 'md5:a684b90a8f9336cd4aab94b7647d7862',
21 'timestamp': 1403047940,
22 'upload_date': '20140617',
27 def _real_extract(self, url):
28 mobj = re.match(self._VALID_URL, url)
29 video_id = mobj.group('id')
31 programcard = self._download_json(
32 'http://www.dr.dk/mu/programcard/expanded/%s' % video_id, video_id, 'Downloading video JSON')
34 data = programcard['Data'][0]
37 description = data['Description']
38 timestamp = parse_iso8601(data['CreatedTime'][:-5])
43 restricted_to_denmark = False
48 for asset in data['Assets']:
49 if asset['Kind'] == 'Image':
50 thumbnail = asset['Uri']
51 elif asset['Kind'] == 'VideoResource':
52 duration = asset['DurationInMilliseconds'] / 1000.0
53 restricted_to_denmark = asset['RestrictedToDenmark']
54 for link in asset['Links']:
55 target = link['Target']
58 'url': uri + '?hdcore=3.3.0&plugin=aasp-3.3.0.99.43' if target == 'HDS' else uri,
60 'ext': link['FileFormat'],
61 'preference': -1 if target == 'HDS' else -2,
63 subtitles_list = asset.get('SubtitlesList')
64 if isinstance(subtitles_list, list):
68 for subs in subtitles_list:
69 lang = subs['Language']
70 subtitles[LANGS.get(lang, lang)] = subs['Uri']
72 if not formats and restricted_to_denmark:
74 'Unfortunately, DR is not allowed to show this program outside Denmark.', expected=True)
76 self._sort_formats(formats)
78 if self._downloader.params.get('listsubtitles', False):
79 self._list_available_subtitles(video_id, subtitles)
85 'description': description,
86 'thumbnail': thumbnail,
87 'timestamp': timestamp,
90 'subtitles': self.extract_subtitles(video_id, subtitles),