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 baf54cd2e4..d3bcd84a7a 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -72,6 +72,7 @@ from .utils import ( GeoRestrictedError, get_domain, HEADRequest, + InAdvancePagedList, int_or_none, iri_to_uri, ISO3166Utils, @@ -1662,6 +1663,9 @@ class YoutubeDL(object): 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 55bd67ea2f..2b33e1ec9e 100644 --- a/yt_dlp/utils.py +++ b/yt_dlp/utils.py @@ -2845,8 +2845,7 @@ class InAdvancePagedList(PagedList): 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):