aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/utils.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2021-09-04 03:07:27 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2021-09-04 03:07:27 +0530
commit8e5fecc88c53611de538a50c1e51eb048b1544e6 (patch)
treede1e17f6769added81c1d844f5f30fc7f6c4fc22 /yt_dlp/utils.py
parent165efb823b3a8a6a6788cfe23e6b93dfbe150568 (diff)
downloadhypervideo-pre-8e5fecc88c53611de538a50c1e51eb048b1544e6.tar.lz
hypervideo-pre-8e5fecc88c53611de538a50c1e51eb048b1544e6.tar.xz
hypervideo-pre-8e5fecc88c53611de538a50c1e51eb048b1544e6.zip
Handle more playlist errors with `-i`
Diffstat (limited to 'yt_dlp/utils.py')
-rw-r--r--yt_dlp/utils.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py
index fa9c509b2..65d585d05 100644
--- a/yt_dlp/utils.py
+++ b/yt_dlp/utils.py
@@ -3972,6 +3972,9 @@ class LazyList(collections.abc.Sequence):
''' Lazy immutable list from an iterable
Note that slices of a LazyList are lists and not LazyList'''
+ class IndexError(IndexError):
+ pass
+
def __init__(self, iterable):
self.__iterable = iter(iterable)
self.__cache = []
@@ -4015,22 +4018,28 @@ class LazyList(collections.abc.Sequence):
or (stop is None and step > 0)):
# We need to consume the entire iterable to be able to slice from the end
# Obviously, never use this with infinite iterables
- return self.__exhaust()[idx]
-
+ self.__exhaust()
+ try:
+ return self.__cache[idx]
+ except IndexError as e:
+ raise self.IndexError(e) from e
n = max(start or 0, stop or 0) - len(self.__cache) + 1
if n > 0:
self.__cache.extend(itertools.islice(self.__iterable, n))
- return self.__cache[idx]
+ try:
+ return self.__cache[idx]
+ except IndexError as e:
+ raise self.IndexError(e) from e
def __bool__(self):
try:
self[-1] if self.__reversed else self[0]
- except IndexError:
+ except self.IndexError:
return False
return True
def __len__(self):
- self.exhaust()
+ self.__exhaust()
return len(self.__cache)
def reverse(self):