2018-08-11 18:47:10 +00:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import itertools
|
|
|
|
import re
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
2019-01-01 11:12:44 +00:00
|
|
|
from ..utils import (
|
2022-06-09 22:42:06 +00:00
|
|
|
clean_html,
|
|
|
|
ExtractorError,
|
|
|
|
GeoRestrictedError,
|
|
|
|
get_element_by_class,
|
|
|
|
get_element_by_id,
|
2019-01-01 11:12:44 +00:00
|
|
|
orderedSet,
|
2022-06-09 22:42:06 +00:00
|
|
|
strip_or_none,
|
2019-11-26 17:20:39 +00:00
|
|
|
unified_strdate,
|
2022-06-09 22:42:06 +00:00
|
|
|
unified_timestamp,
|
2019-01-01 11:12:44 +00:00
|
|
|
urlencode_postdata,
|
|
|
|
)
|
2018-08-11 18:47:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BitChuteIE(InfoExtractor):
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?bitchute\.com/(?:video|embed|torrent/[^/]+)/(?P<id>[^/?#&]+)'
|
|
|
|
_TESTS = [{
|
2022-06-09 22:42:06 +00:00
|
|
|
'url': 'https://www.bitchute.com/video/UGlrF9o9b-Q/',
|
|
|
|
'md5': '7e427d7ed7af5a75b5855705ec750e2b',
|
2018-08-11 18:47:10 +00:00
|
|
|
'info_dict': {
|
2022-06-09 22:42:06 +00:00
|
|
|
'id': 'UGlrF9o9b-Q',
|
2018-08-11 18:47:10 +00:00
|
|
|
'ext': 'mp4',
|
2022-06-09 22:42:06 +00:00
|
|
|
'title': 'This is the first video on #BitChute !',
|
|
|
|
'timestamp': 1483425420,
|
|
|
|
'upload_date': '20170103',
|
|
|
|
'description': 'md5:a0337e7b1fe39e32336974af8173a034',
|
2018-08-11 18:47:10 +00:00
|
|
|
'thumbnail': r're:^https?://.*\.jpg$',
|
2022-06-09 22:42:06 +00:00
|
|
|
'uploader': 'BitChute',
|
2018-08-11 18:47:10 +00:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
'url': 'https://www.bitchute.com/embed/lbb5G1hjPhw/',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'url': 'https://www.bitchute.com/torrent/Zee5BE49045h/szoMrox2JEI.webtorrent',
|
|
|
|
'only_matching': True,
|
|
|
|
}]
|
|
|
|
|
2022-06-09 22:42:06 +00:00
|
|
|
@staticmethod
|
|
|
|
def _extract_urls(webpage):
|
|
|
|
urls = re.finditer(
|
|
|
|
r'''<(?:script|iframe)\b[^>]+\bsrc\s*=\s*(["'])(?P<url>%s)''' % (BitChuteIE._VALID_URL, ),
|
|
|
|
webpage)
|
|
|
|
return (mobj.group('url') for mobj in urls)
|
|
|
|
|
2018-08-11 18:47:10 +00:00
|
|
|
def _real_extract(self, url):
|
|
|
|
video_id = self._match_id(url)
|
|
|
|
|
|
|
|
webpage = self._download_webpage(
|
2018-08-27 15:04:56 +00:00
|
|
|
'https://www.bitchute.com/video/%s' % video_id, video_id, 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',
|
|
|
|
})
|
2018-08-11 18:47:10 +00:00
|
|
|
|
2022-06-09 22:42:06 +00:00
|
|
|
title = (
|
|
|
|
self._og_search_title(webpage, default=None)
|
|
|
|
or strip_or_none(clean_html(get_element_by_id('video-title', webpage)))
|
|
|
|
or self._html_search_regex(r'(?s)<title\b[^>]*>.*?</title', webpage, 'title'))
|
2018-08-11 18:47:10 +00:00
|
|
|
|
2022-06-09 22:42:06 +00:00
|
|
|
format_urls = [
|
|
|
|
mobj.group('url')
|
|
|
|
for mobj in re.finditer(
|
|
|
|
r'''\baddWebSeed\s*\(\s*(["'])(?P<url>(?:(?!\1).)+)\1''', webpage)]
|
|
|
|
format_urls.extend(re.findall(r'''as=(https?://[^&"']+)''', webpage))
|
2019-01-01 11:12:44 +00:00
|
|
|
|
2018-08-11 18:47:10 +00:00
|
|
|
formats = [
|
2019-01-01 11:12:44 +00:00
|
|
|
{'url': format_url}
|
|
|
|
for format_url in orderedSet(format_urls)]
|
2019-06-07 15:58:19 +00:00
|
|
|
|
|
|
|
if not formats:
|
2022-06-09 22:42:06 +00:00
|
|
|
entries = self._parse_html5_media_entries(
|
|
|
|
url, webpage, video_id)
|
|
|
|
if not entries:
|
|
|
|
error = strip_or_none(clean_html(self.get_element_by_id('video-title'))) or 'Cannot find video'
|
|
|
|
if error == 'Video Unavailable':
|
|
|
|
raise GeoRestrictedError(error)
|
|
|
|
raise ExtractorError(error)
|
|
|
|
formats = entries[0]['formats']
|
2019-06-07 15:58:19 +00:00
|
|
|
|
2019-01-12 20:57:31 +00:00
|
|
|
self._check_formats(formats, video_id)
|
2018-08-11 18:47:10 +00:00
|
|
|
self._sort_formats(formats)
|
|
|
|
|
2022-06-09 22:42:06 +00:00
|
|
|
description = (
|
|
|
|
self._og_search_description(webpage)
|
|
|
|
or clean_html(get_element_by_id('video-description', webpage))
|
|
|
|
or self._html_search_regex(
|
|
|
|
r'(?s)<div\b[^>]+\bclass=["\']full hidden[^>]+>(.+?)</div>',
|
|
|
|
webpage, 'description', fatal=False))
|
|
|
|
thumbnail = self._html_search_meta(
|
|
|
|
('og:image', 'twitter:image:src'), webpage, 'thumbnail', fatal=False)
|
2018-08-11 18:47:10 +00:00
|
|
|
uploader = self._html_search_regex(
|
2022-06-09 22:42:06 +00:00
|
|
|
(r'''(?s)<div\b[^>]+?\bclass\s*=\s*["']channel-banner.*?<p\b[^>]+\bclass\s*=\s*["']name\b[^>]+>(.+?)</p>''',
|
|
|
|
r'''(?s)<p\b[^>]+\bclass\s*=\s*["']video-author\b[^>]+>(.+?)</p>'''),
|
2019-05-22 20:51:50 +00:00
|
|
|
webpage, 'uploader', fatal=False)
|
2018-08-11 18:47:10 +00:00
|
|
|
|
2022-06-09 22:42:06 +00:00
|
|
|
def more_unified_timestamp(x):
|
|
|
|
# ... at hh:mm TZ on month nth.
|
|
|
|
y = re.split(r'\s+at\s+', x or '')[-1]
|
|
|
|
y = re.sub(r'(?:^\s+|\s+$|\.+$|(?<=\d)(?:st|nd|rd|th))', '', y)
|
|
|
|
y = ' '.join(reversed(re.split(r'\s+on\s+', y, 1)))
|
|
|
|
return unified_timestamp(y) or unified_timestamp(x)
|
|
|
|
|
|
|
|
timestamp = more_unified_timestamp(get_element_by_class('video-publish-date', webpage))
|
2019-11-26 17:20:39 +00:00
|
|
|
|
2018-08-11 18:47:10 +00:00
|
|
|
return {
|
|
|
|
'id': video_id,
|
|
|
|
'title': title,
|
|
|
|
'description': description,
|
|
|
|
'thumbnail': thumbnail,
|
|
|
|
'uploader': uploader,
|
2022-06-09 22:42:06 +00:00
|
|
|
'timestamp': timestamp,
|
2018-08-11 18:47:10 +00:00
|
|
|
'formats': formats,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class BitChuteChannelIE(InfoExtractor):
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?bitchute\.com/channel/(?P<id>[^/?#&]+)'
|
|
|
|
_TEST = {
|
2022-06-09 22:42:06 +00:00
|
|
|
'url': 'https://www.bitchute.com/channel/livesonnet/',
|
|
|
|
'playlist_mincount': 135,
|
2018-08-11 18:47:10 +00:00
|
|
|
'info_dict': {
|
2022-06-09 22:42:06 +00:00
|
|
|
'id': 'livesonnet',
|
2018-08-11 18:47:10 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
_TOKEN = 'zyG6tQcGPE5swyAEFLqKUwMuMMuF6IO2DZ6ZDQjGfsL0e4dcTLwqkTTul05Jdve7'
|
|
|
|
|
|
|
|
def _entries(self, channel_id):
|
2022-06-09 22:42:06 +00:00
|
|
|
channel_url = 'https://www.bitchute.com/channel/%s' % (channel_id, )
|
2018-08-11 18:52:50 +00:00
|
|
|
offset = 0
|
|
|
|
for page_num in itertools.count(1):
|
2018-08-11 18:47:10 +00:00
|
|
|
data = self._download_json(
|
2022-06-09 22:42:06 +00:00
|
|
|
channel_url + '/extend/', channel_id,
|
|
|
|
'Downloading channel page %d' % (page_num, ),
|
2018-08-11 18:47:10 +00:00
|
|
|
data=urlencode_postdata({
|
|
|
|
'csrfmiddlewaretoken': self._TOKEN,
|
|
|
|
'name': '',
|
2018-08-11 18:52:50 +00:00
|
|
|
'offset': offset,
|
2018-08-11 18:47:10 +00:00
|
|
|
}), headers={
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
|
|
|
'Referer': channel_url,
|
|
|
|
'X-Requested-With': 'XMLHttpRequest',
|
2022-06-09 22:42:06 +00:00
|
|
|
'Cookie': 'csrftoken=' + self._TOKEN,
|
2018-08-11 18:47:10 +00:00
|
|
|
})
|
|
|
|
if data.get('success') is False:
|
|
|
|
break
|
|
|
|
html = data.get('html')
|
|
|
|
if not html:
|
|
|
|
break
|
|
|
|
video_ids = re.findall(
|
2022-06-09 22:42:06 +00:00
|
|
|
r'''class\s*=\s*["']channel-videos-image-container[^>]+>\s*<a\b[^>]+\bhref\s*=\s*["']/video/([^"'/]+)''',
|
2018-08-11 18:47:10 +00:00
|
|
|
html)
|
|
|
|
if not video_ids:
|
|
|
|
break
|
2018-08-11 18:52:50 +00:00
|
|
|
offset += len(video_ids)
|
2018-08-11 18:47:10 +00:00
|
|
|
for video_id in video_ids:
|
|
|
|
yield self.url_result(
|
2022-06-09 22:42:06 +00:00
|
|
|
'https://www.bitchute.com/video/' + video_id,
|
2018-08-11 18:47:10 +00:00
|
|
|
ie=BitChuteIE.ie_key(), video_id=video_id)
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
channel_id = self._match_id(url)
|
|
|
|
return self.playlist_result(
|
|
|
|
self._entries(channel_id), playlist_id=channel_id)
|