Compare commits

..

No commits in common. "dee3de587ff0403143853dc282cbb550223838d9" and "bf521e9d15b593fc3321cb94d44486de4e87d075" have entirely different histories.

View File

@ -3,7 +3,6 @@ import uuid
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
ExtractorError,
int_or_none, int_or_none,
mimetype2ext, mimetype2ext,
parse_iso8601, parse_iso8601,
@ -20,7 +19,7 @@ class DRTVIE(InfoExtractor):
_VALID_URL = r'''(?x) _VALID_URL = r'''(?x)
https?:// https?://
(?: (?:
(?:www\.)?dr\.dk/tv/se(?:/ondemand)?/(?:[^/?#]+/)*| (?:www\.)?dr\.dk/tv/se(?:/ondemand)?/(?:[^/]+/)*|
(?:www\.)?(?:dr\.dk|dr-massive\.com)/drtv/(?:se|episode|program)/ (?:www\.)?(?:dr\.dk|dr-massive\.com)/drtv/(?:se|episode|program)/
) )
(?P<id>[\da-z_-]+) (?P<id>[\da-z_-]+)
@ -126,46 +125,45 @@ class DRTVIE(InfoExtractor):
'only_matching': True, 'only_matching': True,
}] }]
_TOKEN = None
SUBTITLE_LANGS = { SUBTITLE_LANGS = {
'DanishLanguageSubtitles': 'da', 'DanishLanguageSubtitles': 'da',
'ForeignLanguageSubtitles': 'da_foreign', 'ForeignLanguageSubtitles': 'da_foreign',
'CombinedLanguageSubtitles': 'da_combined', 'CombinedLanguageSubtitles': 'da_combined',
} }
_TOKEN = None
def _real_initialize(self): def _real_initialize(self):
if self._TOKEN: if self._TOKEN:
return return
token_response = self._download_json( token_response = self._download_json(
'https://production.dr-massive.com/api/authorization/anonymous-sso', None, 'https://production.dr-massive.com/api/authorization/anonymous-sso', None,
note='Downloading anonymous token', headers={ note='Downloading anonymous token', headers={
'content-type': 'application/json', 'content-type': 'application/json',
}, query={ },
query={
'device': 'web_browser', 'device': 'web_browser',
'ff': 'idp,ldp,rpt', 'ff': 'idp,ldp,rpt',
'lang': 'da', 'lang': 'da',
'supportFallbackToken': 'true', 'supportFallbackToken': 'true',
}, data=json.dumps({ },
data=json.dumps({
'deviceId': str(uuid.uuid4()), 'deviceId': str(uuid.uuid4()),
'scopes': ['Catalog'], 'scopes': [
'Catalog',
],
'optout': True, 'optout': True,
}).encode()) }).encode())
self._TOKEN = traverse_obj( self._TOKEN = traverse_obj(
token_response, (lambda _, x: x['type'] == 'UserAccount', 'value', {str}), get_all=False) token_response, (lambda _, x: x['type'] == 'UserAccount', 'value', {str}), get_all=False)
if not self._TOKEN:
raise ExtractorError('Unable to get anonymous token')
def _real_extract(self, url): def _real_extract(self, url):
url_slug = self._match_id(url) url_slug = self._match_id(url)
webpage = self._download_webpage(url, url_slug) webpage = self._download_webpage(url, url_slug)
json_data = self._search_json( json_data = self._search_json(r'window\.__data\s*=\s*', webpage, 'data', url_slug, fatal=False) or {}
r'window\.__data\s*=', webpage, 'data', url_slug, fatal=False) or {} item = traverse_obj(json_data, ('cache', 'page', ..., (None, ('entries', 0)), 'item'), get_all=False)
item = traverse_obj(
json_data, ('cache', 'page', ..., (None, ('entries', 0)), 'item', {dict}), get_all=False)
if item: if item:
item_id = item.get('id') item_id = item.get('id')
else: else:
@ -182,7 +180,6 @@ class DRTVIE(InfoExtractor):
'segments': 'drtv,optedout', 'segments': 'drtv,optedout',
'sub': 'Anonymous', 'sub': 'Anonymous',
}) })
video_id = try_call(lambda: item['customId'].rsplit(':', 1)[-1]) or item_id video_id = try_call(lambda: item['customId'].rsplit(':', 1)[-1]) or item_id
stream_data = self._download_json( stream_data = self._download_json(
f'https://production.dr-massive.com/api/account/items/{item_id}/videos', video_id, f'https://production.dr-massive.com/api/account/items/{item_id}/videos', video_id,
@ -193,13 +190,16 @@ class DRTVIE(InfoExtractor):
'lang': 'da', 'lang': 'da',
'resolution': 'HD-1080', 'resolution': 'HD-1080',
'sub': 'Anonymous', 'sub': 'Anonymous',
}, headers={'authorization': f'Bearer {self._TOKEN}'}) },
headers={
'authorization': f'Bearer {self._TOKEN}',
})
formats = [] formats = []
subtitles = {} subtitles = {}
for stream in traverse_obj(stream_data, (lambda _, x: x['url'])): for fmt in traverse_obj(stream_data, (lambda _, x: x['url'], {dict})):
format_id = stream.get('format', 'na') format_id = fmt.get('format', 'na')
access_service = stream.get('accessService') access_service = fmt.get('accessService')
preference = None preference = None
subtitle_suffix = '' subtitle_suffix = ''
if access_service in ('SpokenSubtitles', 'SignLanguage', 'VisuallyInterpreted'): if access_service in ('SpokenSubtitles', 'SignLanguage', 'VisuallyInterpreted'):
@ -209,10 +209,10 @@ class DRTVIE(InfoExtractor):
elif access_service == 'StandardVideo': elif access_service == 'StandardVideo':
preference = 1 preference = 1
fmts, subs = self._extract_m3u8_formats_and_subtitles( fmts, subs = self._extract_m3u8_formats_and_subtitles(
stream.get('url'), video_id, preference=preference, m3u8_id=format_id, fatal=False) fmt.get('url'), video_id, preference=preference, m3u8_id=format_id, fatal=False)
formats.extend(fmts) formats.extend(fmts)
api_subtitles = traverse_obj(stream, ('subtitles', lambda _, v: url_or_none(v['link']), {dict})) api_subtitles = traverse_obj(fmt, ('subtitles', lambda _, v: url_or_none(v['link']), {dict}))
if not api_subtitles: if not api_subtitles:
self._merge_subtitles(subs, target=subtitles) self._merge_subtitles(subs, target=subtitles)
@ -223,9 +223,6 @@ class DRTVIE(InfoExtractor):
'ext': mimetype2ext(sub_track.get('format')) or 'vtt' 'ext': mimetype2ext(sub_track.get('format')) or 'vtt'
}) })
if not formats and traverse_obj(item, ('season', 'customFields', 'IsGeoRestricted')):
self.raise_geo_restricted(countries=self._GEO_COUNTRIES)
return { return {
'id': video_id, 'id': video_id,
'formats': formats, 'formats': formats,