Compare commits
2 Commits
2d25012600
...
bc7d76c561
Author | SHA1 | Date |
---|---|---|
Pavle Portic | bc7d76c561 | |
Pavle Portic | 0bd40a67cb |
|
@ -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:
|
||||
|
@ -19,8 +19,10 @@ class HttpClient:
|
|||
resp.raise_for_status()
|
||||
|
||||
def register(self) -> None:
|
||||
user = User(username=self.auth.username, password=self.auth.password)
|
||||
resp = requests.post(url=f'{self.base_url}/fetch', json=user)
|
||||
resp = requests.post(url=f'{self.base_url}/register', json={
|
||||
'username': self.auth.username,
|
||||
'password': self.auth.password,
|
||||
})
|
||||
resp.raise_for_status()
|
||||
|
||||
def subscribe_to_channel(self, channel_id: str) -> None:
|
||||
|
@ -31,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,
|
||||
)
|
||||
|
@ -44,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,
|
||||
)
|
||||
|
|
|
@ -9,14 +9,14 @@ class Configuration:
|
|||
username: str
|
||||
password: str
|
||||
api_url: str = 'https://ytrssil.theedgeofrage.com'
|
||||
max_res: Literal['480', '720', '1080', '1440', '2160'] = '1440'
|
||||
max_resolution: Literal['480', '720', '1080', '1440', '2160'] = '1440'
|
||||
|
||||
@property
|
||||
def mpv_options(self) -> list[str]:
|
||||
return [
|
||||
'--no-terminal',
|
||||
f'--ytdl-format=bestvideo[height<=?{self.max_res}]+bestaudio/best',
|
||||
]
|
||||
return ['--no-terminal', (
|
||||
'--ytdl-format=bestvideo[height<=?'
|
||||
f'{self.max_resolution}]+bestaudio/best'
|
||||
)]
|
||||
|
||||
|
||||
def load_config() -> Configuration:
|
||||
|
|
|
@ -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