From f11338a04a956c71b6c38b78128fe3a71915d268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20=E2=80=9CFrogeye=E2=80=9D=20Preud=27homme?= Date: Fri, 17 Dec 2021 22:13:46 +0100 Subject: [PATCH] rssVideos: Support list filters --- config/scripts/rssVideos | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/config/scripts/rssVideos b/config/scripts/rssVideos index 7e8687b..87c8ab7 100755 --- a/config/scripts/rssVideos +++ b/config/scripts/rssVideos @@ -13,6 +13,7 @@ import functools import logging import os import pickle +import re import sys import typing import urllib.parse @@ -184,6 +185,19 @@ class RVElement: return self.download() + def matches_search(self, args: configargparse.Namespace) -> bool: + if not self.is_video: + return False + if args.title and not re.search(args.title, self.title): + return False + if args.creator and not re.search(args.creator, self.creator): + return False + if args.guid and not re.search(args.guid, str(self.guid)): + return False + if args.link and not re.search(args.link, self.link): + return False + return True + class RVDatabase: SAVE_FILE = ".cache.p" @@ -344,6 +358,10 @@ def get_args() -> configargparse.Namespace: sc_list = subparsers.add_parser("list") sc_list.set_defaults(subcommand=RVCommand.list) + sc_list.add("--guid", help="Regex to filter guid") + sc_list.add("--creator", help="Regex to filter creator") + sc_list.add("--title", help="Regex to filter titles") + sc_list.add("--link", help="Regex to filter link") args = parser.parse_args() args.videos = os.path.realpath(os.path.expanduser(args.videos)) @@ -373,6 +391,8 @@ def main() -> None: if not cache: raise FileNotFoundError("This command doesn't work without a cache yet.") for element in cache.elements: + if not element.matches_search(args): + continue print(element)