diff --git a/twitchdl/commands/download.py b/twitchdl/commands/download.py index 24b3ed3..e70f5f9 100644 --- a/twitchdl/commands/download.py +++ b/twitchdl/commands/download.py @@ -20,7 +20,7 @@ from twitchdl.entities import DownloadOptions from twitchdl.exceptions import ConsoleError from twitchdl.http import download_all from twitchdl.output import blue, bold, dim, green, print_log, yellow -from twitchdl.twitch import Chapter, Clip, Video +from twitchdl.twitch import Chapter, Clip, ClipAccessToken, Video def download(ids: list[str], args: DownloadOptions): @@ -211,8 +211,8 @@ def _crete_temp_dir(base_uri: str) -> str: return str(temp_dir) -def _get_clip_url(clip: Clip, quality: str) -> str: - qualities = clip["videoQualities"] +def _get_clip_url(access_token: ClipAccessToken, quality: str) -> str: + qualities = access_token["videoQualities"] # Quality given as an argument if quality: @@ -250,8 +250,8 @@ def get_clip_authenticated_url(slug: str, quality: str): query = urlencode( { - "sig": access_token["signature"], - "token": access_token["value"], + "sig": access_token["playbackAccessToken"]["signature"], + "token": access_token["playbackAccessToken"]["value"], } ) diff --git a/twitchdl/twitch.py b/twitchdl/twitch.py index 6349c41..fbeef5e 100644 --- a/twitchdl/twitch.py +++ b/twitchdl/twitch.py @@ -38,6 +38,12 @@ class VideoQuality(TypedDict): sourceURL: str +class ClipAccessToken(TypedDict): + id: str + playbackAccessToken: AccessToken + videoQualities: list[VideoQuality] + + class Clip(TypedDict): id: str slug: str @@ -183,7 +189,7 @@ def get_clip(slug: str) -> Clip | None: return response["data"]["clip"] -def get_clip_access_token(slug: str) -> AccessToken: +def get_clip_access_token(slug: str) -> ClipAccessToken: query = f""" {{ "operationName": "VideoAccessToken_Clip", @@ -200,7 +206,7 @@ def get_clip_access_token(slug: str) -> AccessToken: """ response = gql_post(query.strip()) - return response["data"]["clip"]["playbackAccessToken"] + return response["data"]["clip"] def get_channel_clips(channel_id: str, period: ClipsPeriod, limit: int, after: str | None = None):