From 55575225b48535ce878da8f1b8d4651fdece4259 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Mon, 17 May 2021 19:14:20 +0530 Subject: [PATCH] [utils] Add `__getitem__` for `PagedList` --- yt_dlp/utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py index 02a12307a..40b9c4cf3 100644 --- a/yt_dlp/utils.py +++ b/yt_dlp/utils.py @@ -4000,6 +4000,15 @@ def __len__(self): # This is only useful for tests return len(self.getslice()) + def getslice(self, start, end): + raise NotImplementedError('This method must be implemented by subclasses') + + def __getitem__(self, idx): + if not isinstance(idx, int) or idx < 0: + raise TypeError('indices must be non-negative integers') + entries = self.getslice(idx, idx + 1) + return entries[0] if entries else None + class OnDemandPagedList(PagedList): def __init__(self, pagefunc, pagesize, use_cache=True):