rudovideo.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. ExtractorError,
  4. determine_ext,
  5. js_to_json,
  6. traverse_obj,
  7. update_url_query,
  8. url_or_none,
  9. )
  10. class RudoVideoIE(InfoExtractor):
  11. _VALID_URL = r'https?://rudo\.video/(?P<type>vod|podcast|live)/(?P<id>[^/?&#]+)'
  12. _EMBED_REGEX = [r'<iframe[^>]+src=[\'"](?P<url>(?:https?:)//rudo\.video/(?:vod|podcast|live)/[^\'"]+)']
  13. _TESTS = [{
  14. 'url': 'https://rudo.video/podcast/cz2wrUy8l0o',
  15. 'md5': '28ed82b477708dc5e12e072da2449221',
  16. 'info_dict': {
  17. 'id': 'cz2wrUy8l0o',
  18. 'title': 'Diego Cabot',
  19. 'ext': 'mp4',
  20. 'thumbnail': r're:^(?:https?:)?//.*\.(png|jpg)$',
  21. },
  22. }, {
  23. 'url': 'https://rudo.video/podcast/bQkt07',
  24. 'md5': '36b22a9863de0f47f00fc7532a32a898',
  25. 'info_dict': {
  26. 'id': 'bQkt07',
  27. 'title': 'Tubular Bells',
  28. 'ext': 'mp4',
  29. 'thumbnail': r're:^(?:https?:)?//.*\.(png|jpg)$',
  30. },
  31. }, {
  32. 'url': 'https://rudo.video/podcast/b42ZUznHX0',
  33. 'md5': 'b91c70d832938871367f8ad10c895821',
  34. 'info_dict': {
  35. 'id': 'b42ZUznHX0',
  36. 'title': 'Columna Ruperto Concha',
  37. 'ext': 'mp3',
  38. 'thumbnail': r're:^(?:https?:)?//.*\.(png|jpg)$',
  39. },
  40. }, {
  41. 'url': 'https://rudo.video/vod/bN5AaJ',
  42. 'md5': '01324a329227e2591530ecb4f555c881',
  43. 'info_dict': {
  44. 'id': 'bN5AaJ',
  45. 'title': 'Ucrania 19.03',
  46. 'creator': 'La Tercera',
  47. 'ext': 'mp4',
  48. 'thumbnail': r're:^(?:https?:)?//.*\.(png|jpg)$',
  49. },
  50. }, {
  51. 'url': 'https://rudo.video/live/bbtv',
  52. 'info_dict': {
  53. 'id': 'bbtv',
  54. 'ext': 'mp4',
  55. 'creator': 'BioBioTV',
  56. 'live_status': 'is_live',
  57. 'title': r're:^LIVE BBTV\s\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}$',
  58. 'thumbnail': r're:^(?:https?:)?//.*\.(png|jpg)$',
  59. },
  60. }, {
  61. 'url': 'https://rudo.video/live/c13',
  62. 'info_dict': {
  63. 'id': 'c13',
  64. 'title': 'CANAL13',
  65. 'ext': 'mp4',
  66. },
  67. 'skip': 'Geo-restricted to Chile',
  68. }, {
  69. 'url': 'https://rudo.video/live/t13-13cl',
  70. 'info_dict': {
  71. 'id': 't13-13cl',
  72. 'title': 'T13',
  73. 'ext': 'mp4',
  74. },
  75. 'skip': 'Geo-restricted to Chile',
  76. }]
  77. def _real_extract(self, url):
  78. video_id, type_ = self._match_valid_url(url).group('id', 'type')
  79. is_live = type_ == 'live'
  80. webpage = self._download_webpage(url, video_id)
  81. if 'Streaming is not available in your area' in webpage:
  82. self.raise_geo_restricted()
  83. media_url = (
  84. self._search_regex(
  85. r'var\s+streamURL\s*=\s*[\'"]([^?\'"]+)', webpage, 'stream url', default=None)
  86. # Source URL must be used only if streamURL is unavailable
  87. or self._search_regex(
  88. r'<source[^>]+src=[\'"]([^\'"]+)', webpage, 'source url', default=None))
  89. if not media_url:
  90. youtube_url = self._search_regex(r'file:\s*[\'"]((?:https?:)//(?:www\.)?youtube\.com[^\'"]+)',
  91. webpage, 'youtube url', default=None)
  92. if youtube_url:
  93. return self.url_result(youtube_url, 'Youtube')
  94. raise ExtractorError('Unable to extract stream url')
  95. token_array = self._search_json(
  96. r'<script>var\s+_\$_[a-zA-Z0-9]+\s*=', webpage, 'access token array', video_id,
  97. contains_pattern=r'\[(?s:.+)\]', default=None, transform_source=js_to_json)
  98. if token_array:
  99. token_url = traverse_obj(token_array, (..., {url_or_none}), get_all=False)
  100. if not token_url:
  101. raise ExtractorError('Invalid access token array')
  102. access_token = self._download_json(
  103. token_url, video_id, note='Downloading access token')['data']['authToken']
  104. media_url = update_url_query(media_url, {'auth-token': access_token})
  105. ext = determine_ext(media_url)
  106. if ext == 'm3u8':
  107. formats = self._extract_m3u8_formats(media_url, video_id, live=is_live)
  108. elif ext == 'mp3':
  109. formats = [{
  110. 'url': media_url,
  111. 'vcodec': 'none',
  112. }]
  113. else:
  114. formats = [{'url': media_url}]
  115. return {
  116. 'id': video_id,
  117. 'title': (self._search_regex(r'var\s+titleVideo\s*=\s*[\'"]([^\'"]+)',
  118. webpage, 'title', default=None)
  119. or self._og_search_title(webpage)),
  120. 'creator': self._search_regex(r'var\s+videoAuthor\s*=\s*[\'"]([^?\'"]+)',
  121. webpage, 'videoAuthor', default=None),
  122. 'thumbnail': (self._search_regex(r'var\s+posterIMG\s*=\s*[\'"]([^?\'"]+)',
  123. webpage, 'thumbnail', default=None)
  124. or self._og_search_thumbnail(webpage)),
  125. 'formats': formats,
  126. 'is_live': is_live,
  127. }