]>
Commit | Line | Data |
---|---|---|
7d254639 | 1 | # coding: utf-8 |
f2b8db57 S |
2 | from __future__ import unicode_literals |
3 | ||
1335c3ac S |
4 | from .common import InfoExtractor |
5 | from ..utils import ( | |
6 | ExtractorError, | |
6066d03d S |
7 | int_or_none, |
8 | float_or_none, | |
9 | mimetype2ext, | |
1335c3ac | 10 | parse_iso8601, |
5e9e3d0f | 11 | remove_end, |
1335c3ac | 12 | ) |
f2b8db57 S |
13 | |
14 | ||
18c1c424 | 15 | class DRTVIE(InfoExtractor): |
5e9e3d0f | 16 | _VALID_URL = r'https?://(?:www\.)?dr\.dk/(?:tv/se|nyheder)/(?:[^/]+/)*(?P<id>[\da-z-]+)(?:[/#?]|$)' |
f2b8db57 | 17 | |
5e9e3d0f | 18 | _TESTS = [{ |
3fcce302 S |
19 | 'url': 'https://www.dr.dk/tv/se/boern/ultra/klassen-ultra/klassen-darlig-taber-10', |
20 | 'md5': '25e659cccc9a2ed956110a299fdf5983', | |
f2b8db57 | 21 | 'info_dict': { |
3fcce302 | 22 | 'id': 'klassen-darlig-taber-10', |
f2b8db57 | 23 | 'ext': 'mp4', |
3fcce302 S |
24 | 'title': 'Klassen - Dårlig taber (10)', |
25 | 'description': 'md5:815fe1b7fa656ed80580f31e8b3c79aa', | |
26 | 'timestamp': 1471991907, | |
27 | 'upload_date': '20160823', | |
28 | 'duration': 606.84, | |
29 | }, | |
30 | 'params': { | |
31 | 'skip_download': True, | |
f2b8db57 | 32 | }, |
5e9e3d0f SB |
33 | }, { |
34 | 'url': 'https://www.dr.dk/nyheder/indland/live-christianias-rydning-af-pusher-street-er-i-gang', | |
3fcce302 | 35 | 'md5': '2c37175c718155930f939ef59952474a', |
5e9e3d0f SB |
36 | 'info_dict': { |
37 | 'id': 'christiania-pusher-street-ryddes-drdkrjpo', | |
38 | 'ext': 'mp4', | |
39 | 'title': 'LIVE Christianias rydning af Pusher Street er i gang', | |
40 | 'description': '- Det er det fedeste, der er sket i 20 år, fortæller christianit til DR Nyheder.', | |
41 | 'timestamp': 1472800279, | |
42 | 'upload_date': '20160902', | |
43 | 'duration': 131.4, | |
3fcce302 | 44 | }, |
5e9e3d0f | 45 | }] |
f2b8db57 S |
46 | |
47 | def _real_extract(self, url): | |
6ad4013d | 48 | video_id = self._match_id(url) |
f2b8db57 | 49 | |
78271e33 S |
50 | webpage = self._download_webpage(url, video_id) |
51 | ||
aff84bec S |
52 | if '>Programmet er ikke længere tilgængeligt' in webpage: |
53 | raise ExtractorError( | |
54 | 'Video %s is not available' % video_id, expected=True) | |
55 | ||
78271e33 | 56 | video_id = self._search_regex( |
5e9e3d0f SB |
57 | (r'data-(?:material-identifier|episode-slug)="([^"]+)"', |
58 | r'data-resource="[^>"]+mu/programcard/expanded/([^"]+)"'), | |
78271e33 | 59 | webpage, 'video id') |
f2b8db57 | 60 | |
78271e33 S |
61 | programcard = self._download_json( |
62 | 'http://www.dr.dk/mu/programcard/expanded/%s' % video_id, | |
63 | video_id, 'Downloading video JSON') | |
f2b8db57 S |
64 | data = programcard['Data'][0] |
65 | ||
6066d03d S |
66 | title = remove_end(self._og_search_title( |
67 | webpage, default=None), ' | TV | DR') or data['Title'] | |
68 | description = self._og_search_description( | |
69 | webpage, default=None) or data.get('Description') | |
5e9e3d0f | 70 | |
6066d03d | 71 | timestamp = parse_iso8601(data.get('CreatedTime')) |
f2b8db57 S |
72 | |
73 | thumbnail = None | |
74 | duration = None | |
75 | ||
76 | restricted_to_denmark = False | |
77 | ||
78 | formats = [] | |
79 | subtitles = {} | |
80 | ||
81 | for asset in data['Assets']: | |
6066d03d S |
82 | if asset.get('Kind') == 'Image': |
83 | thumbnail = asset.get('Uri') | |
84 | elif asset.get('Kind') == 'VideoResource': | |
85 | duration = float_or_none(asset.get('DurationInMilliseconds'), 1000) | |
86 | restricted_to_denmark = asset.get('RestrictedToDenmark') | |
87 | spoken_subtitles = asset.get('Target') == 'SpokenSubtitles' | |
88 | for link in asset.get('Links', []): | |
89 | uri = link.get('Uri') | |
90 | if not uri: | |
91 | continue | |
92 | target = link.get('Target') | |
93 | format_id = target or '' | |
1335c3ac | 94 | preference = None |
6d2749aa | 95 | if spoken_subtitles: |
1335c3ac | 96 | preference = -1 |
6d2749aa | 97 | format_id += '-spoken-subtitles' |
1335c3ac S |
98 | if target == 'HDS': |
99 | formats.extend(self._extract_f4m_formats( | |
100 | uri + '?hdcore=3.3.0&plugin=aasp-3.3.0.99.43', | |
101 | video_id, preference, f4m_id=format_id)) | |
102 | elif target == 'HLS': | |
103 | formats.extend(self._extract_m3u8_formats( | |
6066d03d S |
104 | uri, video_id, 'mp4', entry_protocol='m3u8_native', |
105 | preference=preference, m3u8_id=format_id)) | |
1335c3ac S |
106 | else: |
107 | bitrate = link.get('Bitrate') | |
108 | if bitrate: | |
109 | format_id += '-%s' % bitrate | |
110 | formats.append({ | |
111 | 'url': uri, | |
112 | 'format_id': format_id, | |
6066d03d | 113 | 'tbr': int_or_none(bitrate), |
1335c3ac S |
114 | 'ext': link.get('FileFormat'), |
115 | }) | |
f2b8db57 S |
116 | subtitles_list = asset.get('SubtitlesList') |
117 | if isinstance(subtitles_list, list): | |
118 | LANGS = { | |
6fa73386 | 119 | 'Danish': 'da', |
f2b8db57 S |
120 | } |
121 | for subs in subtitles_list: | |
6066d03d S |
122 | if not subs.get('Uri'): |
123 | continue | |
124 | lang = subs.get('Language') or 'da' | |
125 | subtitles.setdefault(LANGS.get(lang, lang), []).append({ | |
126 | 'url': subs['Uri'], | |
127 | 'ext': mimetype2ext(subs.get('MimeType')) or 'vtt' | |
128 | }) | |
f2b8db57 S |
129 | |
130 | if not formats and restricted_to_denmark: | |
6066d03d S |
131 | self.raise_geo_restricted( |
132 | 'Unfortunately, DR is not allowed to show this program outside Denmark.', | |
133 | expected=True) | |
f2b8db57 S |
134 | |
135 | self._sort_formats(formats) | |
136 | ||
f2b8db57 S |
137 | return { |
138 | 'id': video_id, | |
139 | 'title': title, | |
140 | 'description': description, | |
141 | 'thumbnail': thumbnail, | |
142 | 'timestamp': timestamp, | |
143 | 'duration': duration, | |
144 | 'formats': formats, | |
18c1c424 | 145 | 'subtitles': subtitles, |
f2b8db57 | 146 | } |