From d37707bda466282b66ce381cbfd734f899f9e06e Mon Sep 17 00:00:00 2001 From: pukkandan Date: Sun, 23 Jan 2022 23:25:17 +0530 Subject: [PATCH] Fix/improve `InAdvancePagedList` --- yt_dlp/YoutubeDL.py | 4 ++++ yt_dlp/utils.py | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index baf54cd2e..d3bcd84a7 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -72,6 +72,7 @@ GeoRestrictedError, get_domain, HEADRequest, + InAdvancePagedList, int_or_none, iri_to_uri, ISO3166Utils, @@ -1662,6 +1663,9 @@ def get_entry(i): msg = 'Downloading %d videos' if not isinstance(ie_entries, (PagedList, LazyList)): ie_entries = LazyList(ie_entries) + elif isinstance(ie_entries, InAdvancePagedList): + if ie_entries._pagesize == 1: + playlist_count = ie_entries._pagecount def get_entry(i): return YoutubeDL.__handle_extraction_exceptions( diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py index 55bd67ea2..2b33e1ec9 100644 --- a/yt_dlp/utils.py +++ b/yt_dlp/utils.py @@ -2845,8 +2845,7 @@ def __init__(self, pagefunc, pagecount, pagesize): def _getslice(self, start, end): start_page = start // self._pagesize - end_page = ( - self._pagecount if end is None else (end // self._pagesize + 1)) + end_page = self._pagecount if end is None else min(self._pagecount, end // self._pagesize + 1) skip_elems = start - start_page * self._pagesize only_more = None if end is None else end - start for pagenum in range(start_page, end_page):