2022-11-08 22:30:15 -05:00
|
|
|
import functools
|
2018-08-11 14:47:10 -04:00
|
|
|
import re
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
2023-07-09 03:53:02 -04:00
|
|
|
from ..networking import HEADRequest
|
2019-01-01 06:12:44 -05:00
|
|
|
from ..utils import (
|
2020-09-11 17:31:44 -04:00
|
|
|
ExtractorError,
|
2022-11-08 22:30:15 -05:00
|
|
|
OnDemandPagedList,
|
2022-11-04 10:08:38 -04:00
|
|
|
clean_html,
|
2023-12-11 18:56:01 -05:00
|
|
|
extract_attributes,
|
2022-11-04 10:08:38 -04:00
|
|
|
get_element_by_class,
|
2022-11-09 04:05:08 -05:00
|
|
|
get_element_by_id,
|
2023-12-11 18:56:01 -05:00
|
|
|
get_element_html_by_class,
|
2022-11-08 22:30:15 -05:00
|
|
|
get_elements_html_by_class,
|
2022-11-04 10:08:38 -04:00
|
|
|
int_or_none,
|
2019-01-01 06:12:44 -05:00
|
|
|
orderedSet,
|
2022-11-08 22:30:15 -05:00
|
|
|
parse_count,
|
|
|
|
parse_duration,
|
2022-11-04 10:08:38 -04:00
|
|
|
traverse_obj,
|
2019-11-26 12:20:39 -05:00
|
|
|
unified_strdate,
|
2019-01-01 06:12:44 -05:00
|
|
|
urlencode_postdata,
|
2023-12-11 18:56:01 -05:00
|
|
|
urljoin,
|
2019-01-01 06:12:44 -05:00
|
|
|
)
|
2018-08-11 14:47:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
class BitChuteIE(InfoExtractor):
|
2024-06-29 11:32:41 -04:00
|
|
|
_VALID_URL = r'https?://(?:(?:www|old)\.)?bitchute\.com/(?:video|embed|torrent/[^/]+)/(?P<id>[^/?#&]+)'
|
2022-07-31 21:23:25 -04:00
|
|
|
_EMBED_REGEX = [rf'<(?:script|iframe)[^>]+\bsrc=(["\'])(?P<url>{_VALID_URL})']
|
2018-08-11 14:47:10 -04:00
|
|
|
_TESTS = [{
|
2021-08-22 15:58:23 -04:00
|
|
|
'url': 'https://www.bitchute.com/video/UGlrF9o9b-Q/',
|
|
|
|
'md5': '7e427d7ed7af5a75b5855705ec750e2b',
|
2018-08-11 14:47:10 -04:00
|
|
|
'info_dict': {
|
2022-11-04 10:08:38 -04:00
|
|
|
'id': 'UGlrF9o9b-Q',
|
2018-08-11 14:47:10 -04:00
|
|
|
'ext': 'mp4',
|
2021-08-22 15:58:23 -04:00
|
|
|
'title': 'This is the first video on #BitChute !',
|
|
|
|
'description': 'md5:a0337e7b1fe39e32336974af8173a034',
|
2018-08-11 14:47:10 -04:00
|
|
|
'thumbnail': r're:^https?://.*\.jpg$',
|
2021-08-22 15:58:23 -04:00
|
|
|
'uploader': 'BitChute',
|
|
|
|
'upload_date': '20170103',
|
2023-12-11 18:56:01 -05:00
|
|
|
'uploader_url': 'https://www.bitchute.com/profile/I5NgtHZn9vPj/',
|
|
|
|
'channel': 'BitChute',
|
2024-06-11 19:09:58 -04:00
|
|
|
'channel_url': 'https://www.bitchute.com/channel/bitchute/',
|
2023-12-11 18:56:01 -05:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
# test case: video with different channel and uploader
|
|
|
|
'url': 'https://www.bitchute.com/video/Yti_j9A-UZ4/',
|
|
|
|
'md5': 'f10e6a8e787766235946d0868703f1d0',
|
|
|
|
'info_dict': {
|
|
|
|
'id': 'Yti_j9A-UZ4',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'Israel at War | Full Measure',
|
|
|
|
'description': 'md5:38cf7bc6f42da1a877835539111c69ef',
|
|
|
|
'thumbnail': r're:^https?://.*\.jpg$',
|
|
|
|
'uploader': 'sharylattkisson',
|
|
|
|
'upload_date': '20231106',
|
|
|
|
'uploader_url': 'https://www.bitchute.com/profile/9K0kUWA9zmd9/',
|
|
|
|
'channel': 'Full Measure with Sharyl Attkisson',
|
2024-06-11 19:09:58 -04:00
|
|
|
'channel_url': 'https://www.bitchute.com/channel/sharylattkisson/',
|
2018-08-11 14:47:10 -04:00
|
|
|
},
|
2022-11-04 10:08:38 -04:00
|
|
|
}, {
|
|
|
|
# video not downloadable in browser, but we can recover it
|
|
|
|
'url': 'https://www.bitchute.com/video/2s6B3nZjAk7R/',
|
|
|
|
'md5': '05c12397d5354bf24494885b08d24ed1',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '2s6B3nZjAk7R',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'filesize': 71537926,
|
|
|
|
'title': 'STYXHEXENHAMMER666 - Election Fraud, Clinton 2020, EU Armies, and Gun Control',
|
|
|
|
'description': 'md5:228ee93bd840a24938f536aeac9cf749',
|
|
|
|
'thumbnail': r're:^https?://.*\.jpg$',
|
|
|
|
'uploader': 'BitChute',
|
|
|
|
'upload_date': '20181113',
|
2023-12-11 18:56:01 -05:00
|
|
|
'uploader_url': 'https://www.bitchute.com/profile/I5NgtHZn9vPj/',
|
|
|
|
'channel': 'BitChute',
|
2024-06-11 19:09:58 -04:00
|
|
|
'channel_url': 'https://www.bitchute.com/channel/bitchute/',
|
2022-11-04 10:08:38 -04:00
|
|
|
},
|
|
|
|
'params': {'check_formats': None},
|
2022-11-09 04:05:08 -05:00
|
|
|
}, {
|
|
|
|
# restricted video
|
|
|
|
'url': 'https://www.bitchute.com/video/WEnQU7XGcTdl/',
|
|
|
|
'info_dict': {
|
|
|
|
'id': 'WEnQU7XGcTdl',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'Impartial Truth - Ein Letzter Appell an die Vernunft',
|
|
|
|
},
|
|
|
|
'params': {'skip_download': True},
|
|
|
|
'skip': 'Georestricted in DE',
|
2018-08-11 14:47:10 -04:00
|
|
|
}, {
|
|
|
|
'url': 'https://www.bitchute.com/embed/lbb5G1hjPhw/',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'url': 'https://www.bitchute.com/torrent/Zee5BE49045h/szoMrox2JEI.webtorrent',
|
|
|
|
'only_matching': True,
|
2024-06-29 11:32:41 -04:00
|
|
|
}, {
|
|
|
|
'url': 'https://old.bitchute.com/video/UGlrF9o9b-Q/',
|
|
|
|
'only_matching': True,
|
2018-08-11 14:47:10 -04:00
|
|
|
}]
|
2022-11-09 04:05:08 -05:00
|
|
|
_GEO_BYPASS = False
|
2018-08-11 14:47:10 -04:00
|
|
|
|
2022-11-04 10:08:38 -04:00
|
|
|
_HEADERS = {
|
|
|
|
'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',
|
|
|
|
'Referer': 'https://www.bitchute.com/',
|
|
|
|
}
|
|
|
|
|
|
|
|
def _check_format(self, video_url, video_id):
|
|
|
|
urls = orderedSet(
|
|
|
|
re.sub(r'(^https?://)(seed\d+)(?=\.bitchute\.com)', fr'\g<1>{host}', video_url)
|
2023-04-25 12:13:54 -04:00
|
|
|
for host in (r'\g<2>', 'seed122', 'seed125', 'seed126', 'seed128',
|
|
|
|
'seed132', 'seed150', 'seed151', 'seed152', 'seed153',
|
|
|
|
'seed167', 'seed171', 'seed177', 'seed305', 'seed307',
|
|
|
|
'seedp29xb', 'zb10-7gsop1v78'))
|
2022-11-04 10:08:38 -04:00
|
|
|
for url in urls:
|
|
|
|
try:
|
|
|
|
response = self._request_webpage(
|
|
|
|
HEADRequest(url), video_id=video_id, note=f'Checking {url}', headers=self._HEADERS)
|
|
|
|
except ExtractorError as e:
|
|
|
|
self.to_screen(f'{video_id}: URL is invalid, skipping: {e.cause}')
|
|
|
|
continue
|
|
|
|
return {
|
|
|
|
'url': url,
|
2024-06-11 19:09:58 -04:00
|
|
|
'filesize': int_or_none(response.headers.get('Content-Length')),
|
2022-11-04 10:08:38 -04:00
|
|
|
}
|
|
|
|
|
2022-11-09 04:05:08 -05:00
|
|
|
def _raise_if_restricted(self, webpage):
|
|
|
|
page_title = clean_html(get_element_by_class('page-title', webpage)) or ''
|
|
|
|
if re.fullmatch(r'(?:Channel|Video) Restricted', page_title):
|
|
|
|
reason = clean_html(get_element_by_id('page-detail', webpage)) or page_title
|
|
|
|
self.raise_geo_restricted(reason)
|
|
|
|
|
2023-12-11 18:56:01 -05:00
|
|
|
@staticmethod
|
|
|
|
def _make_url(html):
|
|
|
|
path = extract_attributes(get_element_html_by_class('spa', html) or '').get('href')
|
|
|
|
return urljoin('https://www.bitchute.com', path)
|
|
|
|
|
2018-08-11 14:47:10 -04:00
|
|
|
def _real_extract(self, url):
|
|
|
|
video_id = self._match_id(url)
|
|
|
|
webpage = self._download_webpage(
|
2024-06-29 11:32:41 -04:00
|
|
|
f'https://old.bitchute.com/video/{video_id}', video_id, headers=self._HEADERS)
|
2018-08-11 14:47:10 -04:00
|
|
|
|
2022-11-09 04:05:08 -05:00
|
|
|
self._raise_if_restricted(webpage)
|
2022-11-04 10:08:38 -04:00
|
|
|
publish_date = clean_html(get_element_by_class('video-publish-date', webpage))
|
|
|
|
entries = self._parse_html5_media_entries(url, webpage, video_id)
|
2018-08-11 14:47:10 -04:00
|
|
|
|
2022-11-04 10:08:38 -04:00
|
|
|
formats = []
|
|
|
|
for format_ in traverse_obj(entries, (0, 'formats', ...)):
|
|
|
|
if self.get_param('check_formats') is not False:
|
|
|
|
format_.update(self._check_format(format_.pop('url'), video_id) or {})
|
|
|
|
if 'url' not in format_:
|
|
|
|
continue
|
|
|
|
formats.append(format_)
|
2019-06-07 11:58:19 -04:00
|
|
|
|
|
|
|
if not formats:
|
2022-11-04 10:08:38 -04:00
|
|
|
self.raise_no_formats(
|
|
|
|
'Video is unavailable. Please make sure this video is playable in the browser '
|
|
|
|
'before reporting this issue.', expected=True, video_id=video_id)
|
2018-08-11 14:47:10 -04:00
|
|
|
|
2023-12-11 18:56:01 -05:00
|
|
|
details = get_element_by_class('details', webpage) or ''
|
|
|
|
uploader_html = get_element_html_by_class('creator', details) or ''
|
|
|
|
channel_html = get_element_html_by_class('name', details) or ''
|
|
|
|
|
2018-08-11 14:47:10 -04:00
|
|
|
return {
|
|
|
|
'id': video_id,
|
2022-11-04 10:08:38 -04:00
|
|
|
'title': self._html_extract_title(webpage) or self._og_search_title(webpage),
|
|
|
|
'description': self._og_search_description(webpage, default=None),
|
|
|
|
'thumbnail': self._og_search_thumbnail(webpage),
|
2023-12-11 18:56:01 -05:00
|
|
|
'uploader': clean_html(uploader_html),
|
|
|
|
'uploader_url': self._make_url(uploader_html),
|
|
|
|
'channel': clean_html(channel_html),
|
|
|
|
'channel_url': self._make_url(channel_html),
|
2022-11-04 10:08:38 -04:00
|
|
|
'upload_date': unified_strdate(self._search_regex(
|
|
|
|
r'at \d+:\d+ UTC on (.+?)\.', publish_date, 'upload date', fatal=False)),
|
2018-08-11 14:47:10 -04:00
|
|
|
'formats': formats,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class BitChuteChannelIE(InfoExtractor):
|
2024-06-29 11:32:41 -04:00
|
|
|
_VALID_URL = r'https?://(?:(?:www|old)\.)?bitchute\.com/(?P<type>channel|playlist)/(?P<id>[^/?#&]+)'
|
2022-11-08 22:30:15 -05:00
|
|
|
_TESTS = [{
|
|
|
|
'url': 'https://www.bitchute.com/channel/bitchute/',
|
2018-08-11 14:47:10 -04:00
|
|
|
'info_dict': {
|
2022-11-08 22:30:15 -05:00
|
|
|
'id': 'bitchute',
|
|
|
|
'title': 'BitChute',
|
2024-06-29 11:32:41 -04:00
|
|
|
'description': 'md5:2134c37d64fc3a4846787c402956adac',
|
2018-08-11 14:47:10 -04:00
|
|
|
},
|
2022-11-08 22:30:15 -05:00
|
|
|
'playlist': [
|
|
|
|
{
|
|
|
|
'md5': '7e427d7ed7af5a75b5855705ec750e2b',
|
|
|
|
'info_dict': {
|
|
|
|
'id': 'UGlrF9o9b-Q',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'This is the first video on #BitChute !',
|
|
|
|
'description': 'md5:a0337e7b1fe39e32336974af8173a034',
|
|
|
|
'thumbnail': r're:^https?://.*\.jpg$',
|
|
|
|
'uploader': 'BitChute',
|
|
|
|
'upload_date': '20170103',
|
2023-12-11 18:56:01 -05:00
|
|
|
'uploader_url': 'https://www.bitchute.com/profile/I5NgtHZn9vPj/',
|
|
|
|
'channel': 'BitChute',
|
|
|
|
'channel_url': 'https://www.bitchute.com/channel/bitchute/',
|
2022-11-08 22:30:15 -05:00
|
|
|
'duration': 16,
|
|
|
|
'view_count': int,
|
|
|
|
},
|
2024-06-11 19:09:58 -04:00
|
|
|
},
|
2022-11-08 22:30:15 -05:00
|
|
|
],
|
|
|
|
'params': {
|
|
|
|
'skip_download': True,
|
|
|
|
'playlist_items': '-1',
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
'url': 'https://www.bitchute.com/playlist/wV9Imujxasw9/',
|
|
|
|
'playlist_mincount': 20,
|
|
|
|
'info_dict': {
|
|
|
|
'id': 'wV9Imujxasw9',
|
|
|
|
'title': 'Bruce MacDonald and "The Light of Darkness"',
|
2023-12-11 18:56:01 -05:00
|
|
|
'description': 'md5:747724ef404eebdfc04277714f81863e',
|
2024-06-11 19:09:58 -04:00
|
|
|
},
|
2024-06-29 11:32:41 -04:00
|
|
|
}, {
|
|
|
|
'url': 'https://old.bitchute.com/playlist/wV9Imujxasw9/',
|
|
|
|
'only_matching': True,
|
2022-11-08 22:30:15 -05:00
|
|
|
}]
|
2018-08-11 14:47:10 -04:00
|
|
|
|
|
|
|
_TOKEN = 'zyG6tQcGPE5swyAEFLqKUwMuMMuF6IO2DZ6ZDQjGfsL0e4dcTLwqkTTul05Jdve7'
|
2022-11-08 22:30:15 -05:00
|
|
|
PAGE_SIZE = 25
|
|
|
|
HTML_CLASS_NAMES = {
|
|
|
|
'channel': {
|
|
|
|
'container': 'channel-videos-container',
|
|
|
|
'title': 'channel-videos-title',
|
|
|
|
'description': 'channel-videos-text',
|
|
|
|
},
|
|
|
|
'playlist': {
|
|
|
|
'container': 'playlist-video',
|
|
|
|
'title': 'title',
|
|
|
|
'description': 'description',
|
2024-06-11 19:09:58 -04:00
|
|
|
},
|
2022-11-08 22:30:15 -05:00
|
|
|
|
|
|
|
}
|
2018-08-11 14:47:10 -04:00
|
|
|
|
2022-11-08 22:30:15 -05:00
|
|
|
@staticmethod
|
|
|
|
def _make_url(playlist_id, playlist_type):
|
2024-06-29 11:32:41 -04:00
|
|
|
return f'https://old.bitchute.com/{playlist_type}/{playlist_id}/'
|
2022-11-08 22:30:15 -05:00
|
|
|
|
|
|
|
def _fetch_page(self, playlist_id, playlist_type, page_num):
|
|
|
|
playlist_url = self._make_url(playlist_id, playlist_type)
|
|
|
|
data = self._download_json(
|
|
|
|
f'{playlist_url}extend/', playlist_id, f'Downloading page {page_num}',
|
|
|
|
data=urlencode_postdata({
|
|
|
|
'csrfmiddlewaretoken': self._TOKEN,
|
|
|
|
'name': '',
|
|
|
|
'offset': page_num * self.PAGE_SIZE,
|
|
|
|
}), headers={
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
|
|
|
'Referer': playlist_url,
|
|
|
|
'X-Requested-With': 'XMLHttpRequest',
|
|
|
|
'Cookie': f'csrftoken={self._TOKEN}',
|
|
|
|
})
|
|
|
|
if not data.get('success'):
|
|
|
|
return
|
|
|
|
classes = self.HTML_CLASS_NAMES[playlist_type]
|
|
|
|
for video_html in get_elements_html_by_class(classes['container'], data.get('html')):
|
|
|
|
video_id = self._search_regex(
|
|
|
|
r'<a\s[^>]*\bhref=["\']/video/([^"\'/]+)', video_html, 'video id', default=None)
|
|
|
|
if not video_id:
|
|
|
|
continue
|
|
|
|
yield self.url_result(
|
|
|
|
f'https://www.bitchute.com/video/{video_id}', BitChuteIE, video_id, url_transparent=True,
|
|
|
|
title=clean_html(get_element_by_class(classes['title'], video_html)),
|
|
|
|
description=clean_html(get_element_by_class(classes['description'], video_html)),
|
|
|
|
duration=parse_duration(get_element_by_class('video-duration', video_html)),
|
|
|
|
view_count=parse_count(clean_html(get_element_by_class('video-views', video_html))))
|
2018-08-11 14:47:10 -04:00
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2022-11-08 22:30:15 -05:00
|
|
|
playlist_type, playlist_id = self._match_valid_url(url).group('type', 'id')
|
|
|
|
webpage = self._download_webpage(self._make_url(playlist_id, playlist_type), playlist_id)
|
|
|
|
|
|
|
|
page_func = functools.partial(self._fetch_page, playlist_id, playlist_type)
|
2018-08-11 14:47:10 -04:00
|
|
|
return self.playlist_result(
|
2022-11-08 22:30:15 -05:00
|
|
|
OnDemandPagedList(page_func, self.PAGE_SIZE), playlist_id,
|
|
|
|
title=self._html_extract_title(webpage, default=None),
|
|
|
|
description=self._html_search_meta(
|
|
|
|
('description', 'og:description', 'twitter:description'), webpage, default=None),
|
|
|
|
playlist_count=int_or_none(self._html_search_regex(
|
|
|
|
r'<span>(\d+)\s+videos?</span>', webpage, 'playlist count', default=None)))
|