Imporve types

This commit is contained in:
Ivan Habunek 2024-03-30 07:52:43 +01:00
parent 11fbfd35fc
commit 5dcc868275
No known key found for this signature in database
GPG Key ID: F5F0623FF5EBCB3D
3 changed files with 21 additions and 8 deletions

View File

@ -14,8 +14,8 @@ def videos(
json: bool,
limit: int | None,
pager: int | None,
sort: str,
type: str,
sort: twitch.VideosSort,
type: twitch.VideosType,
):
game_ids = _get_game_ids(games)
@ -65,7 +65,7 @@ def videos(
)
def _get_game_ids(names):
def _get_game_ids(names: list[str]) -> list[str]:
if not names:
return []

View File

@ -61,7 +61,7 @@ def print_out(*args, **kwargs):
def print_json(data: Any):
print(json.dumps(data))
click.echo(json.dumps(data))
def print_err(*args, **kwargs):
@ -126,7 +126,7 @@ def print_video_compact(video):
print_out(f'<b>{id}</b> {date} <green>{title}</green> <blue>{game}</blue>')
def print_paged_videos(generator, page_size, total_count):
def print_paged_videos(generator, page_size: int, total_count: int):
iterator = iter(generator)
page = list(islice(iterator, page_size))

View File

@ -6,8 +6,9 @@ import httpx
import json
import click
from typing import Dict
from typing import Dict, Generator, Literal
from twitchdl import CLIENT_ID
from twitchdl.entities import Data
from twitchdl.exceptions import ConsoleError
@ -262,8 +263,20 @@ def get_channel_videos(
return response["data"]["user"]["videos"]
def channel_videos_generator(channel_id, max_videos, sort, type, game_ids=[]):
def _generator(videos, max_videos):
VideosSort = Literal["views", "time"]
VideosType = Literal["archive", "highlight", "upload"]
def channel_videos_generator(
channel_id: str,
max_videos: int,
sort: VideosSort,
type: VideosType,
game_ids: list[str] | None = None
) -> tuple[int, Generator[Data, None, None]]:
game_ids = game_ids or []
def _generator(videos: Data, max_videos: int) -> Generator[Data, None, None]:
for video in videos["edges"]:
if max_videos < 1:
return