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 json
|
||||||
|
import re
|
||||||
|
import uuid
|
||||||
|
|
||||||
from .common import InfoExtractor
|
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 (
|
from ..utils import (
|
||||||
|
ExtractorError,
|
||||||
|
float_or_none,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
mimetype2ext,
|
mimetype2ext,
|
||||||
parse_iso8601,
|
str_or_none,
|
||||||
random_uuidv4,
|
traverse_obj,
|
||||||
try_call,
|
unified_timestamp,
|
||||||
update_url_query,
|
update_url_query,
|
||||||
url_or_none,
|
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'
|
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):
|
class DRTVIE(InfoExtractor):
|
||||||
_VALID_URL = r'''(?x)
|
_VALID_URL = r'''(?x)
|
||||||
https?://
|
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):
|
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)
|
webpage = self._download_webpage(url, raw_video_id)
|
||||||
|
if '>Programmet er ikke længere tilgængeligt' in webpage:
|
||||||
json_data = self._search_json(r'window\.__data\s*=\s*', webpage, 'data', raw_video_id)
|
raise ExtractorError(
|
||||||
item = traverse_obj(json_data, ('cache', 'page', ..., (None, ('entries', 0)), 'item'), get_all=False) or {}
|
'Video %s is not available' % raw_video_id, expected=True)
|
||||||
item_id = item.get('id') or raw_video_id.rsplit('_', 1)[-1]
|
json_data = self._search_json(r'window\.__data\s*=', webpage, 'data', raw_video_id)
|
||||||
video_id = try_call(item['customId'].split(':')[-1]) or item_id
|
item = traverse_obj(json_data, ('cache', 'page', Ellipsis, (None, ('entries', 0)), 'item'), get_all=False)
|
||||||
|
itemId = item.get('id')
|
||||||
stream_data = self._download_json(
|
videoId = item['customId'].split(':')[-1]
|
||||||
f'https://production.dr-massive.com/api/account/items/{item_id}/videos', video_id, query={
|
deviceId = uuid.uuid1()
|
||||||
'delivery': 'stream',
|
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']
|
||||||
'device': 'web_browser',
|
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)})
|
||||||
'ff': 'idp,ldp,rpt',
|
|
||||||
'lang': 'da',
|
|
||||||
'resolution': 'HD-1080',
|
|
||||||
'sub': 'Anonymous',
|
|
||||||
},
|
|
||||||
headers={
|
|
||||||
'authorization': f'Bearer {self._TOKEN}',
|
|
||||||
})
|
|
||||||
|
|
||||||
formats = []
|
formats = []
|
||||||
subtitles = {}
|
subtitles = {}
|
||||||
for fmt in stream_data:
|
for fmt in data:
|
||||||
format_id = fmt.get('format', 'na')
|
format_id = fmt.get('format', 'na')
|
||||||
access_service = fmt.get('accessService')
|
access_service = fmt.get('accessService')
|
||||||
preference = None
|
preference = None
|
||||||
if access_service in ('SpokenSubtitles', 'SignLanguage', 'VisuallyInterpreted'):
|
if accessService in ('SpokenSubtitles', 'SignLanguage', 'VisuallyInterpreted'):
|
||||||
preference = -1
|
preference = -1
|
||||||
format_id += '-%s' % access_service
|
formatId += '-%s' % accessService
|
||||||
elif access_service == 'StandardVideo':
|
elif accessService == 'StandardVideo':
|
||||||
preference = 1
|
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)
|
formats.extend(fmts)
|
||||||
self._merge_subtitles(subs, target=subtitles)
|
self._merge_subtitles(subs, target=subtitles)
|
||||||
LANGS = {
|
LANGS = {
|
||||||
'DanishLanguageSubtitles': 'da',
|
'Danish': 'da',
|
||||||
}
|
}
|
||||||
|
|
||||||
for subs in fmt['subtitles']:
|
for subs in fmt['subtitles']:
|
||||||
if not isinstance(subs, dict):
|
if not isinstance(subs, dict):
|
||||||
continue
|
continue
|
||||||
|
@ -232,28 +201,15 @@ class DRTVIE(InfoExtractor):
|
||||||
'url': sub_uri,
|
'url': sub_uri,
|
||||||
'ext': mimetype2ext(subs.get('format')) or 'vtt'
|
'ext': mimetype2ext(subs.get('format')) or 'vtt'
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': videoId,
|
||||||
|
'title': item.get('episodeName'),
|
||||||
|
'description': item.get('description'),
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
'subtitles': subtitles,
|
'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):
|
class DRTVLiveIE(InfoExtractor):
|
||||||
IE_NAME = 'drtv:live'
|
IE_NAME = 'drtv:live'
|
||||||
_VALID_URL = r'https?://(?:www\.)?dr\.dk/(?:tv|TV)/live/(?P<id>[\da-z-]+)'
|
_VALID_URL = r'https?://(?:www\.)?dr\.dk/(?:tv|TV)/live/(?P<id>[\da-z-]+)'
|
||||||
|
@ -308,7 +264,6 @@ class DRTVLiveIE(InfoExtractor):
|
||||||
'is_live': True,
|
'is_live': True,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class DRTVSeasonIE(InfoExtractor):
|
class DRTVSeasonIE(InfoExtractor):
|
||||||
IE_NAME = 'drtv:season'
|
IE_NAME = 'drtv:season'
|
||||||
_VALID_URL = r'https?://(?:www\.)?(?:dr\.dk|dr-massive\.com)/drtv/saeson/(?P<display_id>[\w-]+)_(?P<id>\d+)'
|
_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