threespeak.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. try_get,
  5. unified_strdate,
  6. )
  7. class ThreeSpeakIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?3speak\.tv/watch\?v\=[^/]+/(?P<id>[^/$&#?]+)'
  9. _TESTS = [{
  10. 'url': 'https://3speak.tv/watch?v=dannyshine/wjgoxyfy',
  11. 'info_dict': {
  12. 'id': 'wjgoxyfy',
  13. 'ext': 'mp4',
  14. 'title': 'Can People who took the Vax think Critically',
  15. 'uploader': 'dannyshine',
  16. 'description': 'md5:181aa7ccb304afafa089b5af3bca7a10',
  17. 'tags': ['sex', 'covid', 'antinatalism', 'comedy', 'vaccines'],
  18. 'thumbnail': 'https://img.3speakcontent.co/wjgoxyfy/thumbnails/default.png',
  19. 'upload_date': '20211021',
  20. 'duration': 2703.867833,
  21. 'filesize': 1620054781,
  22. },
  23. 'params': {'skip_download': True},
  24. }]
  25. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. webpage = self._download_webpage(url, video_id)
  28. json_str = self._html_search_regex(r'JSON\.parse\(\'([^\']+)\'\)', webpage, 'json')
  29. # The json string itself is escaped. Hence the double parsing
  30. data_json = self._parse_json(self._parse_json(f'"{json_str}"', video_id), video_id)
  31. video_json = self._parse_json(data_json['json_metadata'], video_id)
  32. formats, subtitles = [], {}
  33. og_m3u8 = self._html_search_regex(r'<meta\s?property=\"ogvideo\"\s?content=\"([^\"]+)\">', webpage, 'og m3u8', fatal=False)
  34. if og_m3u8:
  35. https_frmts, https_subs = self._extract_m3u8_formats_and_subtitles(og_m3u8, video_id, fatal=False, m3u8_id='https')
  36. formats.extend(https_frmts)
  37. subtitles = self._merge_subtitles(subtitles, https_subs)
  38. ipfs_m3u8 = try_get(video_json, lambda x: x['video']['info']['ipfs'])
  39. if ipfs_m3u8:
  40. ipfs_frmts, ipfs_subs = self._extract_m3u8_formats_and_subtitles(
  41. f'https://ipfs.3speak.tv/ipfs/{ipfs_m3u8}', video_id, fatal=False, m3u8_id='ipfs')
  42. formats.extend(ipfs_frmts)
  43. subtitles = self._merge_subtitles(subtitles, ipfs_subs)
  44. mp4_file = try_get(video_json, lambda x: x['video']['info']['file'])
  45. if mp4_file:
  46. formats.append({
  47. 'url': f'https://threespeakvideo.b-cdn.net/{video_id}/{mp4_file}',
  48. 'ext': 'mp4',
  49. 'format_id': 'https-mp4',
  50. 'duration': try_get(video_json, lambda x: x['video']['info']['duration']),
  51. 'filesize': try_get(video_json, lambda x: x['video']['info']['filesize']),
  52. 'quality': 11,
  53. 'format_note': 'Original file',
  54. })
  55. return {
  56. 'id': video_id,
  57. 'title': data_json.get('title') or data_json.get('root_title'),
  58. 'uploader': data_json.get('author'),
  59. 'description': try_get(video_json, lambda x: x['video']['content']['description']),
  60. 'tags': try_get(video_json, lambda x: x['video']['content']['tags']),
  61. 'thumbnail': try_get(video_json, lambda x: x['image'][0]),
  62. 'upload_date': unified_strdate(data_json.get('created')),
  63. 'formats': formats,
  64. 'subtitles': subtitles,
  65. }
  66. class ThreeSpeakUserIE(InfoExtractor):
  67. _VALID_URL = r'https?://(?:www\.)?3speak\.tv/user/(?P<id>[^/$&?#]+)'
  68. _TESTS = [{
  69. 'url': 'https://3speak.tv/user/theycallmedan',
  70. 'info_dict': {
  71. 'id': 'theycallmedan',
  72. },
  73. 'playlist_mincount': 115,
  74. }]
  75. def _real_extract(self, url):
  76. playlist_id = self._match_id(url)
  77. webpage = self._download_webpage(url, playlist_id)
  78. entries = [
  79. self.url_result(
  80. f'https://3speak.tv/watch?v={video}',
  81. ie=ThreeSpeakIE.ie_key())
  82. for video in re.findall(r'data-payout\s?\=\s?\"([^\"]+)\"', webpage) if video
  83. ]
  84. return self.playlist_result(entries, playlist_id)