From d6390bc7a2f42c8967bd01d0cfbfcc8a04f2dae0 Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Thu, 4 Apr 2024 08:36:10 +0200 Subject: [PATCH] Fix bug in accessing video qualities --- twitchdl/commands/download.py | 10 +++++----- twitchdl/twitch.py | 10 ++++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) 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):