Skip to content

Conversation

@bastimeyer
Copy link
Member

Resolves #3341

Twitch's old private API namespace /api has already been deprecated and replaced by their new private GraphQL API when they redesigned their website several years ago. The only exception until yesterday were the access_token requests, which have now fully migrated after a couple of weeks of testing from what it looked like.

Since it is unknown how long the old API namespace will stay available, we'll have to move the access_token request at some point.

This commit switches the access_token API request to the GQL API and uses the PlaybackAccessToken query with the persistedQuery sha256 hash of 0828119ded1c13477966434e15800ff57ddacf13ba1911c129dc2200705b0712. This is the checksum of the actual GraphQL query for server-caching purposes and for Streamlink, this simply means that the query doesn't have to be defined here.

Tested with live streams and vods:

$ streamlink -l debug twitch.tv/shroud
[cli][debug] OS:         Linux-5.10.0-rc4-1-git-x86_64-with-glibc2.2.5
[cli][debug] Python:     3.8.6
[cli][debug] Streamlink: 1.7.0+66.ga98872e
[cli][debug] Requests(2.24.0), Socks(1.7.1), Websocket(0.56.0)
[cli][info] Found matching plugin twitch for URL twitch.tv/shroud
[plugin.twitch][debug] Getting live HLS streams for shroud
[utils.l10n][debug] Language code: en_US
Available streams: audio_only, 160p (worst), 360p, 480p, 720p, 720p60, 936p60 (best)

$ streamlink -l debug https://www.twitch.tv/videos/807481367
[cli][debug] OS:         Linux-5.10.0-rc4-1-git-x86_64-with-glibc2.2.5
[cli][debug] Python:     3.8.6
[cli][debug] Streamlink: 1.7.0+66.ga98872e
[cli][debug] Requests(2.24.0), Socks(1.7.1), Websocket(0.56.0)
[cli][info] Found matching plugin twitch for URL https://www.twitch.tv/videos/807481367
[plugin.twitch][debug] Getting video HLS streams for shroud
[utils.l10n][debug] Language code: en_US
Available streams: audio, 160p (worst), 360p, 480p, 720p, 720p60, 936p60 (best)

@bastimeyer bastimeyer added the plugin issue A Plugin does not work correctly label Nov 18, 2020
@gravyboat
Copy link
Member

This looks good to me @bastimeyer.

@bastimeyer
Copy link
Member Author

Btw, just for the record, it seems like the old private API doesn't work anymore and access tokens can only be acquired on the GQL API, which this PR switched to:
streamlink/streamlink-twitch-gui#774 (comment)

$ streamlink -l debug twitch.tv/shroud
[cli][debug] OS:         Linux-5.10.7-1-git-x86_64-with-glibc2.32
[cli][debug] Python:     3.9.1
[cli][debug] Streamlink: 1.7.0
[cli][debug] Requests(2.25.1), Socks(1.7.1), Websocket(0.57.0)
[cli][info] Found matching plugin twitch for URL twitch.tv/shroud
[plugin.twitch][debug] Getting live HLS streams for shroud
error: No playable streams found on this URL: twitch.tv/shroud
$ streamlink -l debug twitch.tv/shroud
[cli][debug] OS:         Linux-5.10.7-1-git-x86_64-with-glibc2.32
[cli][debug] Python:     3.9.1
[cli][debug] Streamlink: 2.0.0+22.gb9d0d18
[cli][debug] Requests(2.25.1), Socks(1.7.1), Websocket(0.57.0)
[cli][info] Found matching plugin twitch for URL twitch.tv/shroud
[plugins.twitch][debug] Getting live HLS streams for shroud
[utils.l10n][debug] Language code: en_US
Available streams: audio_only, 160p (worst), 360p, 480p, 720p, 720p60, 936p60 (best)

@bastimeyer bastimeyer deleted the plugins/twitch/access-token/gql-api branch January 14, 2021 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin issue A Plugin does not work correctly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plugins.twitch: switch access token API request to GQL

2 participants