]>
Commit | Line | Data |
---|---|---|
0c873df3 AG |
1 | import re |
2 | ||
3 | from .common import InfoExtractor | |
4 | from ..utils import ( | |
5 | try_get, | |
6 | unified_strdate, | |
7 | ) | |
8 | ||
9 | ||
10 | class ThreeSpeakIE(InfoExtractor): | |
73f035e1 | 11 | _VALID_URL = r'https?://(?:www\.)?3speak\.tv/watch\?v\=[^/]+/(?P<id>[^/$&#?]+)' |
0c873df3 AG |
12 | |
13 | _TESTS = [{ | |
14 | 'url': 'https://3speak.tv/watch?v=dannyshine/wjgoxyfy', | |
15 | 'info_dict': { | |
16 | 'id': 'wjgoxyfy', | |
17 | 'ext': 'mp4', | |
18 | 'title': 'Can People who took the Vax think Critically', | |
19 | 'uploader': 'dannyshine', | |
20 | 'description': 'md5:181aa7ccb304afafa089b5af3bca7a10', | |
21 | 'tags': ['sex', 'covid', 'antinatalism', 'comedy', 'vaccines'], | |
22 | 'thumbnail': 'https://img.3speakcontent.co/wjgoxyfy/thumbnails/default.png', | |
23 | 'upload_date': '20211021', | |
24 | 'duration': 2703.867833, | |
25 | 'filesize': 1620054781, | |
26 | }, | |
27 | 'params': {'skip_download': True} | |
28 | }] | |
29 | ||
30 | def _real_extract(self, url): | |
31 | id = self._match_id(url) | |
32 | webpage = self._download_webpage(url, id) | |
33 | json_str = self._html_search_regex(r'JSON\.parse\(\'([^\']+)\'\)', webpage, 'json') | |
34 | # The json string itself is escaped. Hence the double parsing | |
35 | data_json = self._parse_json(self._parse_json(f'"{json_str}"', id), id) | |
36 | video_json = self._parse_json(data_json['json_metadata'], id) | |
37 | formats, subtitles = [], {} | |
38 | og_m3u8 = self._html_search_regex(r'<meta\s?property=\"ogvideo\"\s?content=\"([^\"]+)\">', webpage, 'og m3u8', fatal=False) | |
39 | if og_m3u8: | |
40 | https_frmts, https_subs = self._extract_m3u8_formats_and_subtitles(og_m3u8, id, fatal=False, m3u8_id='https') | |
41 | formats.extend(https_frmts) | |
42 | subtitles = self._merge_subtitles(subtitles, https_subs) | |
43 | ipfs_m3u8 = try_get(video_json, lambda x: x['video']['info']['ipfs']) | |
44 | if ipfs_m3u8: | |
45 | ipfs_frmts, ipfs_subs = self._extract_m3u8_formats_and_subtitles(f'https://ipfs.3speak.tv/ipfs/{ipfs_m3u8}', | |
46 | id, fatal=False, m3u8_id='ipfs') | |
47 | formats.extend(ipfs_frmts) | |
48 | subtitles = self._merge_subtitles(subtitles, ipfs_subs) | |
49 | mp4_file = try_get(video_json, lambda x: x['video']['info']['file']) | |
50 | if mp4_file: | |
51 | formats.append({ | |
52 | 'url': f'https://threespeakvideo.b-cdn.net/{id}/{mp4_file}', | |
53 | 'ext': 'mp4', | |
54 | 'format_id': 'https-mp4', | |
55 | 'duration': try_get(video_json, lambda x: x['video']['info']['duration']), | |
56 | 'filesize': try_get(video_json, lambda x: x['video']['info']['filesize']), | |
57 | 'quality': 11, | |
58 | 'format_note': 'Original file', | |
59 | }) | |
60 | self._sort_formats(formats) | |
61 | return { | |
62 | 'id': id, | |
63 | 'title': data_json.get('title') or data_json.get('root_title'), | |
64 | 'uploader': data_json.get('author'), | |
65 | 'description': try_get(video_json, lambda x: x['video']['content']['description']), | |
66 | 'tags': try_get(video_json, lambda x: x['video']['content']['tags']), | |
67 | 'thumbnail': try_get(video_json, lambda x: x['image'][0]), | |
68 | 'upload_date': unified_strdate(data_json.get('created')), | |
69 | 'formats': formats, | |
70 | 'subtitles': subtitles, | |
71 | } | |
72 | ||
73 | ||
74 | class ThreeSpeakUserIE(InfoExtractor): | |
73f035e1 | 75 | _VALID_URL = r'https?://(?:www\.)?3speak\.tv/user/(?P<id>[^/$&?#]+)' |
0c873df3 AG |
76 | |
77 | _TESTS = [{ | |
78 | 'url': 'https://3speak.tv/user/theycallmedan', | |
79 | 'info_dict': { | |
80 | 'id': 'theycallmedan', | |
81 | }, | |
82 | 'playlist_mincount': 115, | |
83 | }] | |
84 | ||
85 | def _real_extract(self, url): | |
86 | id = self._match_id(url) | |
87 | webpage = self._download_webpage(url, id) | |
88 | entries = [ | |
89 | self.url_result( | |
90 | 'https://3speak.tv/watch?v=%s' % video, | |
91 | ie=ThreeSpeakIE.ie_key()) | |
92 | for video in re.findall(r'data-payout\s?\=\s?\"([^\"]+)\"', webpage) if video | |
93 | ] | |
94 | return self.playlist_result(entries, id) |