]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/bitchute.py
446a1ab19f93955ab143e729628e4ecf1add9b16
[youtubedl] / youtube_dl / extractor / bitchute.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import itertools
5 import re
6
7 from .common import InfoExtractor
8 from ..utils import urlencode_postdata
9
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 },
24 }, {
25 'url': 'https://www.bitchute.com/embed/lbb5G1hjPhw/',
26 'only_matching': True,
27 }, {
28 'url': 'https://www.bitchute.com/torrent/Zee5BE49045h/szoMrox2JEI.webtorrent',
29 'only_matching': True,
30 }]
31
32 def _real_extract(self, url):
33 video_id = self._match_id(url)
34
35 webpage = self._download_webpage(
36 'https://www.bitchute.com/video/%s' % video_id, video_id, headers={
37 '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',
38 })
39
40 title = self._search_regex(
41 (r'<[^>]+\bid=["\']video-title[^>]+>([^<]+)', r'<title>([^<]+)'),
42 webpage, 'title', default=None) or self._html_search_meta(
43 'description', webpage, 'title',
44 default=None) or self._og_search_description(webpage)
45
46 formats = [
47 {'url': mobj.group('url')}
48 for mobj in re.finditer(
49 r'addWebSeed\s*\(\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage)]
50 self._sort_formats(formats)
51
52 description = self._html_search_regex(
53 r'(?s)<div\b[^>]+\bclass=["\']full hidden[^>]+>(.+?)</div>',
54 webpage, 'description', fatal=False)
55 thumbnail = self._og_search_thumbnail(
56 webpage, default=None) or self._html_search_meta(
57 'twitter:image:src', webpage, 'thumbnail')
58 uploader = self._html_search_regex(
59 r'(?s)<p\b[^>]+\bclass=["\']video-author[^>]+>(.+?)</p>', webpage,
60 'uploader', fatal=False)
61
62 return {
63 'id': video_id,
64 'title': title,
65 'description': description,
66 'thumbnail': thumbnail,
67 'uploader': uploader,
68 'formats': formats,
69 }
70
71
72 class BitChuteChannelIE(InfoExtractor):
73 _VALID_URL = r'https?://(?:www\.)?bitchute\.com/channel/(?P<id>[^/?#&]+)'
74 _TEST = {
75 'url': 'https://www.bitchute.com/channel/victoriaxrave/',
76 'playlist_mincount': 185,
77 'info_dict': {
78 'id': 'victoriaxrave',
79 },
80 }
81
82 _TOKEN = 'zyG6tQcGPE5swyAEFLqKUwMuMMuF6IO2DZ6ZDQjGfsL0e4dcTLwqkTTul05Jdve7'
83
84 def _entries(self, channel_id):
85 channel_url = 'https://www.bitchute.com/channel/%s/' % channel_id
86 offset = 0
87 for page_num in itertools.count(1):
88 data = self._download_json(
89 '%sextend/' % channel_url, channel_id,
90 'Downloading channel page %d' % page_num,
91 data=urlencode_postdata({
92 'csrfmiddlewaretoken': self._TOKEN,
93 'name': '',
94 'offset': offset,
95 }), headers={
96 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
97 'Referer': channel_url,
98 'X-Requested-With': 'XMLHttpRequest',
99 'Cookie': 'csrftoken=%s' % self._TOKEN,
100 })
101 if data.get('success') is False:
102 break
103 html = data.get('html')
104 if not html:
105 break
106 video_ids = re.findall(
107 r'class=["\']channel-videos-image-container[^>]+>\s*<a\b[^>]+\bhref=["\']/video/([^"\'/]+)',
108 html)
109 if not video_ids:
110 break
111 offset += len(video_ids)
112 for video_id in video_ids:
113 yield self.url_result(
114 'https://www.bitchute.com/video/%s' % video_id,
115 ie=BitChuteIE.ie_key(), video_id=video_id)
116
117 def _real_extract(self, url):
118 channel_id = self._match_id(url)
119 return self.playlist_result(
120 self._entries(channel_id), playlist_id=channel_id)