diff options
author | Tom-Oliver Heidel <github@tom-oliver.eu> | 2020-11-30 02:34:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-30 02:34:28 +0100 |
commit | e8dfaa0fd7d6c4194644df37d68efa74d5d914b2 (patch) | |
tree | 16e365935804f1f27d61f932010bc657fdea4eb1 /youtube_dlc/extractor | |
parent | 6a03f4f2a8c5c9274cce3d6168b501578d332bae (diff) | |
parent | 9da76d30decd079dbd3ca3d708e475a6201754e4 (diff) | |
download | hypervideo-pre-e8dfaa0fd7d6c4194644df37d68efa74d5d914b2.tar.lz hypervideo-pre-e8dfaa0fd7d6c4194644df37d68efa74d5d914b2.tar.xz hypervideo-pre-e8dfaa0fd7d6c4194644df37d68efa74d5d914b2.zip |
Merge pull request #208 from colethedj/ytsearchfix
[youtube] fix: ytsearch not returning results sometimes due to promoted content
Diffstat (limited to 'youtube_dlc/extractor')
-rw-r--r-- | youtube_dlc/extractor/youtube.py | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/youtube_dlc/extractor/youtube.py b/youtube_dlc/extractor/youtube.py index ad56b9b01..e87692754 100644 --- a/youtube_dlc/extractor/youtube.py +++ b/youtube_dlc/extractor/youtube.py @@ -3469,10 +3469,33 @@ class YoutubeSearchIE(SearchInfoExtractor, YoutubeBaseInfoExtractor): list) if not slr_contents: break - isr_contents = try_get( - slr_contents, - lambda x: x[0]['itemSectionRenderer']['contents'], - list) + + isr_contents = [] + continuation_token = None + # Youtube sometimes adds promoted content to searches, + # changing the index location of videos and token. + # So we search through all entries till we find them. + for index, isr in enumerate(slr_contents): + if not isr_contents: + isr_contents = try_get( + slr_contents, + (lambda x: x[index]['itemSectionRenderer']['contents']), + list) + for content in isr_contents: + if content.get('videoRenderer') is not None: + break + else: + isr_contents = [] + + if continuation_token is None: + continuation_token = try_get( + slr_contents, + lambda x: x[index]['continuationItemRenderer']['continuationEndpoint']['continuationCommand'][ + 'token'], + compat_str) + if continuation_token is not None and isr_contents: + break + if not isr_contents: break for content in isr_contents: @@ -3506,13 +3529,9 @@ class YoutubeSearchIE(SearchInfoExtractor, YoutubeBaseInfoExtractor): } if total == n: return - token = try_get( - slr_contents, - lambda x: x[1]['continuationItemRenderer']['continuationEndpoint']['continuationCommand']['token'], - compat_str) - if not token: + if not continuation_token: break - data['continuation'] = token + data['continuation'] = continuation_token def _get_n_results(self, query, n): """Get a specified number of results for a query""" |