Add subscribe command
This commit is contained in:
parent
0bd40a67cb
commit
bc7d76c561
|
@ -29,6 +29,9 @@ def user_query(videos: list[Video], reverse: bool = False) -> list[str]:
|
|||
videos_str: list[str] = stdout.decode('UTF-8').strip().split('\n')
|
||||
ret: list[str] = []
|
||||
for video_str in videos_str:
|
||||
if video_str == '':
|
||||
continue
|
||||
|
||||
*_, video_id = video_str.split(' - ')
|
||||
|
||||
try:
|
||||
|
@ -40,7 +43,7 @@ def user_query(videos: list[Video], reverse: bool = False) -> list[str]:
|
|||
|
||||
|
||||
@autoparams()
|
||||
def fetch_new_videos(client: Client) -> int:
|
||||
def fetch(client: Client) -> int:
|
||||
client.fetch()
|
||||
return 0
|
||||
|
||||
|
@ -51,6 +54,12 @@ def register(client: Client) -> int:
|
|||
return 0
|
||||
|
||||
|
||||
@autoparams('client')
|
||||
def subscribe_to_channel(client: Client, channel_id: str) -> int:
|
||||
client.subscribe_to_channel(channel_id)
|
||||
return 0
|
||||
|
||||
|
||||
@autoparams()
|
||||
def watch_videos(config: Configuration, client: Client) -> int:
|
||||
videos = client.get_new_videos()
|
||||
|
@ -164,9 +173,18 @@ def main(args: list[str] = argv) -> Any:
|
|||
command = 'watch'
|
||||
|
||||
if command == 'fetch':
|
||||
return fetch_new_videos()
|
||||
return fetch()
|
||||
elif command == 'register':
|
||||
return register()
|
||||
elif command == 'subscribe':
|
||||
if len(args) < 3:
|
||||
print(
|
||||
'Missing channel ID argument for subscribe command',
|
||||
file=stderr,
|
||||
)
|
||||
return 1
|
||||
|
||||
return subscribe_to_channel(channel_id=args[2])
|
||||
elif command == 'watch':
|
||||
return watch_videos()
|
||||
elif command == 'print':
|
||||
|
|
|
@ -2,7 +2,7 @@ import requests
|
|||
from inject import autoparams
|
||||
|
||||
from ytrssil.config import Configuration
|
||||
from ytrssil.datatypes import User, Video
|
||||
from ytrssil.datatypes import Video
|
||||
|
||||
|
||||
class HttpClient:
|
||||
|
@ -33,7 +33,7 @@ class HttpClient:
|
|||
resp.raise_for_status()
|
||||
|
||||
def get_new_videos(self) -> list[Video]:
|
||||
resp = requests.post(
|
||||
resp = requests.get(
|
||||
url=f'{self.base_url}/api/videos/new',
|
||||
auth=self.auth,
|
||||
)
|
||||
|
@ -46,7 +46,7 @@ class HttpClient:
|
|||
return ret
|
||||
|
||||
def get_watched_videos(self) -> list[Video]:
|
||||
resp = requests.post(
|
||||
resp = requests.get(
|
||||
url=f'{self.base_url}/api/videos/watched',
|
||||
auth=self.auth,
|
||||
)
|
||||
|
|
|
@ -6,13 +6,13 @@ from typing import Optional
|
|||
@dataclass
|
||||
class Video:
|
||||
video_id: str
|
||||
name: str
|
||||
title: str
|
||||
channel_name: str
|
||||
timestamp: datetime
|
||||
published_timestamp: datetime
|
||||
watch_timestamp: Optional[datetime] = None
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f'{self.channel_name} - {self.name} - {self.video_id}'
|
||||
return f'{self.channel_name} - {self.title} - {self.video_id}'
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
Loading…
Reference in New Issue