[twitch] Added support for player.twitch.tv URLs (closes #11535)
[youtube-dl] / youtube_dl / extractor / twitch.py
index 8de8ec65b842be8849c630731b1e1c3c94439c3b..09efa505b4f4ab4e88820a02da5afe6463adb5aa 100644 (file)
@@ -22,6 +22,7 @@ from ..utils import (
     orderedSet,
     parse_duration,
     parse_iso8601,
+    update_url_query,
     urlencode_postdata,
 )
 
@@ -205,7 +206,8 @@ class TwitchChapterIE(TwitchItemBaseIE):
 
 class TwitchVodIE(TwitchItemBaseIE):
     IE_NAME = 'twitch:vod'
-    _VALID_URL = r'%s/[^/]+/v/(?P<id>\d+)' % TwitchBaseIE._VALID_URL_BASE
+    _VALID_URL_BASE = r'https?://(?:www\.|player\.)?twitch\.tv'
+    _VALID_URL = r'%s/(?:[^/]+/v/|\?video=v)(?P<id>\d+)' % _VALID_URL_BASE
     _ITEM_TYPE = 'vod'
     _ITEM_SHORTCUT = 'v'
 
@@ -228,6 +230,26 @@ class TwitchVodIE(TwitchItemBaseIE):
             # m3u8 download
             'skip_download': True,
         },
+    }, {
+        # player.twitch.tv URL
+        'url': 'http://player.twitch.tv/?video=v6528877&t=5m10s',
+        'info_dict': {
+            'id': 'v6528877',
+            'ext': 'mp4',
+            'title': 'LCK Summer Split - Week 6 Day 1',
+            'thumbnail': 're:^https?://.*\.jpg$',
+            'duration': 17208,
+            'timestamp': 1435131709,
+            'upload_date': '20150624',
+            'uploader': 'Riot Games',
+            'uploader_id': 'riotgames',
+            'view_count': int,
+            'start_time': 310,
+        },
+        'params': {
+            # m3u8 download
+            'skip_download': True,
+        },
     }, {
         # Untitled broadcast (title is None)
         'url': 'http://www.twitch.tv/belkao_o/v/11230755',
@@ -279,6 +301,18 @@ class TwitchVodIE(TwitchItemBaseIE):
         if 't' in query:
             info['start_time'] = parse_duration(query['t'][0])
 
+        if info.get('timestamp') is not None:
+            info['subtitles'] = {
+                'rechat': [{
+                    'url': update_url_query(
+                        'https://rechat.twitch.tv/rechat-messages', {
+                            'video_id': 'v%s' % item_id,
+                            'start': info['timestamp'],
+                        }),
+                    'ext': 'json',
+                }],
+            }
+
         return info