You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
4.8 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import itertools
  4. import re
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. orderedSet,
  8. urlencode_postdata,
  9. )
  10. class BitChuteIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?bitchute\.com/(?:video|embed|torrent/[^/]+)/(?P<id>[^/?#&]+)'
  12. _TESTS = [{
  13. 'url': 'https://www.bitchute.com/video/szoMrox2JEI/',
  14. 'md5': '66c4a70e6bfc40dcb6be3eb1d74939eb',
  15. 'info_dict': {
  16. 'id': 'szoMrox2JEI',
  17. 'ext': 'mp4',
  18. 'title': 'Fuck bitches get money',
  19. 'description': 'md5:3f21f6fb5b1d17c3dee9cf6b5fe60b3a',
  20. 'thumbnail': r're:^https?://.*\.jpg$',
  21. 'uploader': 'Victoria X Rave',
  22. },
  23. }, {
  24. 'url': 'https://www.bitchute.com/embed/lbb5G1hjPhw/',
  25. 'only_matching': True,
  26. }, {
  27. 'url': 'https://www.bitchute.com/torrent/Zee5BE49045h/szoMrox2JEI.webtorrent',
  28. 'only_matching': True,
  29. }]
  30. def _real_extract(self, url):
  31. video_id = self._match_id(url)
  32. webpage = self._download_webpage(
  33. 'https://www.bitchute.com/video/%s' % video_id, video_id, headers={
  34. 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.57 Safari/537.36',
  35. })
  36. title = self._html_search_regex(
  37. (r'<[^>]+\bid=["\']video-title[^>]+>([^<]+)', r'<title>([^<]+)'),
  38. webpage, 'title', default=None) or self._html_search_meta(
  39. 'description', webpage, 'title',
  40. default=None) or self._og_search_description(webpage)
  41. format_urls = []
  42. for mobj in re.finditer(
  43. r'addWebSeed\s*\(\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage):
  44. format_urls.append(mobj.group('url'))
  45. format_urls.extend(re.findall(r'as=(https?://[^&"\']+)', webpage))
  46. formats = [
  47. {'url': format_url}
  48. for format_url in orderedSet(format_urls)]
  49. self._check_formats(formats, video_id)
  50. self._sort_formats(formats)
  51. description = self._html_search_regex(
  52. r'(?s)<div\b[^>]+\bclass=["\']full hidden[^>]+>(.+?)</div>',
  53. webpage, 'description', fatal=False)
  54. thumbnail = self._og_search_thumbnail(
  55. webpage, default=None) or self._html_search_meta(
  56. 'twitter:image:src', webpage, 'thumbnail')
  57. uploader = self._html_search_regex(
  58. (r'(?s)<div class=["\']channel-banner.*?<p\b[^>]+\bclass=["\']name[^>]+>(.+?)</p>',
  59. r'(?s)<p\b[^>]+\bclass=["\']video-author[^>]+>(.+?)</p>'),
  60. webpage, 'uploader', fatal=False)
  61. return {
  62. 'id': video_id,
  63. 'title': title,
  64. 'description': description,
  65. 'thumbnail': thumbnail,
  66. 'uploader': uploader,
  67. 'formats': formats,
  68. }
  69. class BitChuteChannelIE(InfoExtractor):
  70. _VALID_URL = r'https?://(?:www\.)?bitchute\.com/channel/(?P<id>[^/?#&]+)'
  71. _TEST = {
  72. 'url': 'https://www.bitchute.com/channel/victoriaxrave/',
  73. 'playlist_mincount': 185,
  74. 'info_dict': {
  75. 'id': 'victoriaxrave',
  76. },
  77. }
  78. _TOKEN = 'zyG6tQcGPE5swyAEFLqKUwMuMMuF6IO2DZ6ZDQjGfsL0e4dcTLwqkTTul05Jdve7'
  79. def _entries(self, channel_id):
  80. channel_url = 'https://www.bitchute.com/channel/%s/' % channel_id
  81. offset = 0
  82. for page_num in itertools.count(1):
  83. data = self._download_json(
  84. '%sextend/' % channel_url, channel_id,
  85. 'Downloading channel page %d' % page_num,
  86. data=urlencode_postdata({
  87. 'csrfmiddlewaretoken': self._TOKEN,
  88. 'name': '',
  89. 'offset': offset,
  90. }), headers={
  91. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  92. 'Referer': channel_url,
  93. 'X-Requested-With': 'XMLHttpRequest',
  94. 'Cookie': 'csrftoken=%s' % self._TOKEN,
  95. })
  96. if data.get('success') is False:
  97. break
  98. html = data.get('html')
  99. if not html:
  100. break
  101. video_ids = re.findall(
  102. r'class=["\']channel-videos-image-container[^>]+>\s*<a\b[^>]+\bhref=["\']/video/([^"\'/]+)',
  103. html)
  104. if not video_ids:
  105. break
  106. offset += len(video_ids)
  107. for video_id in video_ids:
  108. yield self.url_result(
  109. 'https://www.bitchute.com/video/%s' % video_id,
  110. ie=BitChuteIE.ie_key(), video_id=video_id)
  111. def _real_extract(self, url):
  112. channel_id = self._match_id(url)
  113. return self.playlist_result(
  114. self._entries(channel_id), playlist_id=channel_id)