- webpage = self._download_webpage(url, video_id)
-
- clip = self._parse_json(
- self._search_regex(
- r'(?s)clipInfo\s*=\s*({.+?});', webpage, 'clip info'),
- video_id, transform_source=js_to_json)
-
- title = clip.get('channel_title') or self._og_search_title(webpage)
-
- formats = [{
- 'url': option['source'],
- 'format_id': option.get('quality'),
- 'height': int_or_none(option.get('quality')),
- } for option in clip.get('quality_options', []) if option.get('source')]
-
- if not formats:
- formats = [{
- 'url': clip['clip_video_url'],
- }]
+ clip = self._download_json(
+ 'https://gql.twitch.tv/gql', video_id, 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
+ }
+ viewCount
+ }
+}''' % video_id,
+ }).encode(), headers={
+ 'Client-ID': self._CLIENT_ID,
+ })['data']['clip']
+
+ if not clip:
+ raise ExtractorError(
+ 'This clip is no longer available', expected=True)