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.

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