rssVideos: Support list filters
This commit is contained in:
parent
9100edac1e
commit
f11338a04a
|
@ -13,6 +13,7 @@ import functools
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import pickle
|
import pickle
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import typing
|
import typing
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
@ -184,6 +185,19 @@ class RVElement:
|
||||||
return
|
return
|
||||||
self.download()
|
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:
|
class RVDatabase:
|
||||||
SAVE_FILE = ".cache.p"
|
SAVE_FILE = ".cache.p"
|
||||||
|
@ -344,6 +358,10 @@ def get_args() -> configargparse.Namespace:
|
||||||
|
|
||||||
sc_list = subparsers.add_parser("list")
|
sc_list = subparsers.add_parser("list")
|
||||||
sc_list.set_defaults(subcommand=RVCommand.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 = parser.parse_args()
|
||||||
args.videos = os.path.realpath(os.path.expanduser(args.videos))
|
args.videos = os.path.realpath(os.path.expanduser(args.videos))
|
||||||
|
@ -373,6 +391,8 @@ def main() -> None:
|
||||||
if not cache:
|
if not cache:
|
||||||
raise FileNotFoundError("This command doesn't work without a cache yet.")
|
raise FileNotFoundError("This command doesn't work without a cache yet.")
|
||||||
for element in cache.elements:
|
for element in cache.elements:
|
||||||
|
if not element.matches_search(args):
|
||||||
|
continue
|
||||||
print(element)
|
print(element)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue