4 from .common
import InfoExtractor
14 from ..utils
.traversal
import traverse_obj
16 SERIES_API
= 'https://production-cdn.dr-massive.com/api/page?device=web_browser&item_detail_expand=all&lang=da&max_list_prefetch=3&path=%s'
19 class DRTVIE(InfoExtractor
):
23 (?:www\.)?dr\.dk/tv/se(?:/ondemand)?/(?:[^/?#]+/)*|
24 (?:www\.)?(?:dr\.dk|dr-massive\.com)/drtv/(?:se|episode|program)/
29 _GEO_COUNTRIES
= ['DK']
32 'url': 'https://www.dr.dk/tv/se/boern/ultra/klassen-ultra/klassen-darlig-taber-10',
33 'md5': '25e659cccc9a2ed956110a299fdf5983',
35 'id': 'klassen-darlig-taber-10',
37 'title': 'Klassen - DÃ¥rlig taber (10)',
38 'description': 'md5:815fe1b7fa656ed80580f31e8b3c79aa',
39 'timestamp': 1539085800,
40 'upload_date': '20181009',
43 'season': 'Klassen I',
45 'season_id': 'urn:dr:mu:bundle:57d7e8216187a4031cfd6f6b',
46 'episode': 'Episode 10',
50 'expected_warnings': ['Unable to download f4m manifest'],
51 'skip': 'this video has been removed',
53 # with SignLanguage formats
54 'url': 'https://www.dr.dk/tv/se/historien-om-danmark/-/historien-om-danmark-stenalder',
58 'title': 'Historien om Danmark: Stenalder',
59 'description': 'md5:8c66dcbc1669bbc6f873879880f37f2a',
60 'timestamp': 1546628400,
61 'upload_date': '20190104',
63 'formats': 'mincount:20',
65 'season_id': 'urn:dr:mu:bundle:5afc03ad6187a4065ca5fd35',
67 'season': 'Historien om Danmark',
68 'series': 'Historien om Danmark',
70 'skip': 'this video has been removed',
72 'url': 'https://www.dr.dk/drtv/se/frank-and-kastaniegaarden_71769',
76 'title': 'Frank & Kastaniegaarden',
77 'description': 'md5:974e1780934cf3275ef10280204bccb0',
78 'release_timestamp': 1546545600,
79 'release_date': '20190103',
81 'season': 'Frank & Kastaniegaarden',
84 'season_number': 2019,
85 'series': 'Frank & Kastaniegaarden',
87 'episode': 'Frank & Kastaniegaarden',
88 'thumbnail': r
're:https?://.+',
91 'skip_download': True,
94 # Foreign and Regular subtitle track
95 'url': 'https://www.dr.dk/drtv/se/spise-med-price_-pasta-selv_397445',
100 'title': 'Spise med Price: Pasta Selv',
101 'alt_title': '1. Pasta Selv',
102 'release_date': '20230807',
103 'description': 'md5:2da9060524fed707810d71080b3d0cd8',
105 'season': 'Spise med Price',
106 'release_timestamp': 1691438400,
107 'season_id': '397440',
108 'episode': 'Spise med Price: Pasta Selv',
109 'thumbnail': r
're:https?://.+',
111 'series': 'Spise med Price',
112 'release_year': 2022,
113 'subtitles': 'mincount:2',
116 'skip_download': 'm3u8',
119 'url': 'https://www.dr.dk/drtv/episode/bonderoeven_71769',
120 'only_matching': True,
122 'url': 'https://dr-massive.com/drtv/se/bonderoeven_71769',
123 'only_matching': True,
125 'url': 'https://www.dr.dk/drtv/program/jagten_220924',
126 'only_matching': True,
130 'DanishLanguageSubtitles': 'da',
131 'ForeignLanguageSubtitles': 'da_foreign',
132 'CombinedLanguageSubtitles': 'da_combined',
137 def _real_initialize(self
):
141 token_response
= self
._download
_json
(
142 'https://isl.dr-massive.com/api/authorization/anonymous-sso', None,
143 note
='Downloading anonymous token', headers
={
144 'content-type': 'application/json',
146 'device': 'phone_android',
148 'supportFallbackToken': 'true',
150 'deviceId': str(uuid
.uuid4()),
151 'scopes': ['Catalog'],
155 self
._TOKEN
= traverse_obj(
156 token_response
, (lambda _
, x
: x
['type'] == 'UserAccount', 'value', {str}
), get_all
=False)
158 raise ExtractorError('Unable to get anonymous token')
160 def _real_extract(self
, url
):
161 url_slug
= self
._match
_id
(url
)
162 webpage
= self
._download
_webpage
(url
, url_slug
)
164 json_data
= self
._search
_json
(
165 r
'window\.__data\s*=', webpage
, 'data', url_slug
, fatal
=False) or {}
167 json_data
, ('cache', 'page', ..., (None, ('entries', 0)), 'item', {dict}
), get_all
=False)
169 item_id
= item
.get('id')
171 item_id
= url_slug
.rsplit('_', 1)[-1]
172 item
= self
._download
_json
(
173 f
'https://production-cdn.dr-massive.com/api/items/{item_id}', item_id
,
174 note
='Attempting to download backup item data', query
={
175 'device': 'web_browser',
179 'isDeviceAbroad': 'false',
181 'segments': 'drtv,optedout',
185 video_id
= try_call(lambda: item
['customId'].rsplit(':', 1)[-1]) or item_id
186 stream_data
= self
._download
_json
(
187 f
'https://production.dr-massive.com/api/account/items/{item_id}/videos', video_id
,
188 note
='Downloading stream data', query
={
189 'delivery': 'stream',
190 'device': 'web_browser',
193 'resolution': 'HD-1080',
195 }, headers
={'authorization': f
'Bearer {self._TOKEN}'})
199 for stream
in traverse_obj(stream_data
, (lambda _
, x
: x
['url'])):
200 format_id
= stream
.get('format', 'na')
201 access_service
= stream
.get('accessService')
204 if access_service
in ('SpokenSubtitles', 'SignLanguage', 'VisuallyInterpreted'):
206 format_id
+= f
'-{access_service}'
207 subtitle_suffix
= f
'-{access_service}'
208 elif access_service
== 'StandardVideo':
210 fmts
, subs
= self
._extract
_m
3u8_formats
_and
_subtitles
(
211 stream
.get('url'), video_id
, ext
='mp4', preference
=preference
, m3u8_id
=format_id
, fatal
=False)
214 api_subtitles
= traverse_obj(stream
, ('subtitles', lambda _
, v
: url_or_none(v
['link']), {dict}
))
215 if not api_subtitles
:
216 self
._merge
_subtitles
(subs
, target
=subtitles
)
218 for sub_track
in api_subtitles
:
219 lang
= sub_track
.get('language') or 'da'
220 subtitles
.setdefault(self
.SUBTITLE_LANGS
.get(lang
, lang
) + subtitle_suffix
, []).append({
221 'url': sub_track
['link'],
222 'ext': mimetype2ext(sub_track
.get('format')) or 'vtt',
225 if not formats
and traverse_obj(item
, ('season', 'customFields', 'IsGeoRestricted')):
226 self
.raise_geo_restricted(countries
=self
._GEO
_COUNTRIES
)
231 'subtitles': subtitles
,
232 **traverse_obj(item
, {
234 'alt_title': 'contextualTitle',
235 'description': 'description',
236 'thumbnail': ('images', 'wallpaper'),
237 'release_timestamp': ('customFields', 'BroadcastTimeDK', {parse_iso8601}
),
238 'duration': ('duration', {int_or_none}
),
239 'series': ('season', 'show', 'title'),
240 'season': ('season', 'title'),
241 'season_number': ('season', 'seasonNumber', {int_or_none}
),
242 'season_id': 'seasonId',
243 'episode': 'episodeName',
244 'episode_number': ('episodeNumber', {int_or_none}
),
245 'release_year': ('releaseYear', {int_or_none}
),
250 class DRTVLiveIE(InfoExtractor
):
251 IE_NAME
= 'drtv:live'
252 _VALID_URL
= r
'https?://(?:www\.)?dr\.dk/(?:tv|TV)/live/(?P<id>[\da-z-]+)'
253 _GEO_COUNTRIES
= ['DK']
255 'url': 'https://www.dr.dk/tv/live/dr1',
259 'title': 're:^DR1 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
263 'skip_download': True,
267 def _real_extract(self
, url
):
268 channel_id
= self
._match
_id
(url
)
269 channel_data
= self
._download
_json
(
270 'https://www.dr.dk/mu-online/api/1.0/channel/' + channel_id
,
272 title
= channel_data
['Title']
275 for streaming_server
in channel_data
.get('StreamingServers', []):
276 server
= streaming_server
.get('Server')
279 link_type
= streaming_server
.get('LinkType')
280 for quality
in streaming_server
.get('Qualities', []):
281 for stream
in quality
.get('Streams', []):
282 stream_path
= stream
.get('Stream')
285 stream_url
= update_url_query(
286 f
'{server}/{stream_path}', {'b': ''})
287 if link_type
== 'HLS':
288 formats
.extend(self
._extract
_m
3u8_formats
(
289 stream_url
, channel_id
, 'mp4',
290 m3u8_id
=link_type
, fatal
=False, live
=True))
291 elif link_type
== 'HDS':
292 formats
.extend(self
._extract
_f
4m
_formats
(update_url_query(
293 f
'{server}/{stream_path}', {'hdcore': '3.7.0'}),
294 channel_id
, f4m_id
=link_type
, fatal
=False))
299 'thumbnail': channel_data
.get('PrimaryImageUri'),
305 class DRTVSeasonIE(InfoExtractor
):
306 IE_NAME
= 'drtv:season'
307 _VALID_URL
= r
'https?://(?:www\.)?(?:dr\.dk|dr-massive\.com)/drtv/saeson/(?P<display_id>[\w-]+)_(?P<id>\d+)'
308 _GEO_COUNTRIES
= ['DK']
310 'url': 'https://www.dr.dk/drtv/saeson/frank-and-kastaniegaarden_9008',
313 'display_id': 'frank-and-kastaniegaarden',
314 'title': 'Frank & Kastaniegaarden',
315 'series': 'Frank & Kastaniegaarden',
316 'season_number': 2008,
317 'alt_title': 'Season 2008',
319 'playlist_mincount': 8,
321 'url': 'https://www.dr.dk/drtv/saeson/frank-and-kastaniegaarden_8761',
324 'display_id': 'frank-and-kastaniegaarden',
325 'title': 'Frank & Kastaniegaarden',
326 'series': 'Frank & Kastaniegaarden',
327 'season_number': 2009,
328 'alt_title': 'Season 2009',
330 'playlist_mincount': 19,
333 def _real_extract(self
, url
):
334 display_id
, season_id
= self
._match
_valid
_url
(url
).group('display_id', 'id')
335 data
= self
._download
_json
(SERIES_API
% f
'/saeson/{display_id}_{season_id}', display_id
)
339 'url': f
'https://www.dr.dk/drtv{episode["path"]}',
340 'ie_key': DRTVIE
.ie_key(),
341 'title': episode
.get('title'),
342 'alt_title': episode
.get('contextualTitle'),
343 'episode': episode
.get('episodeName'),
344 'description': episode
.get('shortDescription'),
345 'series': traverse_obj(data
, ('entries', 0, 'item', 'title')),
346 'season_number': traverse_obj(data
, ('entries', 0, 'item', 'seasonNumber')),
347 'episode_number': episode
.get('episodeNumber'),
348 } for episode
in traverse_obj(data
, ('entries', 0, 'item', 'episodes', 'items'))]
353 'display_id': display_id
,
354 'title': traverse_obj(data
, ('entries', 0, 'item', 'title')),
355 'alt_title': traverse_obj(data
, ('entries', 0, 'item', 'contextualTitle')),
356 'series': traverse_obj(data
, ('entries', 0, 'item', 'title')),
358 'season_number': traverse_obj(data
, ('entries', 0, 'item', 'seasonNumber')),
362 class DRTVSeriesIE(InfoExtractor
):
363 IE_NAME
= 'drtv:series'
364 _VALID_URL
= r
'https?://(?:www\.)?(?:dr\.dk|dr-massive\.com)/drtv/serie/(?P<display_id>[\w-]+)_(?P<id>\d+)'
365 _GEO_COUNTRIES
= ['DK']
367 'url': 'https://www.dr.dk/drtv/serie/frank-and-kastaniegaarden_6954',
370 'display_id': 'frank-and-kastaniegaarden',
371 'title': 'Frank & Kastaniegaarden',
372 'series': 'Frank & Kastaniegaarden',
375 'playlist_mincount': 15,
378 def _real_extract(self
, url
):
379 display_id
, series_id
= self
._match
_valid
_url
(url
).group('display_id', 'id')
380 data
= self
._download
_json
(SERIES_API
% f
'/serie/{display_id}_{series_id}', display_id
)
384 'url': f
'https://www.dr.dk/drtv{season.get("path")}',
385 'ie_key': DRTVSeasonIE
.ie_key(),
386 'title': season
.get('title'),
387 'alt_title': season
.get('contextualTitle'),
388 'series': traverse_obj(data
, ('entries', 0, 'item', 'title')),
389 'season_number': traverse_obj(data
, ('entries', 0, 'item', 'seasonNumber')),
390 } for season
in traverse_obj(data
, ('entries', 0, 'item', 'show', 'seasons', 'items'))]
395 'display_id': display_id
,
396 'title': traverse_obj(data
, ('entries', 0, 'item', 'title')),
397 'alt_title': traverse_obj(data
, ('entries', 0, 'item', 'contextualTitle')),
398 'series': traverse_obj(data
, ('entries', 0, 'item', 'title')),