2 from __future__ import unicode_literals
4 from .common import InfoExtractor
16 class DRTVIE(InfoExtractor):
17 _VALID_URL = r'https?://(?:www\.)?dr\.dk/(?:tv/se|nyheder|radio/ondemand)/(?:[^/]+/)*(?P<id>[\da-z-]+)(?:[/#?]|$)'
19 _GEO_COUNTRIES = ['DK']
22 'url': 'https://www.dr.dk/tv/se/boern/ultra/klassen-ultra/klassen-darlig-taber-10',
23 'md5': '25e659cccc9a2ed956110a299fdf5983',
25 'id': 'klassen-darlig-taber-10',
27 'title': 'Klassen - Dårlig taber (10)',
28 'description': 'md5:815fe1b7fa656ed80580f31e8b3c79aa',
29 'timestamp': 1471991907,
30 'upload_date': '20160823',
34 'skip_download': True,
37 'url': 'https://www.dr.dk/nyheder/indland/live-christianias-rydning-af-pusher-street-er-i-gang',
38 'md5': '2c37175c718155930f939ef59952474a',
40 'id': 'christiania-pusher-street-ryddes-drdkrjpo',
42 'title': 'LIVE Christianias rydning af Pusher Street er i gang',
43 'description': '- Det er det fedeste, der er sket i 20 år, fortæller christianit til DR Nyheder.',
44 'timestamp': 1472800279,
45 'upload_date': '20160902',
50 def _real_extract(self, url):
51 video_id = self._match_id(url)
53 webpage = self._download_webpage(url, video_id)
55 if '>Programmet er ikke længere tilgængeligt' in webpage:
57 'Video %s is not available' % video_id, expected=True)
59 video_id = self._search_regex(
60 (r'data-(?:material-identifier|episode-slug)="([^"]+)"',
61 r'data-resource="[^>"]+mu/programcard/expanded/([^"]+)"'),
64 programcard = self._download_json(
65 'http://www.dr.dk/mu/programcard/expanded/%s' % video_id,
66 video_id, 'Downloading video JSON')
67 data = programcard['Data'][0]
69 title = remove_end(self._og_search_title(
70 webpage, default=None), ' | TV | DR') or data['Title']
71 description = self._og_search_description(
72 webpage, default=None) or data.get('Description')
74 timestamp = parse_iso8601(data.get('CreatedTime'))
79 restricted_to_denmark = False
84 for asset in data['Assets']:
85 kind = asset.get('Kind')
87 thumbnail = asset.get('Uri')
88 elif kind in ('VideoResource', 'AudioResource'):
89 duration = float_or_none(asset.get('DurationInMilliseconds'), 1000)
90 restricted_to_denmark = asset.get('RestrictedToDenmark')
91 spoken_subtitles = asset.get('Target') == 'SpokenSubtitles'
92 for link in asset.get('Links', []):
96 target = link.get('Target')
97 format_id = target or ''
101 format_id += '-spoken-subtitles'
103 f4m_formats = self._extract_f4m_formats(
104 uri + '?hdcore=3.3.0&plugin=aasp-3.3.0.99.43',
105 video_id, preference, f4m_id=format_id)
106 if kind == 'AudioResource':
107 for f in f4m_formats:
109 formats.extend(f4m_formats)
110 elif target == 'HLS':
111 formats.extend(self._extract_m3u8_formats(
112 uri, video_id, 'mp4', entry_protocol='m3u8_native',
113 preference=preference, m3u8_id=format_id))
115 bitrate = link.get('Bitrate')
117 format_id += '-%s' % bitrate
120 'format_id': format_id,
121 'tbr': int_or_none(bitrate),
122 'ext': link.get('FileFormat'),
123 'vcodec': 'none' if kind == 'AudioResource' else None,
125 subtitles_list = asset.get('SubtitlesList')
126 if isinstance(subtitles_list, list):
130 for subs in subtitles_list:
131 if not subs.get('Uri'):
133 lang = subs.get('Language') or 'da'
134 subtitles.setdefault(LANGS.get(lang, lang), []).append({
136 'ext': mimetype2ext(subs.get('MimeType')) or 'vtt'
139 if not formats and restricted_to_denmark:
140 self.raise_geo_restricted(
141 'Unfortunately, DR is not allowed to show this program outside Denmark.',
142 countries=self._GEO_COUNTRIES)
144 self._sort_formats(formats)
149 'description': description,
150 'thumbnail': thumbnail,
151 'timestamp': timestamp,
152 'duration': duration,
154 'subtitles': subtitles,
158 class DRTVLiveIE(InfoExtractor):
159 IE_NAME = 'drtv:live'
160 _VALID_URL = r'https?://(?:www\.)?dr\.dk/(?:tv|TV)/live/(?P<id>[\da-z-]+)'
161 _GEO_COUNTRIES = ['DK']
163 'url': 'https://www.dr.dk/tv/live/dr1',
167 'title': 're:^DR1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
171 'skip_download': True,
175 def _real_extract(self, url):
176 channel_id = self._match_id(url)
177 channel_data = self._download_json(
178 'https://www.dr.dk/mu-online/api/1.0/channel/' + channel_id,
180 title = self._live_title(channel_data['Title'])
183 for streaming_server in channel_data.get('StreamingServers', []):
184 server = streaming_server.get('Server')
187 link_type = streaming_server.get('LinkType')
188 for quality in streaming_server.get('Qualities', []):
189 for stream in quality.get('Streams', []):
190 stream_path = stream.get('Stream')
193 stream_url = update_url_query(
194 '%s/%s' % (server, stream_path), {'b': ''})
195 if link_type == 'HLS':
196 formats.extend(self._extract_m3u8_formats(
197 stream_url, channel_id, 'mp4',
198 m3u8_id=link_type, fatal=False, live=True))
199 elif link_type == 'HDS':
200 formats.extend(self._extract_f4m_formats(update_url_query(
201 '%s/%s' % (server, stream_path), {'hdcore': '3.7.0'}),
202 channel_id, f4m_id=link_type, fatal=False))
203 self._sort_formats(formats)
208 'thumbnail': channel_data.get('PrimaryImageUri'),