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.

135 lines
4.9 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. if not formats:
  50. formats = self._parse_html5_media_entries(
  51. url, webpage, video_id)[0]['formats']
  52. self._check_formats(formats, video_id)
  53. self._sort_formats(formats)
  54. description = self._html_search_regex(
  55. r'(?s)<div\b[^>]+\bclass=["\']full hidden[^>]+>(.+?)</div>',
  56. webpage, 'description', fatal=False)
  57. thumbnail = self._og_search_thumbnail(
  58. webpage, default=None) or self._html_search_meta(
  59. 'twitter:image:src', webpage, 'thumbnail')
  60. uploader = self._html_search_regex(
  61. (r'(?s)<div class=["\']channel-banner.*?<p\b[^>]+\bclass=["\']name[^>]+>(.+?)</p>',
  62. r'(?s)<p\b[^>]+\bclass=["\']video-author[^>]+>(.+?)</p>'),
  63. webpage, 'uploader', fatal=False)
  64. return {
  65. 'id': video_id,
  66. 'title': title,
  67. 'description': description,
  68. 'thumbnail': thumbnail,
  69. 'uploader': uploader,
  70. 'formats': formats,
  71. }
  72. class BitChuteChannelIE(InfoExtractor):
  73. _VALID_URL = r'https?://(?:www\.)?bitchute\.com/channel/(?P<id>[^/?#&]+)'
  74. _TEST = {
  75. 'url': 'https://www.bitchute.com/channel/victoriaxrave/',
  76. 'playlist_mincount': 185,
  77. 'info_dict': {
  78. 'id': 'victoriaxrave',
  79. },
  80. }
  81. _TOKEN = 'zyG6tQcGPE5swyAEFLqKUwMuMMuF6IO2DZ6ZDQjGfsL0e4dcTLwqkTTul05Jdve7'
  82. def _entries(self, channel_id):
  83. channel_url = 'https://www.bitchute.com/channel/%s/' % channel_id
  84. offset = 0
  85. for page_num in itertools.count(1):
  86. data = self._download_json(
  87. '%sextend/' % channel_url, channel_id,
  88. 'Downloading channel page %d' % page_num,
  89. data=urlencode_postdata({
  90. 'csrfmiddlewaretoken': self._TOKEN,
  91. 'name': '',
  92. 'offset': offset,
  93. }), headers={
  94. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  95. 'Referer': channel_url,
  96. 'X-Requested-With': 'XMLHttpRequest',
  97. 'Cookie': 'csrftoken=%s' % self._TOKEN,
  98. })
  99. if data.get('success') is False:
  100. break
  101. html = data.get('html')
  102. if not html:
  103. break
  104. video_ids = re.findall(
  105. r'class=["\']channel-videos-image-container[^>]+>\s*<a\b[^>]+\bhref=["\']/video/([^"\'/]+)',
  106. html)
  107. if not video_ids:
  108. break
  109. offset += len(video_ids)
  110. for video_id in video_ids:
  111. yield self.url_result(
  112. 'https://www.bitchute.com/video/%s' % video_id,
  113. ie=BitChuteIE.ie_key(), video_id=video_id)
  114. def _real_extract(self, url):
  115. channel_id = self._match_id(url)
  116. return self.playlist_result(
  117. self._entries(channel_id), playlist_id=channel_id)