twitch.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import itertools
  4. import re
  5. import random
  6. from .common import InfoExtractor
  7. from ..compat import (
  8. compat_HTTPError,
  9. compat_parse_qs,
  10. compat_str,
  11. compat_urllib_parse_urlencode,
  12. compat_urllib_parse_urlparse,
  13. )
  14. from ..utils import (
  15. clean_html,
  16. ExtractorError,
  17. int_or_none,
  18. js_to_json,
  19. orderedSet,
  20. parse_duration,
  21. parse_iso8601,
  22. update_url_query,
  23. urlencode_postdata,
  24. urljoin,
  25. )
  26. class TwitchBaseIE(InfoExtractor):
  27. _VALID_URL_BASE = r'https?://(?:www\.)?twitch\.tv'
  28. _API_BASE = 'https://api.twitch.tv'
  29. _USHER_BASE = 'https://usher.ttvnw.net'
  30. _LOGIN_URL = 'https://www.twitch.tv/login'
  31. _CLIENT_ID = 'jzkbprff40iqj646a697cyrvl0zt2m6'
  32. _NETRC_MACHINE = 'twitch'
  33. def _handle_error(self, response):
  34. if not isinstance(response, dict):
  35. return
  36. error = response.get('error')
  37. if error:
  38. raise ExtractorError(
  39. '%s returned error: %s - %s' % (self.IE_NAME, error, response.get('message')),
  40. expected=True)
  41. def _call_api(self, path, item_id, note):
  42. response = self._download_json(
  43. '%s/%s' % (self._API_BASE, path), item_id, note,
  44. headers={'Client-ID': self._CLIENT_ID})
  45. self._handle_error(response)
  46. return response
  47. def _real_initialize(self):
  48. self._login()
  49. def _login(self):
  50. (username, password) = self._get_login_info()
  51. if username is None:
  52. return
  53. def fail(message):
  54. raise ExtractorError(
  55. 'Unable to login. Twitch said: %s' % message, expected=True)
  56. def post_login_form(page, urlh, note, data):
  57. form = self._hidden_inputs(page)
  58. form.update(data)
  59. page_url = urlh.geturl()
  60. post_url = self._search_regex(
  61. r'<form[^>]+action=(["\'])(?P<url>.+?)\1', page,
  62. 'post url', default=page_url, group='url')
  63. post_url = urljoin(page_url, post_url)
  64. headers = {'Referer': page_url}
  65. try:
  66. response = self._download_json(
  67. post_url, None, note,
  68. data=urlencode_postdata(form),
  69. headers=headers)
  70. except ExtractorError as e:
  71. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 400:
  72. response = self._parse_json(
  73. e.cause.read().decode('utf-8'), None)
  74. fail(response['message'])
  75. raise
  76. if response.get('redirect'):
  77. redirect_url = urljoin(post_url, response['redirect'])
  78. return self._download_webpage_handle(
  79. redirect_url, None, 'Downloading login redirect page',
  80. headers=headers)
  81. login_page, handle = self._download_webpage_handle(
  82. self._LOGIN_URL, None, 'Downloading login page')
  83. # Some TOR nodes and public proxies are blocked completely
  84. if 'blacklist_message' in login_page:
  85. fail(clean_html(login_page))
  86. login_data = {
  87. 'username': username,
  88. 'password': password,
  89. }
  90. redirect_res = post_login_form(
  91. login_page, handle, 'Logging in as %s' % username, login_data)
  92. if not redirect_res:
  93. return
  94. redirect_page, handle = redirect_res
  95. if re.search(r'(?i)<form[^>]+id="two-factor-submit"', redirect_page) is not None:
  96. # TODO: Add mechanism to request an SMS or phone call
  97. tfa_token = self._get_tfa_info('two-factor authentication token')
  98. tfa_data = {
  99. 'authy_token': tfa_token,
  100. 'remember_2fa': 'true',
  101. }
  102. post_login_form(redirect_page, handle, 'Submitting TFA token', tfa_data)
  103. def _prefer_source(self, formats):
  104. try:
  105. source = next(f for f in formats if f['format_id'] == 'Source')
  106. source['preference'] = 10
  107. except StopIteration:
  108. pass # No Source stream present
  109. self._sort_formats(formats)
  110. class TwitchItemBaseIE(TwitchBaseIE):
  111. def _download_info(self, item, item_id):
  112. return self._extract_info(self._call_api(
  113. 'kraken/videos/%s%s' % (item, item_id), item_id,
  114. 'Downloading %s info JSON' % self._ITEM_TYPE))
  115. def _extract_media(self, item_id):
  116. info = self._download_info(self._ITEM_SHORTCUT, item_id)
  117. response = self._call_api(
  118. 'api/videos/%s%s' % (self._ITEM_SHORTCUT, item_id), item_id,
  119. 'Downloading %s playlist JSON' % self._ITEM_TYPE)
  120. entries = []
  121. chunks = response['chunks']
  122. qualities = list(chunks.keys())
  123. for num, fragment in enumerate(zip(*chunks.values()), start=1):
  124. formats = []
  125. for fmt_num, fragment_fmt in enumerate(fragment):
  126. format_id = qualities[fmt_num]
  127. fmt = {
  128. 'url': fragment_fmt['url'],
  129. 'format_id': format_id,
  130. 'quality': 1 if format_id == 'live' else 0,
  131. }
  132. m = re.search(r'^(?P<height>\d+)[Pp]', format_id)
  133. if m:
  134. fmt['height'] = int(m.group('height'))
  135. formats.append(fmt)
  136. self._sort_formats(formats)
  137. entry = dict(info)
  138. entry['id'] = '%s_%d' % (entry['id'], num)
  139. entry['title'] = '%s part %d' % (entry['title'], num)
  140. entry['formats'] = formats
  141. entries.append(entry)
  142. return self.playlist_result(entries, info['id'], info['title'])
  143. def _extract_info(self, info):
  144. return {
  145. 'id': info['_id'],
  146. 'title': info.get('title') or 'Untitled Broadcast',
  147. 'description': info.get('description'),
  148. 'duration': int_or_none(info.get('length')),
  149. 'thumbnail': info.get('preview'),
  150. 'uploader': info.get('channel', {}).get('display_name'),
  151. 'uploader_id': info.get('channel', {}).get('name'),
  152. 'timestamp': parse_iso8601(info.get('recorded_at')),
  153. 'view_count': int_or_none(info.get('views')),
  154. }
  155. def _real_extract(self, url):
  156. return self._extract_media(self._match_id(url))
  157. class TwitchVideoIE(TwitchItemBaseIE):
  158. IE_NAME = 'twitch:video'
  159. _VALID_URL = r'%s/[^/]+/b/(?P<id>\d+)' % TwitchBaseIE._VALID_URL_BASE
  160. _ITEM_TYPE = 'video'
  161. _ITEM_SHORTCUT = 'a'
  162. _TEST = {
  163. 'url': 'http://www.twitch.tv/riotgames/b/577357806',
  164. 'info_dict': {
  165. 'id': 'a577357806',
  166. 'title': 'Worlds Semifinals - Star Horn Royal Club vs. OMG',
  167. },
  168. 'playlist_mincount': 12,
  169. 'skip': 'HTTP Error 404: Not Found',
  170. }
  171. class TwitchChapterIE(TwitchItemBaseIE):
  172. IE_NAME = 'twitch:chapter'
  173. _VALID_URL = r'%s/[^/]+/c/(?P<id>\d+)' % TwitchBaseIE._VALID_URL_BASE
  174. _ITEM_TYPE = 'chapter'
  175. _ITEM_SHORTCUT = 'c'
  176. _TESTS = [{
  177. 'url': 'http://www.twitch.tv/acracingleague/c/5285812',
  178. 'info_dict': {
  179. 'id': 'c5285812',
  180. 'title': 'ACRL Off Season - Sports Cars @ Nordschleife',
  181. },
  182. 'playlist_mincount': 3,
  183. 'skip': 'HTTP Error 404: Not Found',
  184. }, {
  185. 'url': 'http://www.twitch.tv/tsm_theoddone/c/2349361',
  186. 'only_matching': True,
  187. }]
  188. class TwitchVodIE(TwitchItemBaseIE):
  189. IE_NAME = 'twitch:vod'
  190. _VALID_URL = r'''(?x)
  191. https?://
  192. (?:
  193. (?:www\.)?twitch\.tv/(?:[^/]+/v|videos)/|
  194. player\.twitch\.tv/\?.*?\bvideo=v
  195. )
  196. (?P<id>\d+)
  197. '''
  198. _ITEM_TYPE = 'vod'
  199. _ITEM_SHORTCUT = 'v'
  200. _TESTS = [{
  201. 'url': 'http://www.twitch.tv/riotgames/v/6528877?t=5m10s',
  202. 'info_dict': {
  203. 'id': 'v6528877',
  204. 'ext': 'mp4',
  205. 'title': 'LCK Summer Split - Week 6 Day 1',
  206. 'thumbnail': r're:^https?://.*\.jpg$',
  207. 'duration': 17208,
  208. 'timestamp': 1435131709,
  209. 'upload_date': '20150624',
  210. 'uploader': 'Riot Games',
  211. 'uploader_id': 'riotgames',
  212. 'view_count': int,
  213. 'start_time': 310,
  214. },
  215. 'params': {
  216. # m3u8 download
  217. 'skip_download': True,
  218. },
  219. }, {
  220. # Untitled broadcast (title is None)
  221. 'url': 'http://www.twitch.tv/belkao_o/v/11230755',
  222. 'info_dict': {
  223. 'id': 'v11230755',
  224. 'ext': 'mp4',
  225. 'title': 'Untitled Broadcast',
  226. 'thumbnail': r're:^https?://.*\.jpg$',
  227. 'duration': 1638,
  228. 'timestamp': 1439746708,
  229. 'upload_date': '20150816',
  230. 'uploader': 'BelkAO_o',
  231. 'uploader_id': 'belkao_o',
  232. 'view_count': int,
  233. },
  234. 'params': {
  235. # m3u8 download
  236. 'skip_download': True,
  237. },
  238. 'skip': 'HTTP Error 404: Not Found',
  239. }, {
  240. 'url': 'http://player.twitch.tv/?t=5m10s&video=v6528877',
  241. 'only_matching': True,
  242. }, {
  243. 'url': 'https://www.twitch.tv/videos/6528877',
  244. 'only_matching': True,
  245. }]
  246. def _real_extract(self, url):
  247. item_id = self._match_id(url)
  248. info = self._download_info(self._ITEM_SHORTCUT, item_id)
  249. access_token = self._call_api(
  250. 'api/vods/%s/access_token' % item_id, item_id,
  251. 'Downloading %s access token' % self._ITEM_TYPE)
  252. formats = self._extract_m3u8_formats(
  253. '%s/vod/%s?%s' % (
  254. self._USHER_BASE, item_id,
  255. compat_urllib_parse_urlencode({
  256. 'allow_source': 'true',
  257. 'allow_audio_only': 'true',
  258. 'allow_spectre': 'true',
  259. 'player': 'twitchweb',
  260. 'nauth': access_token['token'],
  261. 'nauthsig': access_token['sig'],
  262. })),
  263. item_id, 'mp4', entry_protocol='m3u8_native')
  264. self._prefer_source(formats)
  265. info['formats'] = formats
  266. parsed_url = compat_urllib_parse_urlparse(url)
  267. query = compat_parse_qs(parsed_url.query)
  268. if 't' in query:
  269. info['start_time'] = parse_duration(query['t'][0])
  270. if info.get('timestamp') is not None:
  271. info['subtitles'] = {
  272. 'rechat': [{
  273. 'url': update_url_query(
  274. 'https://rechat.twitch.tv/rechat-messages', {
  275. 'video_id': 'v%s' % item_id,
  276. 'start': info['timestamp'],
  277. }),
  278. 'ext': 'json',
  279. }],
  280. }
  281. return info
  282. class TwitchPlaylistBaseIE(TwitchBaseIE):
  283. _PLAYLIST_PATH = 'kraken/channels/%s/videos/?offset=%d&limit=%d'
  284. _PAGE_LIMIT = 100
  285. def _extract_playlist(self, channel_id):
  286. info = self._call_api(
  287. 'kraken/channels/%s' % channel_id,
  288. channel_id, 'Downloading channel info JSON')
  289. channel_name = info.get('display_name') or info.get('name')
  290. entries = []
  291. offset = 0
  292. limit = self._PAGE_LIMIT
  293. broken_paging_detected = False
  294. counter_override = None
  295. for counter in itertools.count(1):
  296. response = self._call_api(
  297. self._PLAYLIST_PATH % (channel_id, offset, limit),
  298. channel_id,
  299. 'Downloading %s JSON page %s'
  300. % (self._PLAYLIST_TYPE, counter_override or counter))
  301. page_entries = self._extract_playlist_page(response)
  302. if not page_entries:
  303. break
  304. total = int_or_none(response.get('_total'))
  305. # Since the beginning of March 2016 twitch's paging mechanism
  306. # is completely broken on the twitch side. It simply ignores
  307. # a limit and returns the whole offset number of videos.
  308. # Working around by just requesting all videos at once.
  309. # Upd: pagination bug was fixed by twitch on 15.03.2016.
  310. if not broken_paging_detected and total and len(page_entries) > limit:
  311. self.report_warning(
  312. 'Twitch pagination is broken on twitch side, requesting all videos at once',
  313. channel_id)
  314. broken_paging_detected = True
  315. offset = total
  316. counter_override = '(all at once)'
  317. continue
  318. entries.extend(page_entries)
  319. if broken_paging_detected or total and len(page_entries) >= total:
  320. break
  321. offset += limit
  322. return self.playlist_result(
  323. [self.url_result(entry) for entry in orderedSet(entries)],
  324. channel_id, channel_name)
  325. def _extract_playlist_page(self, response):
  326. videos = response.get('videos')
  327. return [video['url'] for video in videos] if videos else []
  328. def _real_extract(self, url):
  329. return self._extract_playlist(self._match_id(url))
  330. class TwitchProfileIE(TwitchPlaylistBaseIE):
  331. IE_NAME = 'twitch:profile'
  332. _VALID_URL = r'%s/(?P<id>[^/]+)/profile/?(?:\#.*)?$' % TwitchBaseIE._VALID_URL_BASE
  333. _PLAYLIST_TYPE = 'profile'
  334. _TEST = {
  335. 'url': 'http://www.twitch.tv/vanillatv/profile',
  336. 'info_dict': {
  337. 'id': 'vanillatv',
  338. 'title': 'VanillaTV',
  339. },
  340. 'playlist_mincount': 412,
  341. }
  342. class TwitchVideosBaseIE(TwitchPlaylistBaseIE):
  343. _VALID_URL_VIDEOS_BASE = r'%s/(?P<id>[^/]+)/videos' % TwitchBaseIE._VALID_URL_BASE
  344. _PLAYLIST_PATH = TwitchPlaylistBaseIE._PLAYLIST_PATH + '&broadcast_type='
  345. class TwitchAllVideosIE(TwitchVideosBaseIE):
  346. IE_NAME = 'twitch:videos:all'
  347. _VALID_URL = r'%s/all' % TwitchVideosBaseIE._VALID_URL_VIDEOS_BASE
  348. _PLAYLIST_PATH = TwitchVideosBaseIE._PLAYLIST_PATH + 'archive,upload,highlight'
  349. _PLAYLIST_TYPE = 'all videos'
  350. _TEST = {
  351. 'url': 'https://www.twitch.tv/spamfish/videos/all',
  352. 'info_dict': {
  353. 'id': 'spamfish',
  354. 'title': 'Spamfish',
  355. },
  356. 'playlist_mincount': 869,
  357. }
  358. class TwitchUploadsIE(TwitchVideosBaseIE):
  359. IE_NAME = 'twitch:videos:uploads'
  360. _VALID_URL = r'%s/uploads' % TwitchVideosBaseIE._VALID_URL_VIDEOS_BASE
  361. _PLAYLIST_PATH = TwitchVideosBaseIE._PLAYLIST_PATH + 'upload'
  362. _PLAYLIST_TYPE = 'uploads'
  363. _TEST = {
  364. 'url': 'https://www.twitch.tv/spamfish/videos/uploads',
  365. 'info_dict': {
  366. 'id': 'spamfish',
  367. 'title': 'Spamfish',
  368. },
  369. 'playlist_mincount': 0,
  370. }
  371. class TwitchPastBroadcastsIE(TwitchVideosBaseIE):
  372. IE_NAME = 'twitch:videos:past-broadcasts'
  373. _VALID_URL = r'%s/past-broadcasts' % TwitchVideosBaseIE._VALID_URL_VIDEOS_BASE
  374. _PLAYLIST_PATH = TwitchVideosBaseIE._PLAYLIST_PATH + 'archive'
  375. _PLAYLIST_TYPE = 'past broadcasts'
  376. _TEST = {
  377. 'url': 'https://www.twitch.tv/spamfish/videos/past-broadcasts',
  378. 'info_dict': {
  379. 'id': 'spamfish',
  380. 'title': 'Spamfish',
  381. },
  382. 'playlist_mincount': 0,
  383. }
  384. class TwitchHighlightsIE(TwitchVideosBaseIE):
  385. IE_NAME = 'twitch:videos:highlights'
  386. _VALID_URL = r'%s/highlights' % TwitchVideosBaseIE._VALID_URL_VIDEOS_BASE
  387. _PLAYLIST_PATH = TwitchVideosBaseIE._PLAYLIST_PATH + 'highlight'
  388. _PLAYLIST_TYPE = 'highlights'
  389. _TEST = {
  390. 'url': 'https://www.twitch.tv/spamfish/videos/highlights',
  391. 'info_dict': {
  392. 'id': 'spamfish',
  393. 'title': 'Spamfish',
  394. },
  395. 'playlist_mincount': 805,
  396. }
  397. class TwitchStreamIE(TwitchBaseIE):
  398. IE_NAME = 'twitch:stream'
  399. _VALID_URL = r'''(?x)
  400. https?://
  401. (?:
  402. (?:www\.)?twitch\.tv/|
  403. player\.twitch\.tv/\?.*?\bchannel=
  404. )
  405. (?P<id>[^/#?]+)
  406. '''
  407. _TESTS = [{
  408. 'url': 'http://www.twitch.tv/shroomztv',
  409. 'info_dict': {
  410. 'id': '12772022048',
  411. 'display_id': 'shroomztv',
  412. 'ext': 'mp4',
  413. 'title': 're:^ShroomzTV [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  414. 'description': 'H1Z1 - lonewolfing with ShroomzTV | A3 Battle Royale later - @ShroomzTV',
  415. 'is_live': True,
  416. 'timestamp': 1421928037,
  417. 'upload_date': '20150122',
  418. 'uploader': 'ShroomzTV',
  419. 'uploader_id': 'shroomztv',
  420. 'view_count': int,
  421. },
  422. 'params': {
  423. # m3u8 download
  424. 'skip_download': True,
  425. },
  426. }, {
  427. 'url': 'http://www.twitch.tv/miracle_doto#profile-0',
  428. 'only_matching': True,
  429. }, {
  430. 'url': 'https://player.twitch.tv/?channel=lotsofs',
  431. 'only_matching': True,
  432. }]
  433. @classmethod
  434. def suitable(cls, url):
  435. return (False
  436. if any(ie.suitable(url) for ie in (
  437. TwitchVideoIE,
  438. TwitchChapterIE,
  439. TwitchVodIE,
  440. TwitchProfileIE,
  441. TwitchAllVideosIE,
  442. TwitchUploadsIE,
  443. TwitchPastBroadcastsIE,
  444. TwitchHighlightsIE))
  445. else super(TwitchStreamIE, cls).suitable(url))
  446. def _real_extract(self, url):
  447. channel_id = self._match_id(url)
  448. stream = self._call_api(
  449. 'kraken/streams/%s?stream_type=all' % channel_id, channel_id,
  450. 'Downloading stream JSON').get('stream')
  451. if not stream:
  452. raise ExtractorError('%s is offline' % channel_id, expected=True)
  453. # Channel name may be typed if different case than the original channel name
  454. # (e.g. http://www.twitch.tv/TWITCHPLAYSPOKEMON) that will lead to constructing
  455. # an invalid m3u8 URL. Working around by use of original channel name from stream
  456. # JSON and fallback to lowercase if it's not available.
  457. channel_id = stream.get('channel', {}).get('name') or channel_id.lower()
  458. access_token = self._call_api(
  459. 'api/channels/%s/access_token' % channel_id, channel_id,
  460. 'Downloading channel access token')
  461. query = {
  462. 'allow_source': 'true',
  463. 'allow_audio_only': 'true',
  464. 'allow_spectre': 'true',
  465. 'p': random.randint(1000000, 10000000),
  466. 'player': 'twitchweb',
  467. 'segment_preference': '4',
  468. 'sig': access_token['sig'].encode('utf-8'),
  469. 'token': access_token['token'].encode('utf-8'),
  470. }
  471. formats = self._extract_m3u8_formats(
  472. '%s/api/channel/hls/%s.m3u8?%s'
  473. % (self._USHER_BASE, channel_id, compat_urllib_parse_urlencode(query)),
  474. channel_id, 'mp4')
  475. self._prefer_source(formats)
  476. view_count = stream.get('viewers')
  477. timestamp = parse_iso8601(stream.get('created_at'))
  478. channel = stream['channel']
  479. title = self._live_title(channel.get('display_name') or channel.get('name'))
  480. description = channel.get('status')
  481. thumbnails = []
  482. for thumbnail_key, thumbnail_url in stream['preview'].items():
  483. m = re.search(r'(?P<width>\d+)x(?P<height>\d+)\.jpg$', thumbnail_key)
  484. if not m:
  485. continue
  486. thumbnails.append({
  487. 'url': thumbnail_url,
  488. 'width': int(m.group('width')),
  489. 'height': int(m.group('height')),
  490. })
  491. return {
  492. 'id': compat_str(stream['_id']),
  493. 'display_id': channel_id,
  494. 'title': title,
  495. 'description': description,
  496. 'thumbnails': thumbnails,
  497. 'uploader': channel.get('display_name'),
  498. 'uploader_id': channel.get('name'),
  499. 'timestamp': timestamp,
  500. 'view_count': view_count,
  501. 'formats': formats,
  502. 'is_live': True,
  503. }
  504. class TwitchClipsIE(InfoExtractor):
  505. IE_NAME = 'twitch:clips'
  506. _VALID_URL = r'https?://clips\.twitch\.tv/(?:[^/]+/)*(?P<id>[^/?#&]+)'
  507. _TESTS = [{
  508. 'url': 'https://clips.twitch.tv/ea/AggressiveCobraPoooound',
  509. 'md5': '761769e1eafce0ffebfb4089cb3847cd',
  510. 'info_dict': {
  511. 'id': 'AggressiveCobraPoooound',
  512. 'ext': 'mp4',
  513. 'title': 'EA Play 2016 Live from the Novo Theatre',
  514. 'thumbnail': r're:^https?://.*\.jpg',
  515. 'creator': 'EA',
  516. 'uploader': 'stereotype_',
  517. 'uploader_id': 'stereotype_',
  518. },
  519. }, {
  520. # multiple formats
  521. 'url': 'https://clips.twitch.tv/rflegendary/UninterestedBeeDAESuppy',
  522. 'only_matching': True,
  523. }]
  524. def _real_extract(self, url):
  525. video_id = self._match_id(url)
  526. webpage = self._download_webpage(url, video_id)
  527. clip = self._parse_json(
  528. self._search_regex(
  529. r'(?s)clipInfo\s*=\s*({.+?});', webpage, 'clip info'),
  530. video_id, transform_source=js_to_json)
  531. title = clip.get('channel_title') or self._og_search_title(webpage)
  532. formats = [{
  533. 'url': option['source'],
  534. 'format_id': option.get('quality'),
  535. 'height': int_or_none(option.get('quality')),
  536. } for option in clip.get('quality_options', []) if option.get('source')]
  537. if not formats:
  538. formats = [{
  539. 'url': clip['clip_video_url'],
  540. }]
  541. self._sort_formats(formats)
  542. return {
  543. 'id': video_id,
  544. 'title': title,
  545. 'thumbnail': self._og_search_thumbnail(webpage),
  546. 'creator': clip.get('broadcaster_display_name') or clip.get('broadcaster_login'),
  547. 'uploader': clip.get('curator_login'),
  548. 'uploader_id': clip.get('curator_display_name'),
  549. 'formats': formats,
  550. }