mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-09-22 02:11:26 +02:00
Compare commits
No commits in common. "167ae779ff6302926c063869360b96e7fcfdbdf3" and "901bfad490f5e803e2eb9b7bc8013adce30ed889" have entirely different histories.
167ae779ff
...
901bfad490
|
@ -1,20 +1,26 @@
|
|||
import binascii
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
import uuid
|
||||
|
||||
from .common import InfoExtractor
|
||||
from ..aes import aes_cbc_decrypt_bytes, unpad_pkcs7
|
||||
from ..compat import compat_etree_fromstring, compat_urllib_parse_unquote
|
||||
from ..utils import (
|
||||
ExtractorError,
|
||||
float_or_none,
|
||||
int_or_none,
|
||||
mimetype2ext,
|
||||
parse_iso8601,
|
||||
random_uuidv4,
|
||||
try_call,
|
||||
str_or_none,
|
||||
traverse_obj,
|
||||
unified_timestamp,
|
||||
update_url_query,
|
||||
url_or_none,
|
||||
)
|
||||
from ..utils.traversal import traverse_obj
|
||||
|
||||
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'
|
||||
|
||||
|
||||
class DRTVIE(InfoExtractor):
|
||||
_VALID_URL = r'''(?x)
|
||||
https?://
|
||||
|
@ -154,73 +160,36 @@ class DRTVIE(InfoExtractor):
|
|||
},
|
||||
}]
|
||||
|
||||
_TOKEN = None
|
||||
|
||||
def _real_initialize(self):
|
||||
if self._TOKEN:
|
||||
return
|
||||
token_response = self._download_json(
|
||||
'https://production.dr-massive.com/api/authorization/anonymous-sso', None,
|
||||
note='Downloading anonymous token', headers={
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
query={
|
||||
'device': 'web_browser',
|
||||
'ff': 'idp,ldp,rpt',
|
||||
'lang': 'da',
|
||||
'supportFallbackToken': 'true',
|
||||
},
|
||||
data=json.dumps({
|
||||
'deviceId': random_uuidv4(),
|
||||
'scopes': [
|
||||
'Catalog',
|
||||
],
|
||||
'optout': True,
|
||||
}).encode('utf-8'))
|
||||
|
||||
self._TOKEN = traverse_obj(
|
||||
token_response, (lambda _, x: x['type'] == 'UserAccount', 'value'), get_all=False)
|
||||
|
||||
def _real_extract(self, url):
|
||||
raw_video_id = self._match_valid_url(url).group('id')
|
||||
raw_video_id, is_radio_url = self._match_valid_url(url).group('id', 'radio')
|
||||
webpage = self._download_webpage(url, raw_video_id)
|
||||
|
||||
json_data = self._search_json(r'window\.__data\s*=\s*', webpage, 'data', raw_video_id)
|
||||
item = traverse_obj(json_data, ('cache', 'page', ..., (None, ('entries', 0)), 'item'), get_all=False) or {}
|
||||
item_id = item.get('id') or raw_video_id.rsplit('_', 1)[-1]
|
||||
video_id = try_call(item['customId'].split(':')[-1]) or item_id
|
||||
|
||||
stream_data = self._download_json(
|
||||
f'https://production.dr-massive.com/api/account/items/{item_id}/videos', video_id, query={
|
||||
'delivery': 'stream',
|
||||
'device': 'web_browser',
|
||||
'ff': 'idp,ldp,rpt',
|
||||
'lang': 'da',
|
||||
'resolution': 'HD-1080',
|
||||
'sub': 'Anonymous',
|
||||
},
|
||||
headers={
|
||||
'authorization': f'Bearer {self._TOKEN}',
|
||||
})
|
||||
|
||||
if '>Programmet er ikke længere tilgængeligt' in webpage:
|
||||
raise ExtractorError(
|
||||
'Video %s is not available' % raw_video_id, expected=True)
|
||||
json_data = self._search_json(r'window\.__data\s*=', webpage, 'data', raw_video_id)
|
||||
item = traverse_obj(json_data, ('cache', 'page', Ellipsis, (None, ('entries', 0)), 'item'), get_all=False)
|
||||
itemId = item.get('id')
|
||||
videoId = item['customId'].split(':')[-1]
|
||||
deviceId = uuid.uuid1()
|
||||
token = self._download_json('https://isl.dr-massive.com/api/authorization/anonymous-sso?device=web_browser&ff=idp%2Cldp&lang=da', videoId, headers={'Content-Type': 'application/json'}, data=json.dumps({'deviceId': str(deviceId), 'scopes': ['Catalog'], 'optout': True}).encode('utf-8'))[0]['value']
|
||||
data = self._download_json('https://production.dr-massive.com/api/account/items/{0}/videos?delivery=stream&device=web_browser&ff=idp%2Cldp%2Crpt&lang=da&resolution=HD-1080&sub=Anonymous'.format(itemId), videoId, headers={'authorization': 'Bearer {0}'.format(token)})
|
||||
formats = []
|
||||
subtitles = {}
|
||||
for fmt in stream_data:
|
||||
for fmt in data:
|
||||
format_id = fmt.get('format', 'na')
|
||||
access_service = fmt.get('accessService')
|
||||
preference = None
|
||||
if access_service in ('SpokenSubtitles', 'SignLanguage', 'VisuallyInterpreted'):
|
||||
if accessService in ('SpokenSubtitles', 'SignLanguage', 'VisuallyInterpreted'):
|
||||
preference = -1
|
||||
format_id += '-%s' % access_service
|
||||
elif access_service == 'StandardVideo':
|
||||
formatId += '-%s' % accessService
|
||||
elif accessService == 'StandardVideo':
|
||||
preference = 1
|
||||
fmts, subs = self._extract_m3u8_formats_and_subtitles(fmt['url'], video_id, preference=preference, m3u8_id=format_id, fatal=False)
|
||||
fmts, subs = self._extract_m3u8_formats_and_subtitles(fmt['url'], videoId, 'mp4', entry_protocol='m3u8_native', preference=preference, m3u8_id=formatId, fatal=False)
|
||||
formats.extend(fmts)
|
||||
self._merge_subtitles(subs, target=subtitles)
|
||||
LANGS = {
|
||||
'DanishLanguageSubtitles': 'da',
|
||||
'Danish': 'da',
|
||||
}
|
||||
|
||||
for subs in fmt['subtitles']:
|
||||
if not isinstance(subs, dict):
|
||||
continue
|
||||
|
@ -232,28 +201,15 @@ class DRTVIE(InfoExtractor):
|
|||
'url': sub_uri,
|
||||
'ext': mimetype2ext(subs.get('format')) or 'vtt'
|
||||
})
|
||||
|
||||
|
||||
return {
|
||||
'id': video_id,
|
||||
'id': videoId,
|
||||
'title': item.get('episodeName'),
|
||||
'description': item.get('description'),
|
||||
'formats': formats,
|
||||
'subtitles': subtitles,
|
||||
**traverse_obj(item, {
|
||||
'title': 'title',
|
||||
'description': 'description',
|
||||
'thumbnail': ('images', 'wallpaper'),
|
||||
'timestamp': ('customFields', 'BroadcastTimeDK', {parse_iso8601}),
|
||||
'duration': 'duration',
|
||||
'series': ('season', 'title'),
|
||||
'season': ('season', 'show', 'title'),
|
||||
'season_number': ('season', 'seasonNumber', {int_or_none}),
|
||||
'season_id': 'seasonId',
|
||||
'episode': 'episodeName',
|
||||
'episode_number': ('episodeNumber', {int_or_none}),
|
||||
'release_year': 'releaseYear',
|
||||
}),
|
||||
}
|
||||
|
||||
|
||||
class DRTVLiveIE(InfoExtractor):
|
||||
IE_NAME = 'drtv:live'
|
||||
_VALID_URL = r'https?://(?:www\.)?dr\.dk/(?:tv|TV)/live/(?P<id>[\da-z-]+)'
|
||||
|
@ -308,7 +264,6 @@ class DRTVLiveIE(InfoExtractor):
|
|||
'is_live': True,
|
||||
}
|
||||
|
||||
|
||||
class DRTVSeasonIE(InfoExtractor):
|
||||
IE_NAME = 'drtv:season'
|
||||
_VALID_URL = r'https?://(?:www\.)?(?:dr\.dk|dr-massive\.com)/drtv/saeson/(?P<display_id>[\w-]+)_(?P<id>\d+)'
|
||||
|
|
Loading…
Reference in New Issue
Block a user