mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-08-29 07:11:38 +03:00
[ie/SVTPlay] rework extractor
Drop some obsoleted code paths. Authored by: bashonly Signed-off-by: Moritz Barsnick <barsnick@gmx.net>
This commit is contained in:
+19
-45
@@ -6,10 +6,13 @@ from ..utils import (
|
|||||||
determine_ext,
|
determine_ext,
|
||||||
dict_get,
|
dict_get,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
traverse_obj,
|
|
||||||
try_get,
|
try_get,
|
||||||
unified_timestamp,
|
unified_timestamp,
|
||||||
)
|
)
|
||||||
|
from ..utils.traversal import (
|
||||||
|
require,
|
||||||
|
traverse_obj,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SVTBaseIE(InfoExtractor):
|
class SVTBaseIE(InfoExtractor):
|
||||||
@@ -254,58 +257,29 @@ class SVTPlayIE(SVTPlayBaseIE):
|
|||||||
mobj = self._match_valid_url(url)
|
mobj = self._match_valid_url(url)
|
||||||
video_id = mobj.group('id')
|
video_id = mobj.group('id')
|
||||||
svt_id = mobj.group('svt_id') or mobj.group('modal_id')
|
svt_id = mobj.group('svt_id') or mobj.group('modal_id')
|
||||||
|
|
||||||
if svt_id:
|
if svt_id:
|
||||||
return self._extract_by_video_id(svt_id)
|
return self._extract_by_video_id(svt_id)
|
||||||
|
|
||||||
webpage = self._download_webpage(url, video_id)
|
webpage = self._download_webpage(url, video_id)
|
||||||
|
|
||||||
data = self._parse_json(
|
data = traverse_obj(self._search_nextjs_data(webpage, video_id), (
|
||||||
self._search_regex(
|
'props', 'urqlState', ..., 'data', {json.loads},
|
||||||
self._SVTPLAY_RE, webpage, 'embedded data', default='{}',
|
'detailsPageByPath', {dict}, any, {require('video data')}))
|
||||||
group='json'),
|
details = traverse_obj(data, (
|
||||||
video_id, fatal=False)
|
'modules', lambda _, v: v['details']['smartStart']['item']['videos'],
|
||||||
|
'details', {dict}, any))
|
||||||
thumbnail = self._og_search_thumbnail(webpage)
|
svt_id = traverse_obj(details, (
|
||||||
|
'smartStart', 'item', 'videos',
|
||||||
if data:
|
# There can be 'AudioDescribed' and 'SignInterpreted' variants; try 'Default' or else get first
|
||||||
video_info = try_get(
|
(lambda _, v: v['accessibility'] == 'Default', 0),
|
||||||
data, lambda x: x['context']['dispatcher']['stores']['VideoTitlePageStore']['data']['video'],
|
'svtId', {str}, any))
|
||||||
dict)
|
|
||||||
if video_info:
|
|
||||||
info_dict = self._extract_video(video_info, video_id)
|
|
||||||
info_dict.update({
|
|
||||||
'title': data['context']['dispatcher']['stores']['MetaStore']['title'],
|
|
||||||
'thumbnail': thumbnail,
|
|
||||||
})
|
|
||||||
return info_dict
|
|
||||||
|
|
||||||
svt_id = try_get(
|
|
||||||
data, lambda x: x['statistics']['dataLake']['content']['id'],
|
|
||||||
str)
|
|
||||||
|
|
||||||
if not svt_id:
|
if not svt_id:
|
||||||
nextjs_data = self._search_nextjs_data(webpage, video_id, fatal=False)
|
svt_id = traverse_obj(data, ('video', 'svtId', {str}, {require('SVT ID')}))
|
||||||
svt_id = traverse_obj(nextjs_data, (
|
|
||||||
'props', 'urqlState', ..., 'data', {json.loads}, 'detailsPageByPath',
|
|
||||||
'video', 'svtId', {str}), get_all=False)
|
|
||||||
if not svt_id:
|
|
||||||
details = traverse_obj(nextjs_data, (
|
|
||||||
'props', 'urqlState', ..., 'data', {json.loads}, 'detailsPageByPath',
|
|
||||||
'modules', ..., 'details'), get_all=False)
|
|
||||||
description = details['description']
|
|
||||||
svt_id = traverse_obj(details, (
|
|
||||||
'smartStart', 'item', 'videos', ..., 'svtId', {str}), get_all=False)
|
|
||||||
|
|
||||||
if not svt_id:
|
|
||||||
svt_id = self._search_regex(
|
|
||||||
(r'<video[^>]+data-video-id=["\']([\da-zA-Z-]+)',
|
|
||||||
r'<[^>]+\bdata-rt=["\']top-area-play-button["\'][^>]+\bhref=["\'][^"\']*video/[\w-]+/[^"\']*\b(?:modalId|id)=([\w-]+)'),
|
|
||||||
webpage, 'video id')
|
|
||||||
|
|
||||||
info_dict = self._extract_by_video_id(svt_id, webpage)
|
info_dict = self._extract_by_video_id(svt_id, webpage)
|
||||||
info_dict['description'] = description
|
if not info_dict.get('description'):
|
||||||
info_dict['thumbnail'] = thumbnail
|
info_dict['description'] = traverse_obj(details, ('description', {str}))
|
||||||
|
info_dict['thumbnail'] = self._og_search_thumbnail(webpage)
|
||||||
|
|
||||||
return info_dict
|
return info_dict
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user