Compare commits

...

4 Commits

Author SHA1 Message Date
NoSuck
d7a3b821c4
Merge df1852a74eb518b21d8fd87957bd61ffddfdbcbc into 673277e510ebd996b62a2fcc76169bf3cce29910 2025-03-06 05:34:49 -06: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
Friendly
df1852a74e Option to determine extractors ahead of time
Sometimes I just want to know whether youtube-dl can be expected to handle a given URL.  This option accomplishes that quickly.  Previously, I would run youtube-dl with --simulate or --skip-download, but these would take 5+ seconds on my system before returning.  The --determine-extractors option of this PR, however, only takes 1.3 to 2.6 seconds.  You can use it, for example, to handle arbitrary URLs intelligently:  If --determine-extractor indicates success, run youtube-dl (or mpv or whatever).  Otherwise, run $BROWSER.

Thank you.
2021-10-10 22:44:24 -04:00
3 changed files with 69 additions and 2 deletions

View File

@ -8,6 +8,7 @@ __license__ = 'Public Domain'
import io import io
import os import os
import random import random
import re
import sys import sys
@ -122,6 +123,23 @@ def _real_main(argv=None):
table = [[mso_id, mso_info['name']] for mso_id, mso_info in MSO_INFO.items()] table = [[mso_id, mso_info['name']] for mso_id, mso_info in MSO_INFO.items()]
write_string('Supported TV Providers:\n' + render_table(['mso', 'mso name'], table) + '\n', out=sys.stdout) write_string('Supported TV Providers:\n' + render_table(['mso', 'mso name'], table) + '\n', out=sys.stdout)
sys.exit(0) sys.exit(0)
if opts.determine_extractors:
status = 1
for url in all_urls:
if re.match(r'^[^\s/]+\.[^\s/]+/', url): # generic.py
write_string('The url doesn\'t specify the protocol, trying with http\n', out=sys.stderr)
url = 'http://' + url
for ie in list_extractors(opts.age_limit):
if not ie._WORKING or ie.IE_NAME == 'generic':
continue
try:
if re.match(getattr(ie, '_VALID_URL'), url):
write_string(ie.IE_NAME + ' ' + url + '\n', out=sys.stdout)
status = 0
break
except AttributeError:
pass
sys.exit(status)
# Conflicting, missing and erroneous options # Conflicting, missing and erroneous options
if opts.usenetrc and (opts.username is not None or opts.password is not None): if opts.usenetrc and (opts.username is not None or opts.password is not None):

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:

View File

@ -159,6 +159,10 @@ def parseOpts(overrideArguments=None):
'--extractor-descriptions', '--extractor-descriptions',
action='store_true', dest='list_extractor_descriptions', default=False, action='store_true', dest='list_extractor_descriptions', default=False,
help='Output descriptions of all supported extractors') help='Output descriptions of all supported extractors')
general.add_option(
'--determine-extractors',
action='store_true', dest='determine_extractors', default=False,
help='List the extractor that would be used for each URL. Exit status indicates at least one successful match.')
general.add_option( general.add_option(
'--force-generic-extractor', '--force-generic-extractor',
action='store_true', dest='force_generic_extractor', default=False, action='store_true', dest='force_generic_extractor', default=False,