]>
Commit | Line | Data |
---|---|---|
2acf2ce5 A |
1 | import re |
2 | ||
3 | from .common import InfoExtractor | |
4 | from ..utils import ( | |
5 | clean_html, | |
1ee316a3 | 6 | int_or_none, |
7 | parse_codecs, | |
8 | parse_duration, | |
2acf2ce5 | 9 | str_to_int, |
1ee316a3 | 10 | unified_timestamp |
2acf2ce5 A |
11 | ) |
12 | ||
13 | ||
14 | class GabTVIE(InfoExtractor): | |
73f035e1 | 15 | _VALID_URL = r'https?://tv\.gab\.com/channel/[^/]+/view/(?P<id>[a-z0-9-]+)' |
2acf2ce5 A |
16 | _TESTS = [{ |
17 | 'url': 'https://tv.gab.com/channel/wurzelroot/view/why-was-america-in-afghanistan-61217eacea5665de450d0488', | |
18 | 'info_dict': { | |
19 | 'id': '61217eacea5665de450d0488', | |
20 | 'ext': 'mp4', | |
21 | 'title': 'WHY WAS AMERICA IN AFGHANISTAN - AMERICA FIRST AGAINST AMERICAN OLIGARCHY', | |
22 | 'description': None, | |
23 | 'uploader': 'Wurzelroot', | |
24 | 'uploader_id': '608fb0a85738fd1974984f7d', | |
25 | 'thumbnail': 'https://tv.gab.com/image/61217eacea5665de450d0488', | |
26 | } | |
27 | }] | |
28 | ||
29 | def _real_extract(self, url): | |
30 | id = self._match_id(url).split('-')[-1] | |
31 | webpage = self._download_webpage(url, id) | |
32 | channel_id = self._search_regex(r'data-channel-id=\"(?P<channel_id>[^\"]+)', webpage, 'channel_id') | |
33 | channel_name = self._search_regex(r'data-channel-name=\"(?P<channel_id>[^\"]+)', webpage, 'channel_name') | |
34 | title = self._search_regex(r'data-episode-title=\"(?P<channel_id>[^\"]+)', webpage, 'title') | |
35 | view_key = self._search_regex(r'data-view-key=\"(?P<channel_id>[^\"]+)', webpage, 'view_key') | |
1ee316a3 | 36 | description = clean_html( |
37 | self._html_search_regex(self._meta_regex('description'), webpage, 'description', group='content')) or None | |
38 | available_resolutions = re.findall(r'<a\ data-episode-id=\"%s\"\ data-resolution=\"(?P<resolution>[^\"]+)' % id, | |
39 | webpage) | |
2acf2ce5 A |
40 | |
41 | formats = [] | |
42 | for resolution in available_resolutions: | |
43 | frmt = { | |
44 | 'url': f'https://tv.gab.com/media/{id}?viewKey={view_key}&r={resolution}', | |
45 | 'format_id': resolution, | |
46 | 'vcodec': 'h264', | |
47 | 'acodec': 'aac', | |
48 | 'ext': 'mp4' | |
49 | } | |
50 | if 'audio-' in resolution: | |
51 | frmt['abr'] = str_to_int(resolution.replace('audio-', '')) | |
52 | frmt['height'] = 144 | |
53 | frmt['quality'] = -10 | |
54 | else: | |
55 | frmt['height'] = str_to_int(resolution.replace('p', '')) | |
56 | formats.append(frmt) | |
57 | self._sort_formats(formats) | |
58 | ||
59 | return { | |
60 | 'id': id, | |
61 | 'title': title, | |
62 | 'formats': formats, | |
63 | 'description': description, | |
64 | 'uploader': channel_name, | |
65 | 'uploader_id': channel_id, | |
66 | 'thumbnail': f'https://tv.gab.com/image/{id}', | |
67 | } | |
1ee316a3 | 68 | |
69 | ||
70 | class GabIE(InfoExtractor): | |
71 | _VALID_URL = r'https?://(?:www\.)?gab\.com/[^/]+/posts/(?P<id>\d+)' | |
72 | _TESTS = [{ | |
73 | 'url': 'https://gab.com/SomeBitchIKnow/posts/107163961867310434', | |
74 | 'md5': '8ca34fb00f1e1033b5c5988d79ec531d', | |
75 | 'info_dict': { | |
76 | 'id': '107163961867310434-0', | |
77 | 'ext': 'mp4', | |
78 | 'title': 'L on Gab', | |
79 | 'uploader_id': '946600', | |
80 | 'uploader': 'SomeBitchIKnow', | |
81 | 'description': 'md5:204055fafd5e1a519f5d6db953567ca3', | |
82 | 'timestamp': 1635192289, | |
83 | 'upload_date': '20211025', | |
84 | } | |
85 | }, { | |
86 | 'url': 'https://gab.com/TheLonelyProud/posts/107045884469287653', | |
87 | 'md5': 'f9cefcfdff6418e392611a828d47839d', | |
88 | 'info_dict': { | |
89 | 'id': '107045884469287653-0', | |
90 | 'ext': 'mp4', | |
91 | 'title': 'Jody Sadowski on Gab', | |
92 | 'uploader_id': '1390705', | |
93 | 'timestamp': 1633390571, | |
94 | 'upload_date': '20211004', | |
95 | 'uploader': 'TheLonelyProud', | |
96 | } | |
97 | }] | |
98 | ||
99 | def _real_extract(self, url): | |
100 | post_id = self._match_id(url) | |
101 | json_data = self._download_json(f'https://gab.com/api/v1/statuses/{post_id}', post_id) | |
102 | ||
103 | entries = [] | |
104 | for idx, media in enumerate(json_data['media_attachments']): | |
105 | if media.get('type') not in ('video', 'gifv'): | |
106 | continue | |
107 | metadata = media['meta'] | |
108 | format_metadata = { | |
109 | 'acodec': parse_codecs(metadata.get('audio_encode')).get('acodec'), | |
110 | 'asr': int_or_none((metadata.get('audio_bitrate') or '').split(' ')[0]), | |
111 | 'fps': metadata.get('fps'), | |
112 | } | |
113 | ||
114 | formats = [{ | |
115 | 'url': url, | |
116 | 'width': f.get('width'), | |
117 | 'height': f.get('height'), | |
118 | 'tbr': int_or_none(f.get('bitrate'), scale=1000), | |
119 | **format_metadata, | |
120 | } for url, f in ((media.get('url'), metadata.get('original') or {}), | |
121 | (media.get('source_mp4'), metadata.get('playable') or {})) if url] | |
122 | ||
123 | self._sort_formats(formats) | |
124 | ||
125 | author = json_data.get('account') or {} | |
126 | entries.append({ | |
127 | 'id': f'{post_id}-{idx}', | |
128 | 'title': f'{json_data["account"]["display_name"]} on Gab', | |
129 | 'timestamp': unified_timestamp(json_data.get('created_at')), | |
130 | 'formats': formats, | |
131 | 'description': clean_html(json_data.get('content')), | |
132 | 'duration': metadata.get('duration') or parse_duration(metadata.get('length')), | |
133 | 'like_count': json_data.get('favourites_count'), | |
134 | 'comment_count': json_data.get('replies_count'), | |
135 | 'repost_count': json_data.get('reblogs_count'), | |
136 | 'uploader': author.get('username'), | |
137 | 'uploader_id': author.get('id'), | |
138 | 'uploader_url': author.get('url'), | |
139 | }) | |
140 | ||
141 | if len(entries) > 1: | |
142 | return self.playlist_result(entries, post_id) | |
143 | ||
144 | return entries[0] |