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.

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