From f1b310f8776775d5cee7274255ebfd662834bfb6 Mon Sep 17 00:00:00 2001 From: Pavle Portic Date: Wed, 13 Oct 2021 23:53:35 +0200 Subject: [PATCH] Implement print url only function --- ytrssil/__init__.py | 3 ++- ytrssil/cli.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ytrssil/__init__.py b/ytrssil/__init__.py index defcd3d..57fff3f 100644 --- a/ytrssil/__init__.py +++ b/ytrssil/__init__.py @@ -1,10 +1,11 @@ from collections.abc import Sequence -from ytrssil.api import get_new_videos +from ytrssil.api import get_new_video_count, get_new_videos from ytrssil.datatypes import Channel, Video __all__: Sequence[str] = ( 'Channel', 'Video', + 'get_new_video_count', 'get_new_videos', ) diff --git a/ytrssil/cli.py b/ytrssil/cli.py index 2f327c0..553c592 100644 --- a/ytrssil/cli.py +++ b/ytrssil/cli.py @@ -71,6 +71,32 @@ def watch_videos( return 0 +@autoparams() +def print_url( + repository_manager: ChannelRepository, + fetcher: Fetcher, +) -> int: + with repository_manager as repository: + channels, new_videos = fetcher.fetch_new_videos() + if not new_videos: + print('No new videos', file=stderr) + return 1 + + selected_videos = user_query(new_videos) + if not selected_videos: + print('No video selected', file=stderr) + return 2 + + for video in selected_videos: + selected_channel = channels[video.channel_id] + selected_channel.mark_video_as_watched(video) + watch_timestamp = datetime.utcnow().replace(tzinfo=timezone.utc) + repository.update_video(video, watch_timestamp) + print(video.url) + + return 0 + + @autoparams() def watch_history( repository_manager: ChannelRepository, @@ -121,6 +147,8 @@ def main(args: list[str] = argv) -> int: if command == 'watch': return watch_videos() + elif command == 'print': + return print_url() elif command == 'history': return watch_history() elif command == 'mark':