slideslive.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. import re
  2. import urllib.parse
  3. import xml.etree.ElementTree
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. int_or_none,
  8. parse_qs,
  9. smuggle_url,
  10. traverse_obj,
  11. unified_timestamp,
  12. update_url_query,
  13. url_or_none,
  14. xpath_text,
  15. )
  16. class SlidesLiveIE(InfoExtractor):
  17. _VALID_URL = r'https?://slideslive\.com/(?:embed/(?:presentation/)?)?(?P<id>[0-9]+)'
  18. _TESTS = [{
  19. # service_name = yoda, only XML slides info
  20. 'url': 'https://slideslive.com/38902413/gcc-ia16-backend',
  21. 'info_dict': {
  22. 'id': '38902413',
  23. 'ext': 'mp4',
  24. 'title': 'GCC IA16 backend',
  25. 'timestamp': 1697793372,
  26. 'upload_date': '20231020',
  27. 'thumbnail': r're:^https?://.*\.jpg',
  28. 'thumbnails': 'count:42',
  29. 'chapters': 'count:41',
  30. 'duration': 1638,
  31. },
  32. 'params': {
  33. 'skip_download': 'm3u8',
  34. },
  35. }, {
  36. # service_name = yoda, /v7/ slides
  37. 'url': 'https://slideslive.com/38935785',
  38. 'info_dict': {
  39. 'id': '38935785',
  40. 'ext': 'mp4',
  41. 'title': 'Offline Reinforcement Learning: From Algorithms to Practical Challenges',
  42. 'upload_date': '20231020',
  43. 'timestamp': 1697807002,
  44. 'thumbnail': r're:^https?://.*\.(?:jpg|png)',
  45. 'thumbnails': 'count:640',
  46. 'chapters': 'count:639',
  47. 'duration': 9832,
  48. },
  49. 'params': {
  50. 'skip_download': 'm3u8',
  51. },
  52. }, {
  53. # service_name = yoda, /v1/ slides
  54. 'url': 'https://slideslive.com/38973182/how-should-a-machine-learning-researcher-think-about-ai-ethics',
  55. 'info_dict': {
  56. 'id': '38973182',
  57. 'ext': 'mp4',
  58. 'title': 'How Should a Machine Learning Researcher Think About AI Ethics?',
  59. 'upload_date': '20231020',
  60. 'thumbnail': r're:^https?://.*\.jpg',
  61. 'timestamp': 1697822521,
  62. 'thumbnails': 'count:3',
  63. 'chapters': 'count:2',
  64. 'duration': 5889,
  65. },
  66. 'params': {
  67. 'skip_download': 'm3u8',
  68. },
  69. }, {
  70. # formerly youtube, converted to native
  71. 'url': 'https://slideslive.com/38897546/special-metaprednaska-petra-ludwiga-hodnoty-pro-lepsi-spolecnost',
  72. 'md5': '8a79b5e3d700837f40bd2afca3c8fa01',
  73. 'info_dict': {
  74. 'id': '38897546',
  75. 'ext': 'mp4',
  76. 'title': 'SPECIÁL: Meta-přednáška Petra Ludwiga - Hodnoty pro lepší společnost',
  77. 'thumbnail': r're:^https?://.*\.jpg',
  78. 'upload_date': '20231029',
  79. 'timestamp': 1698588144,
  80. 'thumbnails': 'count:169',
  81. 'chapters': 'count:168',
  82. 'duration': 6827,
  83. },
  84. 'params': {
  85. 'skip_download': 'm3u8',
  86. },
  87. }, {
  88. # embed-only presentation, only XML slides info
  89. 'url': 'https://slideslive.com/embed/presentation/38925850',
  90. 'info_dict': {
  91. 'id': '38925850',
  92. 'ext': 'mp4',
  93. 'title': 'Towards a Deep Network Architecture for Structured Smoothness',
  94. 'thumbnail': r're:^https?://.*\.jpg',
  95. 'thumbnails': 'count:8',
  96. 'timestamp': 1697803109,
  97. 'upload_date': '20231020',
  98. 'chapters': 'count:7',
  99. 'duration': 326,
  100. },
  101. 'params': {
  102. 'skip_download': 'm3u8',
  103. },
  104. }, {
  105. # embed-only presentation, only JSON slides info, /v5/ slides (.png)
  106. 'url': 'https://slideslive.com/38979920/',
  107. 'info_dict': {
  108. 'id': '38979920',
  109. 'ext': 'mp4',
  110. 'title': 'MoReL: Multi-omics Relational Learning',
  111. 'thumbnail': r're:^https?://.*\.(?:jpg|png)',
  112. 'thumbnails': 'count:7',
  113. 'timestamp': 1697824939,
  114. 'upload_date': '20231020',
  115. 'chapters': 'count:6',
  116. 'duration': 171,
  117. },
  118. 'params': {
  119. 'skip_download': 'm3u8',
  120. },
  121. }, {
  122. # /v2/ slides (.jpg)
  123. 'url': 'https://slideslive.com/38954074',
  124. 'info_dict': {
  125. 'id': '38954074',
  126. 'ext': 'mp4',
  127. 'title': 'Decentralized Attribution of Generative Models',
  128. 'thumbnail': r're:^https?://.*\.jpg',
  129. 'thumbnails': 'count:16',
  130. 'timestamp': 1697814901,
  131. 'upload_date': '20231020',
  132. 'chapters': 'count:15',
  133. 'duration': 306,
  134. },
  135. 'params': {
  136. 'skip_download': 'm3u8',
  137. },
  138. }, {
  139. # /v4/ slides (.png)
  140. 'url': 'https://slideslive.com/38979570/',
  141. 'info_dict': {
  142. 'id': '38979570',
  143. 'ext': 'mp4',
  144. 'title': 'Efficient Active Search for Combinatorial Optimization Problems',
  145. 'thumbnail': r're:^https?://.*\.(?:jpg|png)',
  146. 'thumbnails': 'count:9',
  147. 'timestamp': 1697824757,
  148. 'upload_date': '20231020',
  149. 'chapters': 'count:8',
  150. 'duration': 295,
  151. },
  152. 'params': {
  153. 'skip_download': 'm3u8',
  154. },
  155. }, {
  156. # /v10/ slides
  157. 'url': 'https://slideslive.com/embed/presentation/38979880?embed_parent_url=https%3A%2F%2Fedit.videoken.com%2F',
  158. 'info_dict': {
  159. 'id': '38979880',
  160. 'ext': 'mp4',
  161. 'title': 'The Representation Power of Neural Networks',
  162. 'timestamp': 1697824919,
  163. 'thumbnail': r're:^https?://.*\.(?:jpg|png)',
  164. 'thumbnails': 'count:22',
  165. 'upload_date': '20231020',
  166. 'chapters': 'count:21',
  167. 'duration': 294,
  168. },
  169. 'params': {
  170. 'skip_download': 'm3u8',
  171. },
  172. }, {
  173. # /v7/ slides, 2 video slides
  174. 'url': 'https://slideslive.com/embed/presentation/38979682?embed_container_origin=https%3A%2F%2Fedit.videoken.com',
  175. 'playlist_count': 3,
  176. 'info_dict': {
  177. 'id': '38979682-playlist',
  178. 'title': 'LoRA: Low-Rank Adaptation of Large Language Models',
  179. },
  180. 'playlist': [{
  181. 'info_dict': {
  182. 'id': '38979682',
  183. 'ext': 'mp4',
  184. 'title': 'LoRA: Low-Rank Adaptation of Large Language Models',
  185. 'timestamp': 1697824815,
  186. 'thumbnail': r're:^https?://.*\.(?:jpg|png)',
  187. 'thumbnails': 'count:30',
  188. 'upload_date': '20231020',
  189. 'chapters': 'count:31',
  190. 'duration': 272,
  191. },
  192. }, {
  193. 'info_dict': {
  194. 'id': '38979682-021',
  195. 'ext': 'mp4',
  196. 'title': 'LoRA: Low-Rank Adaptation of Large Language Models - Slide 021',
  197. 'duration': 3,
  198. 'timestamp': 1697824815,
  199. 'upload_date': '20231020',
  200. },
  201. }, {
  202. 'info_dict': {
  203. 'id': '38979682-024',
  204. 'ext': 'mp4',
  205. 'title': 'LoRA: Low-Rank Adaptation of Large Language Models - Slide 024',
  206. 'duration': 4,
  207. 'timestamp': 1697824815,
  208. 'upload_date': '20231020',
  209. },
  210. }],
  211. 'params': {
  212. 'skip_download': 'm3u8',
  213. },
  214. }, {
  215. # /v6/ slides, 1 video slide, edit.videoken.com embed
  216. 'url': 'https://slideslive.com/38979481/',
  217. 'playlist_count': 2,
  218. 'info_dict': {
  219. 'id': '38979481-playlist',
  220. 'title': 'How to Train Your MAML to Excel in Few-Shot Classification',
  221. },
  222. 'playlist': [{
  223. 'info_dict': {
  224. 'id': '38979481',
  225. 'ext': 'mp4',
  226. 'title': 'How to Train Your MAML to Excel in Few-Shot Classification',
  227. 'timestamp': 1697824716,
  228. 'thumbnail': r're:^https?://.*\.(?:jpg|png)',
  229. 'thumbnails': 'count:43',
  230. 'upload_date': '20231020',
  231. 'chapters': 'count:43',
  232. 'duration': 315,
  233. },
  234. }, {
  235. 'info_dict': {
  236. 'id': '38979481-013',
  237. 'ext': 'mp4',
  238. 'title': 'How to Train Your MAML to Excel in Few-Shot Classification - Slide 013',
  239. 'duration': 3,
  240. 'timestamp': 1697824716,
  241. 'upload_date': '20231020',
  242. },
  243. }],
  244. 'params': {
  245. 'skip_download': 'm3u8',
  246. },
  247. }, {
  248. # /v3/ slides, .jpg and .png, service_name = youtube
  249. 'url': 'https://slideslive.com/embed/38932460/',
  250. 'info_dict': {
  251. 'id': 'RTPdrgkyTiE',
  252. 'display_id': '38932460',
  253. 'ext': 'mp4',
  254. 'title': 'Active Learning for Hierarchical Multi-Label Classification',
  255. 'description': 'Watch full version of this video at https://slideslive.com/38932460.',
  256. 'channel': 'SlidesLive Videos - A',
  257. 'channel_id': 'UC62SdArr41t_-_fX40QCLRw',
  258. 'channel_url': 'https://www.youtube.com/channel/UC62SdArr41t_-_fX40QCLRw',
  259. 'uploader': 'SlidesLive Videos - A',
  260. 'uploader_id': '@slideslivevideos-a6075',
  261. 'uploader_url': 'https://www.youtube.com/@slideslivevideos-a6075',
  262. 'upload_date': '20200903',
  263. 'timestamp': 1697805922,
  264. 'duration': 942,
  265. 'age_limit': 0,
  266. 'live_status': 'not_live',
  267. 'playable_in_embed': True,
  268. 'availability': 'unlisted',
  269. 'categories': ['People & Blogs'],
  270. 'tags': [],
  271. 'channel_follower_count': int,
  272. 'like_count': int,
  273. 'view_count': int,
  274. 'thumbnail': r're:^https?://.*\.(?:jpg|png|webp)',
  275. 'thumbnails': 'count:21',
  276. 'chapters': 'count:20',
  277. },
  278. 'params': {
  279. 'skip_download': 'm3u8',
  280. },
  281. }, {
  282. # /v3/ slides, .png only, service_name = yoda
  283. 'url': 'https://slideslive.com/38983994',
  284. 'info_dict': {
  285. 'id': '38983994',
  286. 'ext': 'mp4',
  287. 'title': 'Zero-Shot AutoML with Pretrained Models',
  288. 'timestamp': 1697826708,
  289. 'upload_date': '20231020',
  290. 'thumbnail': r're:^https?://.*\.(?:jpg|png)',
  291. 'thumbnails': 'count:23',
  292. 'chapters': 'count:22',
  293. 'duration': 295,
  294. },
  295. 'params': {
  296. 'skip_download': 'm3u8',
  297. },
  298. }, {
  299. # service_name = yoda
  300. 'url': 'https://slideslive.com/38903721/magic-a-scientific-resurrection-of-an-esoteric-legend',
  301. 'only_matching': True,
  302. }, {
  303. # dead link, service_name = url
  304. 'url': 'https://slideslive.com/38922070/learning-transferable-skills-1',
  305. 'only_matching': True,
  306. }, {
  307. # dead link, service_name = vimeo
  308. 'url': 'https://slideslive.com/38921896/retrospectives-a-venue-for-selfreflection-in-ml-research-3',
  309. 'only_matching': True,
  310. }]
  311. _WEBPAGE_TESTS = [{
  312. # only XML slides info
  313. 'url': 'https://iclr.cc/virtual_2020/poster_Hklr204Fvr.html',
  314. 'info_dict': {
  315. 'id': '38925850',
  316. 'ext': 'mp4',
  317. 'title': 'Towards a Deep Network Architecture for Structured Smoothness',
  318. 'thumbnail': r're:^https?://.*\.jpg',
  319. 'thumbnails': 'count:8',
  320. 'timestamp': 1697803109,
  321. 'upload_date': '20231020',
  322. 'chapters': 'count:7',
  323. 'duration': 326,
  324. },
  325. 'params': {
  326. 'skip_download': 'm3u8',
  327. },
  328. }]
  329. @classmethod
  330. def _extract_embed_urls(cls, url, webpage):
  331. # Reference: https://slideslive.com/embed_presentation.js
  332. for embed_id in re.findall(r'(?s)new\s+SlidesLiveEmbed\s*\([^)]+\bpresentationId:\s*["\'](\d+)["\']', webpage):
  333. url_parsed = urllib.parse.urlparse(url)
  334. origin = f'{url_parsed.scheme}://{url_parsed.netloc}'
  335. yield update_url_query(
  336. f'https://slideslive.com/embed/presentation/{embed_id}', {
  337. 'embed_parent_url': url,
  338. 'embed_container_origin': origin,
  339. })
  340. def _download_embed_webpage_handle(self, video_id, headers):
  341. return self._download_webpage_handle(
  342. f'https://slideslive.com/embed/presentation/{video_id}', video_id,
  343. headers=headers, query=traverse_obj(headers, {
  344. 'embed_parent_url': 'Referer',
  345. 'embed_container_origin': 'Origin',
  346. }))
  347. def _extract_custom_m3u8_info(self, m3u8_data):
  348. m3u8_dict = {}
  349. lookup = {
  350. 'PRESENTATION-TITLE': 'title',
  351. 'PRESENTATION-UPDATED-AT': 'timestamp',
  352. 'PRESENTATION-THUMBNAIL': 'thumbnail',
  353. 'PLAYLIST-TYPE': 'playlist_type',
  354. 'VOD-VIDEO-SERVICE-NAME': 'service_name',
  355. 'VOD-VIDEO-ID': 'service_id',
  356. 'VOD-VIDEO-SERVERS': 'video_servers',
  357. 'VOD-SUBTITLES': 'subtitles',
  358. 'VOD-SLIDES-JSON-URL': 'slides_json_url',
  359. 'VOD-SLIDES-XML-URL': 'slides_xml_url',
  360. }
  361. for line in m3u8_data.splitlines():
  362. if not line.startswith('#EXT-SL-'):
  363. continue
  364. tag, _, value = line.partition(':')
  365. key = lookup.get(tag[8:])
  366. if not key:
  367. continue
  368. m3u8_dict[key] = value
  369. # Some values are stringified JSON arrays
  370. for key in ('video_servers', 'subtitles'):
  371. if key in m3u8_dict:
  372. m3u8_dict[key] = self._parse_json(m3u8_dict[key], None, fatal=False) or []
  373. return m3u8_dict
  374. def _extract_formats_and_duration(self, cdn_hostname, path, video_id, skip_duration=False):
  375. formats, duration = [], None
  376. hls_formats = self._extract_m3u8_formats(
  377. f'https://{cdn_hostname}/{path}/master.m3u8',
  378. video_id, 'mp4', m3u8_id='hls', fatal=False, live=True)
  379. if hls_formats:
  380. if not skip_duration:
  381. duration = self._extract_m3u8_vod_duration(
  382. hls_formats[0]['url'], video_id, note='Extracting duration from HLS manifest')
  383. formats.extend(hls_formats)
  384. dash_formats = self._extract_mpd_formats(
  385. f'https://{cdn_hostname}/{path}/master.mpd', video_id, mpd_id='dash', fatal=False)
  386. if dash_formats:
  387. if not duration and not skip_duration:
  388. duration = self._extract_mpd_vod_duration(
  389. f'https://{cdn_hostname}/{path}/master.mpd', video_id,
  390. note='Extracting duration from DASH manifest')
  391. formats.extend(dash_formats)
  392. return formats, duration
  393. def _real_extract(self, url):
  394. video_id = self._match_id(url)
  395. webpage, urlh = self._download_embed_webpage_handle(
  396. video_id, headers=traverse_obj(parse_qs(url), {
  397. 'Referer': ('embed_parent_url', -1),
  398. 'Origin': ('embed_container_origin', -1)}))
  399. redirect_url = urlh.url
  400. if 'domain_not_allowed' in redirect_url:
  401. domain = traverse_obj(parse_qs(redirect_url), ('allowed_domains[]', ...), get_all=False)
  402. if not domain:
  403. raise ExtractorError(
  404. 'This is an embed-only presentation. Try passing --referer', expected=True)
  405. webpage, _ = self._download_embed_webpage_handle(video_id, headers={
  406. 'Referer': f'https://{domain}/',
  407. 'Origin': f'https://{domain}',
  408. })
  409. player_token = self._search_regex(r'data-player-token="([^"]+)"', webpage, 'player token')
  410. player_data = self._download_webpage(
  411. f'https://ben.slideslive.com/player/{video_id}', video_id,
  412. note='Downloading player info', query={'player_token': player_token})
  413. player_info = self._extract_custom_m3u8_info(player_data)
  414. service_name = player_info['service_name'].lower()
  415. assert service_name in ('url', 'yoda', 'vimeo', 'youtube')
  416. service_id = player_info['service_id']
  417. slide_url_template = 'https://slides.slideslive.com/%s/slides/original/%s%s'
  418. slides, slides_info = {}, []
  419. if player_info.get('slides_json_url'):
  420. slides = self._download_json(
  421. player_info['slides_json_url'], video_id, fatal=False,
  422. note='Downloading slides JSON', errnote=False) or {}
  423. slide_ext_default = '.png'
  424. slide_quality = traverse_obj(slides, ('slide_qualities', 0))
  425. if slide_quality:
  426. slide_ext_default = '.jpg'
  427. slide_url_template = f'https://cdn.slideslive.com/data/presentations/%s/slides/{slide_quality}/%s%s'
  428. for slide_id, slide in enumerate(traverse_obj(slides, ('slides', ...), expected_type=dict), 1):
  429. slides_info.append((
  430. slide_id, traverse_obj(slide, ('image', 'name')),
  431. traverse_obj(slide, ('image', 'extname'), default=slide_ext_default),
  432. int_or_none(slide.get('time'), scale=1000)))
  433. if not slides and player_info.get('slides_xml_url'):
  434. slides = self._download_xml(
  435. player_info['slides_xml_url'], video_id, fatal=False,
  436. note='Downloading slides XML', errnote='Failed to download slides info')
  437. if isinstance(slides, xml.etree.ElementTree.Element):
  438. slide_url_template = 'https://cdn.slideslive.com/data/presentations/%s/slides/big/%s%s'
  439. for slide_id, slide in enumerate(slides.findall('./slide')):
  440. slides_info.append((
  441. slide_id, xpath_text(slide, './slideName', 'name'), '.jpg',
  442. int_or_none(xpath_text(slide, './timeSec', 'time'))))
  443. chapters, thumbnails = [], []
  444. if url_or_none(player_info.get('thumbnail')):
  445. thumbnails.append({'id': 'cover', 'url': player_info['thumbnail']})
  446. for slide_id, slide_path, slide_ext, start_time in slides_info:
  447. if slide_path:
  448. thumbnails.append({
  449. 'id': f'{slide_id:03d}',
  450. 'url': slide_url_template % (video_id, slide_path, slide_ext),
  451. })
  452. chapters.append({
  453. 'title': f'Slide {slide_id:03d}',
  454. 'start_time': start_time,
  455. })
  456. subtitles = {}
  457. for sub in traverse_obj(player_info, ('subtitles', ...), expected_type=dict):
  458. webvtt_url = url_or_none(sub.get('webvtt_url'))
  459. if not webvtt_url:
  460. continue
  461. subtitles.setdefault(sub.get('language') or 'en', []).append({
  462. 'url': webvtt_url,
  463. 'ext': 'vtt',
  464. })
  465. info = {
  466. 'id': video_id,
  467. 'title': player_info.get('title') or self._html_search_meta('title', webpage, default=''),
  468. 'timestamp': unified_timestamp(player_info.get('timestamp')),
  469. 'is_live': player_info.get('playlist_type') != 'vod',
  470. 'thumbnails': thumbnails,
  471. 'chapters': chapters,
  472. 'subtitles': subtitles,
  473. }
  474. if service_name == 'url':
  475. info['url'] = service_id
  476. elif service_name == 'yoda':
  477. formats, duration = self._extract_formats_and_duration(
  478. player_info['video_servers'][0], service_id, video_id)
  479. info.update({
  480. 'duration': duration,
  481. 'formats': formats,
  482. })
  483. else:
  484. info.update({
  485. '_type': 'url_transparent',
  486. 'url': service_id,
  487. 'ie_key': service_name.capitalize(),
  488. 'display_id': video_id,
  489. })
  490. if service_name == 'vimeo':
  491. info['url'] = smuggle_url(
  492. f'https://player.vimeo.com/video/{service_id}',
  493. {'referer': url})
  494. video_slides = traverse_obj(slides, ('slides', ..., 'video', 'id'))
  495. if not video_slides:
  496. return info
  497. def entries():
  498. yield info
  499. service_data = self._download_json(
  500. f'https://ben.slideslive.com/player/{video_id}/slides_video_service_data',
  501. video_id, fatal=False, query={
  502. 'player_token': player_token,
  503. 'videos': ','.join(video_slides),
  504. }, note='Downloading video slides info', errnote='Failed to download video slides info') or {}
  505. for slide_id, slide in enumerate(traverse_obj(slides, ('slides', ...)), 1):
  506. if traverse_obj(slide, ('video', 'service')) != 'yoda':
  507. continue
  508. video_path = traverse_obj(slide, ('video', 'id'))
  509. cdn_hostname = traverse_obj(service_data, (
  510. video_path, 'video_servers', ...), get_all=False)
  511. if not cdn_hostname or not video_path:
  512. continue
  513. formats, _ = self._extract_formats_and_duration(
  514. cdn_hostname, video_path, video_id, skip_duration=True)
  515. if not formats:
  516. continue
  517. yield {
  518. 'id': f'{video_id}-{slide_id:03d}',
  519. 'title': f'{info["title"]} - Slide {slide_id:03d}',
  520. 'timestamp': info['timestamp'],
  521. 'duration': int_or_none(traverse_obj(slide, ('video', 'duration_ms')), scale=1000),
  522. 'formats': formats,
  523. }
  524. return self.playlist_result(entries(), f'{video_id}-playlist', info['title'])