mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-03-09 12:50:23 -05:00
Separate playlist-end and 5000 limit checking
for accuracy and readability
This commit is contained in:
parent
1564c71921
commit
ec1d3c97d0
1 changed files with 7 additions and 4 deletions
|
@ -97,8 +97,8 @@ def _extract_info(self, gif_data, video_id):
|
||||||
'subtitles': subtitles,
|
'subtitles': subtitles,
|
||||||
}
|
}
|
||||||
|
|
||||||
def _api_channel_feed(self, channel_id, max_offset=_GIPHY_MAX):
|
def _api_channel_feed(self, channel_id):
|
||||||
offset = 0
|
count, offset = 0, 0
|
||||||
query_url = f'https://giphy.com/api/v4/channels/{channel_id}/feed/?offset={offset}'
|
query_url = f'https://giphy.com/api/v4/channels/{channel_id}/feed/?offset={offset}'
|
||||||
for _ in itertools.count(1):
|
for _ in itertools.count(1):
|
||||||
search_results = self._download_json(query_url, channel_id, fatal=False,
|
search_results = self._download_json(query_url, channel_id, fatal=False,
|
||||||
|
@ -110,10 +110,13 @@ def _api_channel_feed(self, channel_id, max_offset=_GIPHY_MAX):
|
||||||
**self._extract_info(video, video['id']),
|
**self._extract_info(video, video['id']),
|
||||||
'webpage_url': video['url'],
|
'webpage_url': video['url'],
|
||||||
}
|
}
|
||||||
|
count += len(search_results.get('results'))
|
||||||
|
if count >= (int_or_none(self.get_param('playlistend')) or (self._GIPHY_MAX + 1)):
|
||||||
|
return
|
||||||
query_url = url_or_none(search_results.get('next')) or ''
|
query_url = url_or_none(search_results.get('next')) or ''
|
||||||
offset = int(self._search_regex(r'offset=(\d+)', query_url, 'offset', default=0))
|
offset = int(self._search_regex(r'offset=(\d+)', query_url, 'offset', default=0))
|
||||||
# offset cannot exceed 5000
|
# offset cannot exceed 5000
|
||||||
if not query_url or offset > min((max_offset or self._GIPHY_MAX) + 1, self._GIPHY_MAX):
|
if not query_url or offset > self._GIPHY_MAX:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@ -242,7 +245,7 @@ def _real_extract(self, url):
|
||||||
if channel_id := self._html_search_regex(r'\{"channelId":\s*([^\}]+)\}', webpage, 'channel_id', default=None):
|
if channel_id := self._html_search_regex(r'\{"channelId":\s*([^\}]+)\}', webpage, 'channel_id', default=None):
|
||||||
uploader_id = self._html_search_meta('twitter:creator', webpage).replace('@', '').lower()
|
uploader_id = self._html_search_meta('twitter:creator', webpage).replace('@', '').lower()
|
||||||
entries = []
|
entries = []
|
||||||
for i in self._api_channel_feed(channel_id, int_or_none(self.get_param('playlistend'))):
|
for i in self._api_channel_feed(channel_id):
|
||||||
entries.append(i)
|
entries.append(i)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in a new issue