Merge remote-tracking branch 'origin/master'

This commit is contained in:
Geoffrey Frogeye 2022-01-08 16:35:21 +01:00
commit 1ba2a75749

View file

@ -464,22 +464,22 @@ class RVDatabase:
return yt_dlp.YoutubeDL(self.ytdl_dry_opts)
def filter(self, args: configargparse.Namespace) -> typing.Iterable[RVElement]:
elements_src = self.elements.copy()
elements: typing.Iterable[RVElement]
# Inexpensive sort
if args.order == "new":
elements = reversed(self.elements)
elements = reversed(elements_src)
elif args.order == "title":
elements = sorted(self.elements, key=lambda el: el.title)
elements = sorted(elements_src, key=lambda el: el.title)
elif args.order == "creator":
elements = sorted(self.elements, key=lambda el: el.creator or "")
elements = sorted(elements_src, key=lambda el: el.creator or "")
elif args.order == "link":
elements = sorted(self.elements, key=lambda el: el.link)
elements = sorted(elements_src, key=lambda el: el.link)
elif args.order == "random":
elements_random = self.elements.copy()
random.shuffle(elements_random)
elements = elements_random
elements = elements_src
random.shuffle(elements)
else:
elements = self.elements
elements = elements_src
# Possibly expensive filtering
elements = filter(lambda el: el.matches_filter(args), elements)