Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[twitch] Switch access token to GraphQL and refactor. #27646

Closed
wants to merge 1 commit into from

Conversation

23rd
Copy link

@23rd 23rd commented Jan 3, 2021

Before submitting a pull request make sure you have:

In order to be accepted and merged into youtube-dl each piece of code must be in public domain or released under Unlicense. Check one of the following options:

  • I am the original author of this code and I am willing to release it under Unlicense
  • I am not the original author of this code but it is in public domain or released under Unlicense (provide reliable evidence)

What is the purpose of your pull request?

  • Bug fix
  • Improvement
  • New extractor
  • New feature

Description of your pull request and other information

The main purpose of this PR is switching endpoint for the access token from the old api.twitch.tv/api to the newest GraphQL.
Looks like the api.twitch.tv/api endpoint is still working, but it will be rejected at any time. The twitch.tv frontend already uses GraphQL requests to get the access token.

Side changes:

  • Removed unused _download_access_token method.
  • Moved TwitchGraphQLBaseIE class to the top after TwitchBaseIE class.
  • Added a new _download_base_gql method to make general GraphQL requests and remove repeated https://gql.twitch.tv/gql endpoint strings.

I am open to suggestions for improving the code of this PR.

youtube_dl/extractor/twitch.py Outdated Show resolved Hide resolved
youtube_dl/extractor/twitch.py Outdated Show resolved Hide resolved
youtube_dl/extractor/twitch.py Outdated Show resolved Hide resolved
Comment on lines 212 to 220
def _download_vod_access_token_gql(self, video_id):
return self._download_access_token_gql(
video_id, 'videoPlaybackAccessToken', 'id',
'Downloading %s access token JSON GraphQL' % video_id)

def _download_stream_access_token_gql(self, channel_name):
return self._download_access_token_gql(
channel_name, 'streamPlaybackAccessToken', 'channelName',
'Downloading access token JSON GraphQL')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline.

youtube_dl/extractor/twitch.py Outdated Show resolved Hide resolved
youtube_dl/extractor/twitch.py Outdated Show resolved Hide resolved
youtube_dl/extractor/twitch.py Outdated Show resolved Hide resolved
@galipmedia
Copy link

Can anyone here help me? I am trying to hit the endpoint as specified in the code but I am not getting an access token back as the 'value' but rather a json object...

  data: {
    videoPlaybackAccessToken: {
      value: '{"authorization":{"forbidden":false,"reason":""},"chansub":{"restricted_bitrates":[]},"device_id":null,"expires":1610841132,"https_required":true,"privileged":false,"user_id":null,"version":2,"vod_id":1234567}',
      signature: '99aecf120103b0bb375bad907aa17a880c51d3c0',
      __typename: 'PlaybackAccessToken'
    }
  },
  extensions: { durationMilliseconds: 70, requestID: '01EW4N4TJSA64ACG62Q2G6KPZM' }
}

I am using the same Client-ID that was working with the old api.

@TaoziDB
Copy link

TaoziDB commented Jan 16, 2021

'value' you got is a string, the same as 'value' from using old API.

@galipmedia
Copy link

Aha thanks @TaoziDB it works, i just had to uri encode it for the next call.

ThirumalaiK pushed a commit to ThirumalaiK/youtube-dl that referenced this pull request Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants