rssVideos: Add list command

Then you know which video you should watch next :)
This commit is contained in:
Geoffrey Frogeye 2021-12-10 23:13:29 +01:00
parent 814b316584
commit 7d9fa984a6
Signed by: geoffrey
GPG key ID: C72403E7F82E6AD8

View file

@ -41,6 +41,9 @@ def configure_logging(args: configargparse.Namespace) -> None:
logger=log, logger=log,
) )
class RVCommand(enum.Enum):
download = "download"
list = "list"
class RVElement: class RVElement:
title: str title: str
@ -302,6 +305,15 @@ def get_args() -> configargparse.Namespace:
action="store_true", action="store_true",
) )
parser.set_defaults(subcommand=RVCommand.download)
subparsers = parser.add_subparsers(title="subcommand")
sc_download = subparsers.add_parser("download")
sc_download.set_defaults(subcommand=RVCommand.download)
sc_list = subparsers.add_parser("list")
sc_list.set_defaults(subcommand=RVCommand.list)
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))
@ -315,14 +327,22 @@ def main() -> None:
os.makedirs(args.videos, exist_ok=True) os.makedirs(args.videos, exist_ok=True)
os.chdir(args.videos) os.chdir(args.videos)
database = RVDatabase(args) if args.subcommand == RVCommand.download:
database.read_feed() database = RVDatabase(args)
cache = RVDatabase.load() database.read_feed()
if cache: cache = RVDatabase.load()
database.read_cache(cache) if cache:
database.clean() database.read_cache(cache)
database.act_all() database.clean()
database.save() database.act_all()
database.save()
elif args.subcommand == RVCommand.list:
cache = RVDatabase.load()
if not cache:
raise FileNotFoundError("This command doesn't work without a cache yet.")
for element in cache.elements:
print(element)
if __name__ == "__main__": if __name__ == "__main__":