Implement print url only function
This commit is contained in:
parent
10045645e1
commit
f1b310f877
|
@ -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',
|
||||
)
|
||||
|
|
|
@ -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':
|
||||
|
|
Loading…
Reference in New Issue