Compare commits

...

2 Commits

Author SHA1 Message Date
sepro
167ae779ff Cleanup Part 1
Currently untested. More to come.
2023-11-05 02:45:43 +01:00
almx
24e7b94d36 Update drtv.py
Updated according to PR comments.
2023-11-05 00:37:37 +01:00

View File

@ -1,26 +1,20 @@
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,
str_or_none,
traverse_obj,
unified_timestamp,
parse_iso8601,
random_uuidv4,
try_call,
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?://
@ -160,36 +154,73 @@ 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, is_radio_url = self._match_valid_url(url).group('id', 'radio')
raw_video_id = self._match_valid_url(url).group('id')
webpage = self._download_webpage(url, raw_video_id)
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)})
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}',
})
formats = []
subtitles = {}
for fmt in data:
for fmt in stream_data:
format_id = fmt.get('format', 'na')
access_service = fmt.get('accessService')
preference = None
if accessService in ('SpokenSubtitles', 'SignLanguage', 'VisuallyInterpreted'):
if access_service in ('SpokenSubtitles', 'SignLanguage', 'VisuallyInterpreted'):
preference = -1
formatId += '-%s' % accessService
elif accessService == 'StandardVideo':
format_id += '-%s' % access_service
elif access_service == 'StandardVideo':
preference = 1
fmts, subs = self._extract_m3u8_formats_and_subtitles(fmt['url'], videoId, 'mp4', entry_protocol='m3u8_native', preference=preference, m3u8_id=formatId, fatal=False)
fmts, subs = self._extract_m3u8_formats_and_subtitles(fmt['url'], video_id, preference=preference, m3u8_id=format_id, fatal=False)
formats.extend(fmts)
self._merge_subtitles(subs, target=subtitles)
LANGS = {
'Danish': 'da',
'DanishLanguageSubtitles': 'da',
}
for subs in fmt['subtitles']:
if not isinstance(subs, dict):
continue
@ -201,15 +232,28 @@ class DRTVIE(InfoExtractor):
'url': sub_uri,
'ext': mimetype2ext(subs.get('format')) or 'vtt'
})
return {
'id': videoId,
'title': item.get('episodeName'),
'description': item.get('description'),
'id': video_id,
'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-]+)'
@ -264,6 +308,7 @@ 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+)'