theta.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. from .common import InfoExtractor
  2. from ..utils import try_get
  3. class ThetaStreamIE(InfoExtractor):
  4. _VALID_URL = r'https?://(?:www\.)?theta\.tv/(?!video/)(?P<id>[a-z0-9-]+)'
  5. _TESTS = [{
  6. 'url': 'https://www.theta.tv/davirus',
  7. 'skip': 'The live may have ended',
  8. 'info_dict': {
  9. 'id': 'DaVirus',
  10. 'ext': 'mp4',
  11. 'title': 'I choose you - My Community is King -👀 - YO HABLO ESPANOL - CODE DAVIRUS',
  12. 'thumbnail': r're:https://live-thumbnails-prod-theta-tv\.imgix\.net/thumbnail/.+\.jpg',
  13. }
  14. }, {
  15. 'url': 'https://www.theta.tv/mst3k',
  16. 'note': 'This channel is live 24/7',
  17. 'info_dict': {
  18. 'id': 'MST3K',
  19. 'ext': 'mp4',
  20. 'title': 'Mystery Science Theatre 3000 24/7 Powered by the THETA Network.',
  21. 'thumbnail': r're:https://user-prod-theta-tv\.imgix\.net/.+\.jpg',
  22. }
  23. }, {
  24. 'url': 'https://www.theta.tv/contv-anime',
  25. 'info_dict': {
  26. 'id': 'ConTVAnime',
  27. 'ext': 'mp4',
  28. 'title': 'CONTV ANIME 24/7. Powered by THETA Network.',
  29. 'thumbnail': r're:https://user-prod-theta-tv\.imgix\.net/.+\.jpg',
  30. }
  31. }]
  32. def _real_extract(self, url):
  33. channel_id = self._match_id(url)
  34. info = self._download_json(f'https://api.theta.tv/v1/channel?alias={channel_id}', channel_id)['body']
  35. m3u8_playlist = next(
  36. data['url'] for data in info['live_stream']['video_urls']
  37. if data.get('type') != 'embed' and data.get('resolution') in ('master', 'source'))
  38. formats = self._extract_m3u8_formats(m3u8_playlist, channel_id, 'mp4', m3u8_id='hls', live=True)
  39. channel = try_get(info, lambda x: x['user']['username']) # using this field instead of channel_id due to capitalization
  40. return {
  41. 'id': channel,
  42. 'title': try_get(info, lambda x: x['live_stream']['title']),
  43. 'channel': channel,
  44. 'view_count': try_get(info, lambda x: x['live_stream']['view_count']),
  45. 'is_live': True,
  46. 'formats': formats,
  47. 'thumbnail': try_get(info, lambda x: x['live_stream']['thumbnail_url']),
  48. }
  49. class ThetaVideoIE(InfoExtractor):
  50. _VALID_URL = r'https?://(?:www\.)?theta\.tv/video/(?P<id>vid[a-z0-9]+)'
  51. _TEST = {
  52. 'url': 'https://www.theta.tv/video/vidiq6aaet3kzf799p0',
  53. 'md5': '633d8c29eb276bb38a111dbd591c677f',
  54. 'info_dict': {
  55. 'id': 'vidiq6aaet3kzf799p0',
  56. 'ext': 'mp4',
  57. 'title': 'Theta EdgeCast Tutorial',
  58. 'uploader': 'Pixiekittie',
  59. 'description': 'md5:e316253f5bdced8b5a46bb50ae60a09f',
  60. 'thumbnail': r're:https://user-prod-theta-tv\.imgix\.net/.+/vod_thumb/.+.jpg',
  61. }
  62. }
  63. def _real_extract(self, url):
  64. video_id = self._match_id(url)
  65. info = self._download_json(f'https://api.theta.tv/v1/video/{video_id}/raw', video_id)['body']
  66. m3u8_playlist = try_get(info, lambda x: x['video_urls'][0]['url'])
  67. formats = self._extract_m3u8_formats(m3u8_playlist, video_id, 'mp4', m3u8_id='hls')
  68. return {
  69. 'id': video_id,
  70. 'title': info.get('title'),
  71. 'uploader': try_get(info, lambda x: x['user']['username']),
  72. 'description': info.get('description'),
  73. 'view_count': info.get('view_count'),
  74. 'like_count': info.get('like_count'),
  75. 'formats': formats,
  76. 'thumbnail': info.get('thumbnail_url'),
  77. }