From 8885bb196aaa0850c1d115b694fb7ecf5071b7ab Mon Sep 17 00:00:00 2001 From: anxdpanic Date: Sat, 19 Jun 2021 18:02:51 -0400 Subject: [PATCH 1/2] fix playback of clips --- addon.xml | 3 +-- changelog.txt | 3 +++ resources/lib/twitch/api/usher.py | 39 +++++++++++-------------------- resources/lib/twitch/parser.py | 23 +++++++++++++++--- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/addon.xml b/addon.xml index ab90c9d..58b7737 100644 --- a/addon.xml +++ b/addon.xml @@ -9,8 +9,7 @@ all -[fix] playback, change access token to use gql endpoints -[chg] change followed, following, and unfollowing games to use gql endpoints +[fix] playback of clips icon.png diff --git a/changelog.txt b/changelog.txt index 09018aa..f96ca2e 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +2.0.17 +[fix] playback of clips + 2.0.16 [fix] playback, change access token to use gql endpoints [chg] change followed, following, and unfollowing games to use gql endpoints diff --git a/resources/lib/twitch/api/usher.py b/resources/lib/twitch/api/usher.py index fb82841..cd87d3b 100644 --- a/resources/lib/twitch/api/usher.py +++ b/resources/lib/twitch/api/usher.py @@ -216,31 +216,18 @@ def video(video_id, platform=keys.WEB, headers={}): @clip_embed @query def clip(slug, headers={}): - data = json.dumps({ - 'query': '''{ - clip(slug: "%s") { - broadcaster { - displayName - } - createdAt - curator { - displayName - id - } - durationSeconds - id - tiny: thumbnailURL(width: 86, height: 45) - small: thumbnailURL(width: 260, height: 147) - medium: thumbnailURL(width: 480, height: 272) - title - videoQualities { - frameRate - quality - sourceURL + qry = { + "operationName": "VideoAccessToken_Clip", + "extensions": { + "persistedQuery": { + "version": 1, + "sha256Hash": "36b89d2507fce29e5ca551df756d27c1cfe079e2609642b4390aa4c35796eb11" + } + }, + "variables": { + "slug": slug } - viewCount - } - }''' % slug, - }) - q = ClipsQuery(headers=headers, data=data) + } + + q = ClipsQuery(headers=headers, data=json.dumps(qry)) return q diff --git a/resources/lib/twitch/parser.py b/resources/lib/twitch/parser.py index b1a6c44..d46aa12 100644 --- a/resources/lib/twitch/parser.py +++ b/resources/lib/twitch/parser.py @@ -12,6 +12,8 @@ import re +from six.moves.urllib_parse import urlencode + from . import keys from .log import log @@ -58,7 +60,11 @@ def m3u8_wrapper(*args, **kwargs): else: error = re.search(_error_pattern, results) if error: - return {'error': 'Error', 'message': error.group('message'), 'status': 404} + return { + 'error': 'Error', + 'message': error.group('message'), + 'status': 404 + } return m3u8_to_list(results) return m3u8_wrapper @@ -132,7 +138,18 @@ def m3u8_to_list(string): def clip_embed_to_list(response): log.debug('clip_embed_to_list called for:\n{0}'.format(response)) - qualities = list() + + clip_json = response.get('data', {}).get('clip', {}) + access_token = clip_json.get('playbackAccessToken', {}) + token = access_token.get('value', '') + signature = access_token.get('signature', '') + qualities = clip_json.get('videoQualities', []) + + params = urlencode({ + 'sig': signature, + 'token': token + }) + l = list() if isinstance(response, dict): @@ -143,7 +160,7 @@ def clip_embed_to_list(response): l = [{ 'id': item['quality'], 'name': item['quality'], - 'url': item['sourceURL'], + 'url': item['sourceURL'] + '?' + params, 'bandwidth': -1 } for item in qualities] if l: From 144f526379db3f2c8079277b36396c07d1db28cb Mon Sep 17 00:00:00 2001 From: anxdpanic Date: Sat, 19 Jun 2021 18:03:02 -0400 Subject: [PATCH 2/2] 2.0.17 --- addon.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon.xml b/addon.xml index 58b7737..8c2afeb 100644 --- a/addon.xml +++ b/addon.xml @@ -1,5 +1,5 @@ - +