]>
Commit | Line | Data |
---|---|---|
f2b8db57 S |
1 | from __future__ import unicode_literals |
2 | ||
18c1c424 | 3 | from .common import InfoExtractor, ExtractorError |
803540e8 | 4 | from ..utils import parse_iso8601 |
f2b8db57 S |
5 | |
6 | ||
18c1c424 | 7 | class DRTVIE(InfoExtractor): |
ef1269fb | 8 | _VALID_URL = r'https?://(?:www\.)?dr\.dk/tv/se/(?:[^/]+/)*(?P<id>[\da-z-]+)(?:[/#?]|$)' |
f2b8db57 S |
9 | |
10 | _TEST = { | |
11 | 'url': 'http://www.dr.dk/tv/se/partiets-mand/partiets-mand-7-8', | |
12 | 'md5': '4a7e1dd65cdb2643500a3f753c942f25', | |
13 | 'info_dict': { | |
14 | 'id': 'partiets-mand-7-8', | |
15 | 'ext': 'mp4', | |
16 | 'title': 'Partiets mand (7:8)', | |
17 | 'description': 'md5:a684b90a8f9336cd4aab94b7647d7862', | |
18 | 'timestamp': 1403047940, | |
19 | 'upload_date': '20140617', | |
20 | 'duration': 1299.040, | |
21 | }, | |
22 | } | |
23 | ||
24 | def _real_extract(self, url): | |
6ad4013d | 25 | video_id = self._match_id(url) |
f2b8db57 | 26 | |
78271e33 S |
27 | webpage = self._download_webpage(url, video_id) |
28 | ||
29 | video_id = self._search_regex( | |
30 | r'data-(?:material-identifier|episode-slug)="([^"]+)"', | |
31 | webpage, 'video id') | |
f2b8db57 | 32 | |
78271e33 S |
33 | programcard = self._download_json( |
34 | 'http://www.dr.dk/mu/programcard/expanded/%s' % video_id, | |
35 | video_id, 'Downloading video JSON') | |
f2b8db57 S |
36 | data = programcard['Data'][0] |
37 | ||
38 | title = data['Title'] | |
39 | description = data['Description'] | |
6ad4013d | 40 | timestamp = parse_iso8601(data['CreatedTime']) |
f2b8db57 S |
41 | |
42 | thumbnail = None | |
43 | duration = None | |
44 | ||
45 | restricted_to_denmark = False | |
46 | ||
47 | formats = [] | |
48 | subtitles = {} | |
49 | ||
50 | for asset in data['Assets']: | |
51 | if asset['Kind'] == 'Image': | |
52 | thumbnail = asset['Uri'] | |
53 | elif asset['Kind'] == 'VideoResource': | |
54 | duration = asset['DurationInMilliseconds'] / 1000.0 | |
55 | restricted_to_denmark = asset['RestrictedToDenmark'] | |
6d2749aa | 56 | spoken_subtitles = asset['Target'] == 'SpokenSubtitles' |
f2b8db57 S |
57 | for link in asset['Links']: |
58 | target = link['Target'] | |
59 | uri = link['Uri'] | |
6d2749aa JMF |
60 | format_id = target |
61 | preference = -1 if target == 'HDS' else -2 | |
62 | if spoken_subtitles: | |
63 | preference -= 2 | |
64 | format_id += '-spoken-subtitles' | |
f2b8db57 S |
65 | formats.append({ |
66 | 'url': uri + '?hdcore=3.3.0&plugin=aasp-3.3.0.99.43' if target == 'HDS' else uri, | |
6d2749aa | 67 | 'format_id': format_id, |
f2b8db57 | 68 | 'ext': link['FileFormat'], |
6d2749aa | 69 | 'preference': preference, |
f2b8db57 S |
70 | }) |
71 | subtitles_list = asset.get('SubtitlesList') | |
72 | if isinstance(subtitles_list, list): | |
73 | LANGS = { | |
74 | 'Danish': 'dk', | |
75 | } | |
76 | for subs in subtitles_list: | |
77 | lang = subs['Language'] | |
18c1c424 | 78 | subtitles[LANGS.get(lang, lang)] = [{'url': subs['Uri'], 'ext': 'vtt'}] |
f2b8db57 S |
79 | |
80 | if not formats and restricted_to_denmark: | |
81 | raise ExtractorError( | |
82 | 'Unfortunately, DR is not allowed to show this program outside Denmark.', expected=True) | |
83 | ||
84 | self._sort_formats(formats) | |
85 | ||
f2b8db57 S |
86 | return { |
87 | 'id': video_id, | |
88 | 'title': title, | |
89 | 'description': description, | |
90 | 'thumbnail': thumbnail, | |
91 | 'timestamp': timestamp, | |
92 | 'duration': duration, | |
93 | 'formats': formats, | |
18c1c424 | 94 | 'subtitles': subtitles, |
f2b8db57 | 95 | } |