Compare commits

...

5 Commits
v0.5.1 ... main

8 changed files with 75 additions and 15 deletions

View File

@ -29,3 +29,11 @@ clean:
rm -rf $(CURDIR)/build
rm -rf $(CURDIR)/dist
rm -rf $(CURDIR)/$(NAME).egg-info
publish:
@git checkout $(shell git tag | sort -V | tail -n1) >/dev/null 2>&1
@$(MAKE) clean > /dev/null
@$(MAKE) build > /dev/null
@twine upload dist/*
@$(MAKE) clean > /dev/null
@git switch main >/dev/null 2>&1

View File

@ -34,6 +34,7 @@ setup(
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'License :: OSI Approved :: BSD License',
'Operating System :: POSIX :: Linux',
],

View File

@ -0,0 +1,10 @@
from collections.abc import Sequence
from ytrssil.api import get_new_video_count, get_new_videos
from ytrssil.datatypes import Video
__all__: Sequence[str] = (
'Video',
'get_new_video_count',
'get_new_videos',
)

21
ytrssil/api.py Normal file
View File

@ -0,0 +1,21 @@
from typing import cast
from inject import autoparams
from ytrssil.bindings import setup_dependencies
from ytrssil.datatypes import Video
from ytrssil.protocols import Client
def get_new_videos() -> list[Video]:
setup_dependencies()
@autoparams()
def _get_new_videos(client: Client) -> list[Video]:
return client.get_new_videos()
return cast(list[Video], _get_new_videos())
def get_new_video_count() -> int:
return len(get_new_videos())

View File

@ -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':

View File

@ -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,
)

View File

@ -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:

View File

@ -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