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