1
0
mirror of https://github.com/yt-dlp/yt-dlp synced 2025-07-12 16:47:39 -05:00

Handle more playlist errors with -i

This commit is contained in:
pukkandan
2021-09-04 03:07:27 +05:30
parent 165efb823b
commit 8e5fecc88c
2 changed files with 29 additions and 15 deletions

View File

@ -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):