logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

bitchute.py (5326B)


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