Compare commits

...

4 Commits

Author SHA1 Message Date
Teemu Ikonen
5344626dce
Merge a94b69e4d3862c9549585782f308c03b17ed8699 into 673277e510ebd996b62a2fcc76169bf3cce29910 2025-03-09 13:27:34 +00:00
dirkf
673277e510
[YouTube] Fix 91b1569 2025-02-28 01:02:20 +00:00
dirkf
91b1569f68
[YouTube] Fix channel playlist extraction (#33074)
* [YouTube] Extract playlist items from LOCKUP_VIEW_MODEL_...
* resolves #33073
* thx seproDev (yt-dlp/yt-dlp#11615)

Co-authored-by: sepro <sepro@sepr0.com>
2025-02-28 00:02:10 +00:00
tpikonen
a94b69e4d3 [icareus] Add new extractor 2021-03-21 18:38:16 +02:00
3 changed files with 278 additions and 2 deletions

View File

@ -506,6 +506,7 @@ from .hungama import (
HungamaSongIE, HungamaSongIE,
) )
from .hypem import HypemIE from .hypem import HypemIE
from .icareus import IcareusIE
from .ign import ( from .ign import (
IGNIE, IGNIE,
IGNVideoIE, IGNVideoIE,

View File

@ -0,0 +1,230 @@
# coding: utf-8
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..utils import (
clean_html,
determine_ext,
get_element_by_attribute,
get_element_by_class,
int_or_none,
parse_bitrate,
parse_resolution,
unified_timestamp,
urlencode_postdata,
url_or_none,
)
class IcareusIE(InfoExtractor):
_VALID_URL = r'''(?x)
https?://(?:www\.)?
(?:
asahitv\.fi|
helsinkikanava\.fi|
hyvinvointitv\.fi|
inez\.fi|
midastv\.ke|
permanto\.fi|
suite.icareus.com|
videos\.minifiddlers\.org
)
/.+/player/.*(?:assetId|eventId)=(?P<id>\d+).*'''
_TESTS = [{
'url': 'https://www.helsinkikanava.fi/fi_FI/web/helsinkikanava/player/vod?assetId=68021894',
'md5': 'ca0b62ffc814a5411dfa6349cf5adb8a',
'info_dict': {
'id': '68021894',
'ext': 'mp4',
'title': 'Perheiden parhaaksi',
'description': 'md5:fe4e4ec742a34f53022f3a0409b0f6e7',
'thumbnail': 'https://www.helsinkikanava.fi/image/image_gallery?img_id=68022501',
'upload_date': '20200924',
'timestamp': 1600938300,
},
}, { # Recorded livestream
'url': 'https://www.helsinkikanava.fi/fi/web/helsinkikanava/player/event/view?eventId=76241489',
'md5': '014327e69dfa7b949fcc861f6d162d6d',
'info_dict': {
'id': '76258304',
'ext': 'mp4',
'title': 'Helsingin kaupungin ja HUSin tiedotustilaisuus koronaepidemiatilanteesta 24.11.2020',
'description': 'md5:3129d041c6fbbcdc7fe68d9a938fef1c',
'thumbnail': 'https://icareus-suite.secure2.footprint.net/image/image_gallery?img_id=76288630',
'upload_date': '20201124',
'timestamp': 1606206600,
},
}, {
'url': 'https://asahitv.fi/fi/web/asahi/player/vod?assetId=89415818',
'only_matching': True
}, {
'url': 'https://hyvinvointitv.fi/fi/web/hyvinvointitv/player/vod?assetId=89149730',
'only_matching': True
}, {
'url': 'https://inez.fi/fi/web/inez-media/player/vod?assetId=71328822',
'only_matching': True
}, {
'url': 'https://www.midastv.ke/en/web/midas-tv/player/embed/vod?assetId=65714535',
'only_matching': True
}, {
'url': 'https://www.permanto.fi/fi/web/alfatv/player/vod?assetId=95010095',
'only_matching': True
}, {
'url': 'https://suite.icareus.com/fi/web/westend-indians/player/vod?assetId=47567389',
'only_matching': True
}, {
'url': 'https://videos.minifiddlers.org/web/international-minifiddlers/player/vod?assetId=1982759',
'only_matching': True
}]
_API2_PATH = '/icareus-suite-api-portlet/publishing'
def _real_extract(self, url):
maybe_id = self._match_id(url)
page = self._download_webpage(url, maybe_id)
video_id = self._search_regex(
r"_icareus\['itemId'\]='(\d+)'", page, "video_id")
api_base = self._search_regex(
r'var publishingServiceURL = "(http.*?)";', page, "api_base")
organization_id = self._search_regex(
r"_icareus\['organizationId'\]='(\d+)'", page, "organization_id")
token = self._search_regex(
r"_icareus\['token'\]='([a-f0-9]+)'", page, "token")
token2 = self._search_regex(
r'''data\s*:\s*{action:"getAsset".*?token:'([a-f0-9]+)'}''', page,
"token2", default=None, fatal=False)
metajson = get_element_by_attribute('type', 'application/ld+json', page)
metad = None
if metajson:
# The description can contain newlines, HTML tags, quote chars etc.
# so we'll extract it manually
mo = re.match(
r'(.*",)\s*"description": "(.*?)",(\s*"thumbnailUrl":.*)',
metajson, flags=re.DOTALL)
if mo:
desc_text = mo.group(2)
metajson = mo.group(1) + mo.group(3)
metad = self._parse_json(metajson, video_id, fatal=False)
else:
self.report_warning("Could not fix metadata JSON", video_id)
livestream_title = get_element_by_class(
'unpublished-info-item future-event-title', page)
duration = None
thumbnail = None
if metad:
title = metad.get('name')
description = desc_text
timestamp = unified_timestamp(metad.get('uploadDate'))
thumbnail = url_or_none(metad.get('thumbnailUrl'))
elif token2:
base_url = self._search_regex(r'(https?://[^/]+)/', url, 'base_url')
data = {
"version": "03",
"action": "getAsset",
"organizationId": organization_id,
"assetId": video_id,
"languageId": "en_US",
"userId": "0",
"token": token2,
}
metad = self._download_json(base_url + self._API2_PATH, video_id,
data=urlencode_postdata(data))
title = metad.get('name')
description = metad.get('description')
timestamp = int_or_none(metad.get('date'), scale=1000)
duration = int_or_none(metad.get('duration'))
thumbnail = url_or_none(metad.get('thumbnailMedium'))
elif livestream_title: # Recorded livestream
title = livestream_title
description = get_element_by_class(
'unpublished-info-item future-event-description', page)
timestamp = int_or_none(self._search_regex(
r"var startEvent\s*=\s*(\d+);", page, "uploadDate",
fatal=False), scale=1000)
else:
self.report_warning("Could not extract metadata", video_id)
description = None
timestamp = None
title = title if title else video_id
description = clean_html(description)
data = {
"version": "03",
"action": "getAssetPlaybackUrls",
"organizationId": organization_id,
"assetId": video_id,
"token": token,
}
jsond = self._download_json(api_base, video_id,
data=urlencode_postdata(data))
if thumbnail is None:
thumbnail = url_or_none(jsond.get('thumbnail'))
formats = []
for item in jsond.get('urls', []):
video_url = url_or_none(item.get('url'))
ext = determine_ext(video_url)
if ext == 'm3u8':
formats.extend(self._extract_m3u8_formats(
video_url, video_id, 'mp4',
entry_protocol='m3u8_native', m3u8_id='hls',
fatal=False))
else:
fd = {'url': video_url}
fmt = item.get('name')
if fmt:
fd['format'] = fmt
fd.update(parse_resolution(fmt))
mo = re.search(r'\((\d+)\s*kbps\)\s*\+\s*(\d+)\s*kbps', fmt)
if mo:
fd['vbr'] = int_or_none(mo.group(1))
fd['abr'] = int_or_none(mo.group(2))
else:
fd['tbr'] = parse_bitrate(fmt)
fmt_id = item.get('id')
if fmt_id:
fd['format_id'] = str(fmt_id)
formats.append(fd)
for item in jsond.get('audio_urls', []):
fmt = item.get('name')
mo = re.match(r'.*\((\d+)k\).*', fmt if fmt else '')
abr = int_or_none(mo.group(1)) if mo else None
fd = {
'format': fmt,
'format_id': 'audio',
'url': url_or_none(item.get('url')),
'vcodec': 'none',
}
if abr:
fd['abr'] = abr
formats.append(fd)
subtitles = {}
for sub in jsond.get('subtitles', []):
scode, sdesc, surl = sub
lang = sdesc.split(' ')[0]
lang = lang[:-1] if lang.endswith(':') else lang
subtitles[lang] = [{"url": url_or_none(surl)}]
info = {
'id': video_id,
'title': title,
'description': description,
'thumbnail': thumbnail,
'timestamp': timestamp,
'formats': formats,
}
if duration:
info['duration'] = duration
if subtitles:
info['subtitles'] = subtitles
return info

View File

@ -27,6 +27,7 @@ from ..compat import (
) )
from ..jsinterp import JSInterpreter from ..jsinterp import JSInterpreter
from ..utils import ( from ..utils import (
bug_reports_message,
clean_html, clean_html,
dict_get, dict_get,
error_to_compat_str, error_to_compat_str,
@ -65,6 +66,7 @@ from ..utils import (
url_or_none, url_or_none,
urlencode_postdata, urlencode_postdata,
urljoin, urljoin,
variadic,
) )
@ -460,6 +462,26 @@ class YoutubeBaseInfoExtractor(InfoExtractor):
'uploader': uploader, 'uploader': uploader,
} }
@staticmethod
def _extract_thumbnails(data, *path_list, **kw_final_key):
"""
Extract thumbnails from thumbnails dict
@param path_list: path list to level that contains 'thumbnails' key
"""
final_key = kw_final_key.get('final_key', 'thumbnails')
return traverse_obj(data, ((
tuple(variadic(path) + (final_key, Ellipsis)
for path in path_list or [()])), {
'url': ('url', T(url_or_none),
# Sometimes youtube gives a wrong thumbnail URL. See:
# https://github.com/yt-dlp/yt-dlp/issues/233
# https://github.com/ytdl-org/youtube-dl/issues/28023
T(lambda u: update_url(u, query=None) if u and 'maxresdefault' in u else u)),
'height': ('height', T(int_or_none)),
'width': ('width', T(int_or_none)),
}, T(lambda t: t if t.get('url') else None)))
def _search_results(self, query, params): def _search_results(self, query, params):
data = { data = {
'context': { 'context': {
@ -3183,8 +3205,12 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
expected_type=txt_or_none) expected_type=txt_or_none)
def _grid_entries(self, grid_renderer): def _grid_entries(self, grid_renderer):
for item in grid_renderer['items']: for item in traverse_obj(grid_renderer, ('items', Ellipsis, T(dict))):
if not isinstance(item, dict): lockup_view_model = traverse_obj(item, ('lockupViewModel', T(dict)))
if lockup_view_model:
entry = self._extract_lockup_view_model(lockup_view_model)
if entry:
yield entry
continue continue
renderer = self._extract_grid_item_renderer(item) renderer = self._extract_grid_item_renderer(item)
if not isinstance(renderer, dict): if not isinstance(renderer, dict):
@ -3268,6 +3294,25 @@ class YoutubeTabIE(YoutubeBaseInfoExtractor):
continue continue
yield self._extract_video(renderer) yield self._extract_video(renderer)
def _extract_lockup_view_model(self, view_model):
content_id = view_model.get('contentId')
if not content_id:
return
content_type = view_model.get('contentType')
if content_type not in ('LOCKUP_CONTENT_TYPE_PLAYLIST', 'LOCKUP_CONTENT_TYPE_PODCAST'):
self.report_warning(
'Unsupported lockup view model content type "{0}"{1}'.format(content_type, bug_reports_message()), only_once=True)
return
return merge_dicts(self.url_result(
update_url_query('https://www.youtube.com/playlist', {'list': content_id}),
ie=YoutubeTabIE.ie_key(), video_id=content_id), {
'title': traverse_obj(view_model, (
'metadata', 'lockupMetadataViewModel', 'title', 'content', T(compat_str))),
'thumbnails': self._extract_thumbnails(view_model, (
'contentImage', 'collectionThumbnailViewModel', 'primaryThumbnail',
'thumbnailViewModel', 'image'), final_key='sources'),
})
def _video_entry(self, video_renderer): def _video_entry(self, video_renderer):
video_id = video_renderer.get('videoId') video_id = video_renderer.get('videoId')
if video_id: if video_id: