wevidi.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. from .common import InfoExtractor
  2. from ..utils import clean_html, float_or_none, get_element_by_class, js_to_json, traverse_obj
  3. class WeVidiIE(InfoExtractor):
  4. _VALID_URL = r'https?://(?:www\.)?wevidi\.net/watch/(?P<id>[\w-]{11})'
  5. _TESTS = [{
  6. 'url': 'https://wevidi.net/watch/2th7UO5F4KV',
  7. 'md5': 'b913d1ff5bbad499e2c7ef4aa6d829d7',
  8. 'info_dict': {
  9. 'id': '2th7UO5F4KV',
  10. 'ext': 'mp4',
  11. 'title': 'YouTube Alternative: WeVidi - customizable channels & more',
  12. 'thumbnail': r're:^https?://.*\.jpg$',
  13. 'description': 'md5:73a27d0a87d49fbcc5584566326ebeed',
  14. 'uploader': 'eclecRC',
  15. 'duration': 932.098,
  16. },
  17. }, {
  18. 'url': 'https://wevidi.net/watch/ievRuuQHbPS',
  19. 'md5': 'ce8a94989a959bff9003fa27ee572935',
  20. 'info_dict': {
  21. 'id': 'ievRuuQHbPS',
  22. 'ext': 'mp4',
  23. 'title': 'WeVidi Playlists',
  24. 'thumbnail': r're:^https?://.*\.jpg$',
  25. 'description': 'md5:32cdfca272687390d9bd9b0c9c6153ee',
  26. 'uploader': 'WeVidi',
  27. 'duration': 36.1999,
  28. },
  29. }, {
  30. 'url': 'https://wevidi.net/watch/PcMzDWaQSWb',
  31. 'md5': '55ee0d3434be5d9e5cc76b83f2bb57ec',
  32. 'info_dict': {
  33. 'id': 'PcMzDWaQSWb',
  34. 'ext': 'mp4',
  35. 'title': 'Cat blep',
  36. 'thumbnail': r're:^https?://.*\.jpg$',
  37. 'description': 'md5:e2c9e2b54b8bb424cc64937c8fdc068f',
  38. 'uploader': 'WeVidi',
  39. 'duration': 41.972,
  40. },
  41. }, {
  42. 'url': 'https://wevidi.net/watch/wJnRqDHNe_u',
  43. 'md5': 'c8f263dd47e66cc17546b3abf47b5a77',
  44. 'info_dict': {
  45. 'id': 'wJnRqDHNe_u',
  46. 'ext': 'mp4',
  47. 'title': 'Gissy Talks: YouTube Alternatives',
  48. 'thumbnail': r're:^https?://.*\.jpg$',
  49. 'description': 'md5:e65036f0d4af80e0af191bd11af5195e',
  50. 'uploader': 'GissyEva',
  51. 'duration': 630.451,
  52. },
  53. }, {
  54. 'url': 'https://wevidi.net/watch/4m1c4yJR_yc',
  55. 'md5': 'c63ce5ca6990dce86855fc02ca5bc1ed',
  56. 'info_dict': {
  57. 'id': '4m1c4yJR_yc',
  58. 'ext': 'mp4',
  59. 'title': 'Enough of that! - Awesome Exilez Podcast',
  60. 'thumbnail': r're:^https?://.*\.jpg$',
  61. 'description': 'md5:96af99dd63468b2dfab3020560e3e9b2',
  62. 'uploader': 'eclecRC',
  63. 'duration': 6.804,
  64. },
  65. }]
  66. def _extract_formats(self, wvplayer_props):
  67. # Taken from WeVidi player JS: https://wevidi.net/layouts/default/static/player.min.js
  68. resolution_map = {
  69. 1: 144,
  70. 2: 240,
  71. 3: 360,
  72. 4: 480,
  73. 5: 720,
  74. 6: 1080,
  75. }
  76. src_path = f'{wvplayer_props["srcVID"]}/{wvplayer_props["srcUID"]}/{wvplayer_props["srcNAME"]}'
  77. for res in traverse_obj(wvplayer_props, ('resolutions', ..., {int}, {lambda x: x or None})):
  78. format_id = str(-(res // -2) - 1)
  79. yield {
  80. 'acodec': 'mp4a.40.2',
  81. 'ext': 'mp4',
  82. 'format_id': format_id,
  83. 'height': resolution_map.get(res),
  84. 'url': f'https://www.wevidi.net/videoplayback/{src_path}/{format_id}',
  85. 'vcodec': 'avc1.42E01E',
  86. }
  87. def _real_extract(self, url):
  88. video_id = self._match_id(url)
  89. webpage = self._download_webpage(url, video_id)
  90. wvplayer_props = self._search_json(
  91. r'WVPlayer\(', webpage, 'player', video_id,
  92. transform_source=lambda x: js_to_json(x.replace('||', '}')))
  93. return {
  94. 'id': video_id,
  95. 'title': clean_html(get_element_by_class('video_title', webpage)),
  96. 'description': clean_html(get_element_by_class('descr_long', webpage)),
  97. 'uploader': clean_html(get_element_by_class('username', webpage)),
  98. 'formats': list(self._extract_formats(wvplayer_props)),
  99. 'thumbnail': self._og_search_thumbnail(webpage),
  100. 'duration': float_or_none(wvplayer_props.get('duration')),
  101. }