[twitch] Set OAuth token for GraphQL requests using auth-token cookie (#27790)
authormain() <main@ehvag.eu.org>
Thu, 14 Jan 2021 12:41:44 +0000 (13:41 +0100)
committerGitHub <noreply@github.com>
Thu, 14 Jan 2021 12:41:44 +0000 (12:41 +0000)
Co-authored-by: remitamine <remitamine@gmail.com>
youtube_dl/extractor/twitch.py

index c4fd2f6860bd0c079379ac45d906e5061cc83fad..a7867f4d349ffbb9f4bd59973e8f832a5dc087b6 100644 (file)
@@ -138,13 +138,17 @@ class TwitchBaseIE(InfoExtractor):
         self._sort_formats(formats)
 
     def _download_base_gql(self, video_id, ops, note, fatal=True):
+        headers = {
+            'Content-Type': 'text/plain;charset=UTF-8',
+            'Client-ID': self._CLIENT_ID,
+        }
+        gql_auth = self._get_cookies('https://gql.twitch.tv').get('auth-token')
+        if gql_auth:
+            headers['Authorization'] = 'OAuth ' + gql_auth.value
         return self._download_json(
             'https://gql.twitch.tv/gql', video_id, note,
             data=json.dumps(ops).encode(),
-            headers={
-                'Content-Type': 'text/plain;charset=UTF-8',
-                'Client-ID': self._CLIENT_ID,
-            }, fatal=fatal)
+            headers=headers, fatal=fatal)
 
     def _download_gql(self, video_id, ops, note, fatal=True):
         for op in ops: