]> jfr.im git - yt-dlp.git/blame - youtube_dlc/extractor/bitchute.py
Merge branch 'alura' of https://github.com/hugohaa/youtube-dl into hugohaa-alura
[yt-dlp.git] / youtube_dlc / extractor / bitchute.py
CommitLineData
b65e3b06
S
1# coding: utf-8
2from __future__ import unicode_literals
3
4import itertools
5import re
6
7from .common import InfoExtractor
6b688b89 8from ..utils import (
37fb591c
AH
9 ExtractorError,
10 GeoRestrictedError,
6b688b89 11 orderedSet,
6ddd4bf6 12 unified_strdate,
6b688b89
S
13 urlencode_postdata,
14)
b65e3b06
S
15
16
17class BitChuteIE(InfoExtractor):
18 _VALID_URL = r'https?://(?:www\.)?bitchute\.com/(?:video|embed|torrent/[^/]+)/(?P<id>[^/?#&]+)'
19 _TESTS = [{
20 'url': 'https://www.bitchute.com/video/szoMrox2JEI/',
21 'md5': '66c4a70e6bfc40dcb6be3eb1d74939eb',
22 'info_dict': {
23 'id': 'szoMrox2JEI',
24 'ext': 'mp4',
25 'title': 'Fuck bitches get money',
26 'description': 'md5:3f21f6fb5b1d17c3dee9cf6b5fe60b3a',
27 'thumbnail': r're:^https?://.*\.jpg$',
28 'uploader': 'Victoria X Rave',
6ddd4bf6 29 'upload_date': '20170813',
b65e3b06
S
30 },
31 }, {
32 'url': 'https://www.bitchute.com/embed/lbb5G1hjPhw/',
33 'only_matching': True,
34 }, {
35 'url': 'https://www.bitchute.com/torrent/Zee5BE49045h/szoMrox2JEI.webtorrent',
36 'only_matching': True,
37 }]
38
39 def _real_extract(self, url):
40 video_id = self._match_id(url)
41
42 webpage = self._download_webpage(
02df4135
AU
43 'https://www.bitchute.com/video/%s' % video_id, video_id, headers={
44 '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',
45 })
b65e3b06 46
8578ea4d 47 title = self._html_search_regex(
b65e3b06
S
48 (r'<[^>]+\bid=["\']video-title[^>]+>([^<]+)', r'<title>([^<]+)'),
49 webpage, 'title', default=None) or self._html_search_meta(
50 'description', webpage, 'title',
51 default=None) or self._og_search_description(webpage)
52
6b688b89
S
53 format_urls = []
54 for mobj in re.finditer(
55 r'addWebSeed\s*\(\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage):
56 format_urls.append(mobj.group('url'))
57 format_urls.extend(re.findall(r'as=(https?://[^&"\']+)', webpage))
58
b65e3b06 59 formats = [
6b688b89
S
60 {'url': format_url}
61 for format_url in orderedSet(format_urls)]
4c78c3d7
S
62
63 if not formats:
37fb591c
AH
64 entries = self._parse_html5_media_entries(
65 url, webpage, video_id)
66 if not entries:
67 error = self._html_search_regex(r'<h1 class="page-title">([^<]+)</h1>', webpage, 'error', default='Cannot find video')
68 if error == 'Video Unavailable':
69 raise GeoRestrictedError(error)
70 raise ExtractorError(error)
71 formats = entries[0]['formats']
4c78c3d7 72
d65f6e73 73 self._check_formats(formats, video_id)
b65e3b06
S
74 self._sort_formats(formats)
75
76 description = self._html_search_regex(
77 r'(?s)<div\b[^>]+\bclass=["\']full hidden[^>]+>(.+?)</div>',
78 webpage, 'description', fatal=False)
79 thumbnail = self._og_search_thumbnail(
80 webpage, default=None) or self._html_search_meta(
81 'twitter:image:src', webpage, 'thumbnail')
82 uploader = self._html_search_regex(
bbf1defe
GS
83 (r'(?s)<div class=["\']channel-banner.*?<p\b[^>]+\bclass=["\']name[^>]+>(.+?)</p>',
84 r'(?s)<p\b[^>]+\bclass=["\']video-author[^>]+>(.+?)</p>'),
85 webpage, 'uploader', fatal=False)
b65e3b06 86
6ddd4bf6
I
87 upload_date = unified_strdate(self._search_regex(
88 r'class=["\']video-publish-date[^>]+>[^<]+ at \d+:\d+ UTC on (.+?)\.',
89 webpage, 'upload date', fatal=False))
90
b65e3b06
S
91 return {
92 'id': video_id,
93 'title': title,
94 'description': description,
95 'thumbnail': thumbnail,
96 'uploader': uploader,
6ddd4bf6 97 'upload_date': upload_date,
b65e3b06
S
98 'formats': formats,
99 }
100
101
102class BitChuteChannelIE(InfoExtractor):
103 _VALID_URL = r'https?://(?:www\.)?bitchute\.com/channel/(?P<id>[^/?#&]+)'
104 _TEST = {
105 'url': 'https://www.bitchute.com/channel/victoriaxrave/',
106 'playlist_mincount': 185,
107 'info_dict': {
108 'id': 'victoriaxrave',
109 },
110 }
111
112 _TOKEN = 'zyG6tQcGPE5swyAEFLqKUwMuMMuF6IO2DZ6ZDQjGfsL0e4dcTLwqkTTul05Jdve7'
113
114 def _entries(self, channel_id):
115 channel_url = 'https://www.bitchute.com/channel/%s/' % channel_id
de4c41b4
S
116 offset = 0
117 for page_num in itertools.count(1):
b65e3b06
S
118 data = self._download_json(
119 '%sextend/' % channel_url, channel_id,
de4c41b4 120 'Downloading channel page %d' % page_num,
b65e3b06
S
121 data=urlencode_postdata({
122 'csrfmiddlewaretoken': self._TOKEN,
123 'name': '',
de4c41b4 124 'offset': offset,
b65e3b06
S
125 }), headers={
126 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
127 'Referer': channel_url,
128 'X-Requested-With': 'XMLHttpRequest',
129 'Cookie': 'csrftoken=%s' % self._TOKEN,
130 })
131 if data.get('success') is False:
132 break
133 html = data.get('html')
134 if not html:
135 break
136 video_ids = re.findall(
137 r'class=["\']channel-videos-image-container[^>]+>\s*<a\b[^>]+\bhref=["\']/video/([^"\'/]+)',
138 html)
139 if not video_ids:
140 break
de4c41b4 141 offset += len(video_ids)
b65e3b06
S
142 for video_id in video_ids:
143 yield self.url_result(
144 'https://www.bitchute.com/video/%s' % video_id,
145 ie=BitChuteIE.ie_key(), video_id=video_id)
146
147 def _real_extract(self, url):
148 channel_id = self._match_id(url)
149 return self.playlist_result(
150 self._entries(channel_id), playlist_id=channel_id)