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) return yt_dlp.YoutubeDL(self.ytdl_dry_opts)
def filter(self, args: configargparse.Namespace) -> typing.Iterable[RVElement]: def filter(self, args: configargparse.Namespace) -> typing.Iterable[RVElement]:
elements_src = self.elements.copy()
elements: typing.Iterable[RVElement] elements: typing.Iterable[RVElement]
# Inexpensive sort # Inexpensive sort
if args.order == "new": if args.order == "new":
elements = reversed(self.elements) elements = reversed(elements_src)
elif args.order == "title": 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": 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": 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": elif args.order == "random":
elements_random = self.elements.copy() elements = elements_src
random.shuffle(elements_random) random.shuffle(elements)
elements = elements_random
else: else:
elements = self.elements elements = elements_src
# Possibly expensive filtering # Possibly expensive filtering
elements = filter(lambda el: el.matches_filter(args), elements) elements = filter(lambda el: el.matches_filter(args), elements)