diff --git a/twitchdl/entities.py b/twitchdl/entities.py index ab1a25d..e934b0e 100644 --- a/twitchdl/entities.py +++ b/twitchdl/entities.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -from typing import Any, Mapping, Optional +from typing import Any, List, Literal, Mapping, Optional, TypedDict @dataclass @@ -20,6 +20,73 @@ class DownloadOptions: max_workers: int +ClipsPeriod = Literal["last_day", "last_week", "last_month", "all_time"] +VideosSort = Literal["views", "time"] +VideosType = Literal["archive", "highlight", "upload"] + + +class AccessToken(TypedDict): + signature: str + value: str + + +class User(TypedDict): + login: str + displayName: str + + +class Game(TypedDict): + id: str + name: str + + +class VideoQuality(TypedDict): + frameRate: str + quality: str + sourceURL: str + + +class ClipAccessToken(TypedDict): + id: str + playbackAccessToken: AccessToken + videoQualities: List[VideoQuality] + + +class Clip(TypedDict): + id: str + slug: str + title: str + createdAt: str + viewCount: int + durationSeconds: int + url: str + videoQualities: List[VideoQuality] + game: Game + broadcaster: User + + +class Video(TypedDict): + id: str + title: str + description: str + publishedAt: str + broadcastType: str + lengthSeconds: int + game: Game + creator: User + + +class Chapter(TypedDict): + id: str + durationMilliseconds: int + positionMilliseconds: int + type: str + description: str + subDescription: str + thumbnailURL: str + game: Game + + # Type for annotating decoded JSON # TODO: make data classes for common structs Data = Mapping[str, Any] diff --git a/twitchdl/output.py b/twitchdl/output.py index 77124e5..f732eab 100644 --- a/twitchdl/output.py +++ b/twitchdl/output.py @@ -6,7 +6,7 @@ from typing import Any, Callable, Generator, List, Optional, TypeVar import click from twitchdl import utils -from twitchdl.twitch import Clip, Video +from twitchdl.entities import Clip, Video T = TypeVar("T") diff --git a/twitchdl/twitch.py b/twitchdl/twitch.py index eff6730..12bba8e 100644 --- a/twitchdl/twitch.py +++ b/twitchdl/twitch.py @@ -4,81 +4,25 @@ Twitch API access. import logging import time -from typing import Any, Dict, Generator, List, Literal, Mapping, Optional, Tuple, TypedDict, Union +from typing import Any, Dict, Generator, List, Mapping, Optional, Tuple, Union import click import httpx from twitchdl import CLIENT_ID -from twitchdl.entities import Data +from twitchdl.entities import ( + AccessToken, + Chapter, + Clip, + ClipAccessToken, + ClipsPeriod, + Data, + Video, + VideosSort, + VideosType, +) from twitchdl.exceptions import ConsoleError -ClipsPeriod = Literal["last_day", "last_week", "last_month", "all_time"] -VideosSort = Literal["views", "time"] -VideosType = Literal["archive", "highlight", "upload"] - - -class AccessToken(TypedDict): - signature: str - value: str - - -class User(TypedDict): - login: str - displayName: str - - -class Game(TypedDict): - id: str - name: str - - -class VideoQuality(TypedDict): - frameRate: str - quality: str - sourceURL: str - - -class ClipAccessToken(TypedDict): - id: str - playbackAccessToken: AccessToken - videoQualities: List[VideoQuality] - - -class Clip(TypedDict): - id: str - slug: str - title: str - createdAt: str - viewCount: int - durationSeconds: int - url: str - videoQualities: List[VideoQuality] - game: Game - broadcaster: User - - -class Video(TypedDict): - id: str - title: str - description: str - publishedAt: str - broadcastType: str - lengthSeconds: int - game: Game - creator: User - - -class Chapter(TypedDict): - id: str - durationMilliseconds: int - positionMilliseconds: int - type: str - description: str - subDescription: str - thumbnailURL: str - game: Game - class GQLError(click.ClickException): def __init__(self, errors: List[str]):