]>
Commit | Line | Data |
---|---|---|
f7f18f90 | 1 | import itertools |
b801cd71 | 2 | import json |
bd9ff55b | 3 | import random |
b801cd71 | 4 | import re |
bd9ff55b M |
5 | import string |
6 | import time | |
1ead840d KS |
7 | |
8 | from .common import InfoExtractor | |
b801cd71 | 9 | from ..compat import compat_urllib_parse_unquote, compat_urllib_parse_urlparse |
1ead840d | 10 | from ..utils import ( |
ce18a19b | 11 | ExtractorError, |
88afe056 | 12 | HEADRequest, |
b801cd71 | 13 | LazyList, |
11e1c2e3 | 14 | UnsupportedError, |
ff91cf74 | 15 | get_first, |
1ead840d | 16 | int_or_none, |
34921b43 | 17 | join_nonempty, |
b801cd71 | 18 | qualities, |
e0585e65 | 19 | srt_subtitles_timecode, |
1ead840d | 20 | str_or_none, |
bd9ff55b M |
21 | traverse_obj, |
22 | try_get, | |
943d5ab1 | 23 | url_or_none, |
1ead840d KS |
24 | ) |
25 | ||
26 | ||
0fd6661e | 27 | class TikTokBaseIE(InfoExtractor): |
046cab39 M |
28 | _APP_VERSIONS = [('20.9.3', '293'), ('20.4.3', '243'), ('20.2.1', '221'), ('20.1.2', '212'), ('20.0.4', '204')] |
29 | _WORKING_APP_VERSION = None | |
943d5ab1 M |
30 | _APP_NAME = 'trill' |
31 | _AID = 1180 | |
53dad39e | 32 | _API_HOSTNAME = 'api-h2.tiktokv.com' |
943d5ab1 | 33 | _UPLOADER_URL_FORMAT = 'https://www.tiktok.com/@%s' |
53dad39e | 34 | _WEBPAGE_HOST = 'https://www.tiktok.com/' |
be1f331f | 35 | QUALITIES = ('360p', '540p', '720p', '1080p') |
ce18a19b | 36 | |
b801cd71 | 37 | @staticmethod |
38 | def _create_url(user_id, video_id): | |
39 | return f'https://www.tiktok.com/@{user_id or "_"}/video/{video_id}' | |
40 | ||
046cab39 M |
41 | def _call_api_impl(self, ep, query, manifest_app_version, video_id, fatal=True, |
42 | note='Downloading API JSON', errnote='Unable to download API page'): | |
43 | self._set_cookie(self._API_HOSTNAME, 'odin_tt', ''.join(random.choice('0123456789abcdef') for _ in range(160))) | |
44 | webpage_cookies = self._get_cookies(self._WEBPAGE_HOST) | |
45 | if webpage_cookies.get('sid_tt'): | |
46 | self._set_cookie(self._API_HOSTNAME, 'sid_tt', webpage_cookies['sid_tt'].value) | |
47 | return self._download_json( | |
48 | 'https://%s/aweme/v1/%s/' % (self._API_HOSTNAME, ep), video_id=video_id, | |
49 | fatal=fatal, note=note, errnote=errnote, headers={ | |
50 | 'User-Agent': f'com.ss.android.ugc.trill/{manifest_app_version} (Linux; U; Android 10; en_US; Pixel 4; Build/QQ3A.200805.001; Cronet/58.0.2991.0)', | |
51 | 'Accept': 'application/json', | |
52 | }, query=query) | |
53 | ||
54 | def _build_api_query(self, query, app_version, manifest_app_version): | |
55 | return { | |
0fd6661e | 56 | **query, |
046cab39 M |
57 | 'version_name': app_version, |
58 | 'version_code': manifest_app_version, | |
59 | 'build_number': app_version, | |
60 | 'manifest_version_code': manifest_app_version, | |
61 | 'update_version_code': manifest_app_version, | |
0930b11f | 62 | 'openudid': ''.join(random.choice('0123456789abcdef') for _ in range(16)), |
63 | 'uuid': ''.join([random.choice(string.digits) for _ in range(16)]), | |
bd9ff55b M |
64 | '_rticket': int(time.time() * 1000), |
65 | 'ts': int(time.time()), | |
66 | 'device_brand': 'Google', | |
67 | 'device_type': 'Pixel 4', | |
68 | 'device_platform': 'android', | |
69 | 'resolution': '1080*1920', | |
70 | 'dpi': 420, | |
71 | 'os_version': '10', | |
72 | 'os_api': '29', | |
73 | 'carrier_region': 'US', | |
74 | 'sys_region': 'US', | |
75 | 'region': 'US', | |
943d5ab1 | 76 | 'app_name': self._APP_NAME, |
bd9ff55b M |
77 | 'app_language': 'en', |
78 | 'language': 'en', | |
79 | 'timezone_name': 'America/New_York', | |
80 | 'timezone_offset': '-14400', | |
81 | 'channel': 'googleplay', | |
82 | 'ac': 'wifi', | |
83 | 'mcc_mnc': '310260', | |
84 | 'is_my_cn': 0, | |
943d5ab1 | 85 | 'aid': self._AID, |
bd9ff55b M |
86 | 'ssmix': 'a', |
87 | 'as': 'a1qwert123', | |
88 | 'cp': 'cbfhckdckkde1', | |
89 | } | |
046cab39 M |
90 | |
91 | def _call_api(self, ep, query, video_id, fatal=True, | |
92 | note='Downloading API JSON', errnote='Unable to download API page'): | |
93 | if not self._WORKING_APP_VERSION: | |
94 | app_version = self._configuration_arg('app_version', [''], ie_key=TikTokIE.ie_key())[0] | |
95 | manifest_app_version = self._configuration_arg('manifest_app_version', [''], ie_key=TikTokIE.ie_key())[0] | |
96 | if app_version and manifest_app_version: | |
97 | self._WORKING_APP_VERSION = (app_version, manifest_app_version) | |
98 | self.write_debug('Imported app version combo from extractor arguments') | |
99 | elif app_version or manifest_app_version: | |
100 | self.report_warning('Only one of the two required version params are passed as extractor arguments', only_once=True) | |
101 | ||
102 | if self._WORKING_APP_VERSION: | |
103 | app_version, manifest_app_version = self._WORKING_APP_VERSION | |
104 | real_query = self._build_api_query(query, app_version, manifest_app_version) | |
105 | return self._call_api_impl(ep, real_query, manifest_app_version, video_id, fatal, note, errnote) | |
106 | ||
107 | for count, (app_version, manifest_app_version) in enumerate(self._APP_VERSIONS, start=1): | |
108 | real_query = self._build_api_query(query, app_version, manifest_app_version) | |
109 | try: | |
110 | res = self._call_api_impl(ep, real_query, manifest_app_version, video_id, fatal, note, errnote) | |
111 | self._WORKING_APP_VERSION = (app_version, manifest_app_version) | |
112 | return res | |
113 | except ExtractorError as e: | |
114 | if isinstance(e.cause, json.JSONDecodeError) and e.cause.pos == 0: | |
115 | if count == len(self._APP_VERSIONS): | |
116 | if fatal: | |
117 | raise e | |
118 | else: | |
119 | self.report_warning(str(e.cause or e.msg)) | |
120 | return | |
121 | self.report_warning('%s. Retrying... (attempt %s of %s)' % (str(e.cause or e.msg), count, len(self._APP_VERSIONS))) | |
122 | continue | |
123 | raise e | |
0fd6661e | 124 | |
e0585e65 M |
125 | def _get_subtitles(self, aweme_detail, aweme_id): |
126 | # TODO: Extract text positioning info | |
127 | subtitles = {} | |
128 | captions_info = traverse_obj( | |
129 | aweme_detail, ('interaction_stickers', ..., 'auto_video_caption_info', 'auto_captions', ...), expected_type=dict, default=[]) | |
130 | for caption in captions_info: | |
131 | caption_url = traverse_obj(caption, ('url', 'url_list', ...), expected_type=url_or_none, get_all=False) | |
132 | if not caption_url: | |
133 | continue | |
134 | caption_json = self._download_json( | |
135 | caption_url, aweme_id, note='Downloading captions', errnote='Unable to download captions', fatal=False) | |
136 | if not caption_json: | |
137 | continue | |
138 | subtitles.setdefault(caption.get('language', 'en'), []).append({ | |
139 | 'ext': 'srt', | |
140 | 'data': '\n\n'.join( | |
141 | f'{i + 1}\n{srt_subtitles_timecode(line["start_time"] / 1000)} --> {srt_subtitles_timecode(line["end_time"] / 1000)}\n{line["text"]}' | |
142 | for i, line in enumerate(caption_json['utterances']) if line.get('text')) | |
143 | }) | |
144 | return subtitles | |
145 | ||
943d5ab1 | 146 | def _parse_aweme_video_app(self, aweme_detail): |
0fd6661e | 147 | aweme_id = aweme_detail['aweme_id'] |
bd9ff55b M |
148 | video_info = aweme_detail['video'] |
149 | ||
150 | def parse_url_key(url_key): | |
151 | format_id, codec, res, bitrate = self._search_regex( | |
152 | r'v[^_]+_(?P<id>(?P<codec>[^_]+)_(?P<res>\d+p)_(?P<bitrate>\d+))', url_key, | |
153 | 'url key', default=(None, None, None, None), group=('id', 'codec', 'res', 'bitrate')) | |
154 | if not format_id: | |
155 | return {}, None | |
156 | return { | |
157 | 'format_id': format_id, | |
158 | 'vcodec': 'h265' if codec == 'bytevc1' else codec, | |
159 | 'tbr': int_or_none(bitrate, scale=1000) or None, | |
160 | 'quality': qualities(self.QUALITIES)(res), | |
161 | }, res | |
162 | ||
163 | known_resolutions = {} | |
164 | ||
165 | def extract_addr(addr, add_meta={}): | |
166 | parsed_meta, res = parse_url_key(addr.get('url_key', '')) | |
167 | if res: | |
168 | known_resolutions.setdefault(res, {}).setdefault('height', add_meta.get('height')) | |
169 | known_resolutions[res].setdefault('width', add_meta.get('width')) | |
170 | parsed_meta.update(known_resolutions.get(res, {})) | |
171 | add_meta.setdefault('height', int_or_none(res[:-1])) | |
172 | return [{ | |
173 | 'url': url, | |
174 | 'filesize': int_or_none(addr.get('data_size')), | |
175 | 'ext': 'mp4', | |
176 | 'acodec': 'aac', | |
0fd6661e M |
177 | 'source_preference': -2 if 'aweme/v1' in url else -1, # Downloads from API might get blocked |
178 | **add_meta, **parsed_meta, | |
34921b43 | 179 | 'format_note': join_nonempty( |
180 | add_meta.get('format_note'), '(API)' if 'aweme/v1' in url else None, delim=' ') | |
bd9ff55b M |
181 | } for url in addr.get('url_list') or []] |
182 | ||
183 | # Hack: Add direct video links first to prioritize them when removing duplicate formats | |
184 | formats = [] | |
185 | if video_info.get('play_addr'): | |
186 | formats.extend(extract_addr(video_info['play_addr'], { | |
187 | 'format_id': 'play_addr', | |
188 | 'format_note': 'Direct video', | |
189 | 'vcodec': 'h265' if traverse_obj( | |
be1f331f | 190 | video_info, 'is_bytevc1', 'is_h265') else 'h264', # TODO: Check for "direct iOS" videos, like https://www.tiktok.com/@cookierun_dev/video/7039716639834656002 |
bd9ff55b M |
191 | 'width': video_info.get('width'), |
192 | 'height': video_info.get('height'), | |
193 | })) | |
194 | if video_info.get('download_addr'): | |
195 | formats.extend(extract_addr(video_info['download_addr'], { | |
196 | 'format_id': 'download_addr', | |
197 | 'format_note': 'Download video%s' % (', watermarked' if video_info.get('has_watermark') else ''), | |
198 | 'vcodec': 'h264', | |
199 | 'width': video_info.get('width'), | |
200 | 'height': video_info.get('height'), | |
0fd6661e | 201 | 'preference': -2 if video_info.get('has_watermark') else -1, |
bd9ff55b M |
202 | })) |
203 | if video_info.get('play_addr_h264'): | |
204 | formats.extend(extract_addr(video_info['play_addr_h264'], { | |
205 | 'format_id': 'play_addr_h264', | |
206 | 'format_note': 'Direct video', | |
207 | 'vcodec': 'h264', | |
208 | })) | |
209 | if video_info.get('play_addr_bytevc1'): | |
210 | formats.extend(extract_addr(video_info['play_addr_bytevc1'], { | |
211 | 'format_id': 'play_addr_bytevc1', | |
212 | 'format_note': 'Direct video', | |
213 | 'vcodec': 'h265', | |
214 | })) | |
215 | ||
216 | for bitrate in video_info.get('bit_rate', []): | |
217 | if bitrate.get('play_addr'): | |
218 | formats.extend(extract_addr(bitrate['play_addr'], { | |
219 | 'format_id': bitrate.get('gear_name'), | |
220 | 'format_note': 'Playback video', | |
221 | 'tbr': try_get(bitrate, lambda x: x['bit_rate'] / 1000), | |
222 | 'vcodec': 'h265' if traverse_obj( | |
223 | bitrate, 'is_bytevc1', 'is_h265') else 'h264', | |
943d5ab1 | 224 | 'fps': bitrate.get('FPS'), |
bd9ff55b M |
225 | })) |
226 | ||
227 | self._remove_duplicate_formats(formats) | |
6134fbeb M |
228 | auth_cookie = self._get_cookies(self._WEBPAGE_HOST).get('sid_tt') |
229 | if auth_cookie: | |
230 | for f in formats: | |
be1f331f | 231 | self._set_cookie(compat_urllib_parse_urlparse(f['url']).hostname, 'sid_tt', auth_cookie.value) |
0fd6661e | 232 | self._sort_formats(formats, ('quality', 'codec', 'size', 'br')) |
bd9ff55b M |
233 | |
234 | thumbnails = [] | |
235 | for cover_id in ('cover', 'ai_dynamic_cover', 'animated_cover', 'ai_dynamic_cover_bak', | |
236 | 'origin_cover', 'dynamic_cover'): | |
237 | cover = video_info.get(cover_id) | |
238 | if cover: | |
239 | for cover_url in cover['url_list']: | |
240 | thumbnails.append({ | |
241 | 'id': cover_id, | |
242 | 'url': cover_url, | |
243 | }) | |
244 | ||
245 | stats_info = aweme_detail.get('statistics', {}) | |
246 | author_info = aweme_detail.get('author', {}) | |
247 | music_info = aweme_detail.get('music', {}) | |
943d5ab1 M |
248 | user_url = self._UPLOADER_URL_FORMAT % (traverse_obj(author_info, |
249 | 'sec_uid', 'id', 'uid', 'unique_id', | |
250 | expected_type=str_or_none, get_all=False)) | |
a8549f19 | 251 | labels = traverse_obj(aweme_detail, ('hybrid_label', ..., 'text'), expected_type=str, default=[]) |
bd9ff55b M |
252 | |
253 | contained_music_track = traverse_obj( | |
254 | music_info, ('matched_song', 'title'), ('matched_pgc_sound', 'title'), expected_type=str) | |
255 | contained_music_author = traverse_obj( | |
256 | music_info, ('matched_song', 'author'), ('matched_pgc_sound', 'author'), 'author', expected_type=str) | |
257 | ||
258 | is_generic_og_trackname = music_info.get('is_original_sound') and music_info.get('title') == 'original sound - %s' % music_info.get('owner_handle') | |
259 | if is_generic_og_trackname: | |
260 | music_track, music_author = contained_music_track or 'original sound', contained_music_author | |
261 | else: | |
262 | music_track, music_author = music_info.get('title'), music_info.get('author') | |
263 | ||
264 | return { | |
265 | 'id': aweme_id, | |
5fa3c9a8 | 266 | 'title': aweme_detail.get('desc'), |
a44ca5a4 | 267 | 'description': aweme_detail.get('desc'), |
bd9ff55b M |
268 | 'view_count': int_or_none(stats_info.get('play_count')), |
269 | 'like_count': int_or_none(stats_info.get('digg_count')), | |
270 | 'repost_count': int_or_none(stats_info.get('share_count')), | |
271 | 'comment_count': int_or_none(stats_info.get('comment_count')), | |
272 | 'uploader': str_or_none(author_info.get('unique_id')), | |
943d5ab1 | 273 | 'creator': str_or_none(author_info.get('nickname')), |
bd9ff55b | 274 | 'uploader_id': str_or_none(author_info.get('uid')), |
943d5ab1 | 275 | 'uploader_url': user_url, |
bd9ff55b M |
276 | 'track': music_track, |
277 | 'album': str_or_none(music_info.get('album')) or None, | |
278 | 'artist': music_author, | |
279 | 'timestamp': int_or_none(aweme_detail.get('create_time')), | |
280 | 'formats': formats, | |
e0585e65 | 281 | 'subtitles': self.extract_subtitles(aweme_detail, aweme_id), |
bd9ff55b | 282 | 'thumbnails': thumbnails, |
53dad39e M |
283 | 'duration': int_or_none(traverse_obj(video_info, 'duration', ('download_addr', 'duration')), scale=1000), |
284 | 'availability': self._availability( | |
285 | is_private='Private' in labels, | |
286 | needs_subscription='Friends only' in labels, | |
287 | is_unlisted='Followers only' in labels) | |
bd9ff55b M |
288 | } |
289 | ||
0481e266 | 290 | def _parse_aweme_video_web(self, aweme_detail, webpage_url): |
943d5ab1 | 291 | video_info = aweme_detail['video'] |
11aa91a1 | 292 | author_info = traverse_obj(aweme_detail, 'authorInfo', 'author', expected_type=dict, default={}) |
943d5ab1 M |
293 | music_info = aweme_detail.get('music') or {} |
294 | stats_info = aweme_detail.get('stats') or {} | |
295 | user_url = self._UPLOADER_URL_FORMAT % (traverse_obj(author_info, | |
296 | 'secUid', 'id', 'uid', 'uniqueId', | |
11aa91a1 M |
297 | expected_type=str_or_none, get_all=False) |
298 | or aweme_detail.get('authorSecId')) | |
943d5ab1 M |
299 | |
300 | formats = [] | |
301 | play_url = video_info.get('playAddr') | |
302 | width = video_info.get('width') | |
303 | height = video_info.get('height') | |
304 | if isinstance(play_url, str): | |
305 | formats = [{ | |
306 | 'url': self._proto_relative_url(play_url), | |
307 | 'ext': 'mp4', | |
308 | 'width': width, | |
309 | 'height': height, | |
310 | }] | |
311 | elif isinstance(play_url, list): | |
312 | formats = [{ | |
313 | 'url': self._proto_relative_url(url), | |
314 | 'ext': 'mp4', | |
315 | 'width': width, | |
316 | 'height': height, | |
317 | } for url in traverse_obj(play_url, (..., 'src'), expected_type=url_or_none, default=[]) if url] | |
318 | ||
319 | download_url = url_or_none(video_info.get('downloadAddr')) or traverse_obj(video_info, ('download', 'url'), expected_type=url_or_none) | |
320 | if download_url: | |
321 | formats.append({ | |
322 | 'format_id': 'download', | |
323 | 'url': self._proto_relative_url(download_url), | |
324 | 'ext': 'mp4', | |
325 | 'width': width, | |
326 | 'height': height, | |
327 | }) | |
328 | self._remove_duplicate_formats(formats) | |
329 | self._sort_formats(formats) | |
330 | ||
331 | thumbnails = [] | |
332 | for thumbnail_name in ('thumbnail', 'cover', 'dynamicCover', 'originCover'): | |
333 | if aweme_detail.get(thumbnail_name): | |
334 | thumbnails = [{ | |
335 | 'url': self._proto_relative_url(aweme_detail[thumbnail_name]), | |
336 | 'width': width, | |
337 | 'height': height | |
338 | }] | |
339 | ||
340 | return { | |
341 | 'id': traverse_obj(aweme_detail, 'id', 'awemeId', expected_type=str_or_none), | |
342 | 'title': aweme_detail.get('desc'), | |
343 | 'duration': try_get(aweme_detail, lambda x: x['video']['duration'], int), | |
344 | 'view_count': int_or_none(stats_info.get('playCount')), | |
345 | 'like_count': int_or_none(stats_info.get('diggCount')), | |
346 | 'repost_count': int_or_none(stats_info.get('shareCount')), | |
347 | 'comment_count': int_or_none(stats_info.get('commentCount')), | |
348 | 'timestamp': int_or_none(aweme_detail.get('createTime')), | |
349 | 'creator': str_or_none(author_info.get('nickname')), | |
11aa91a1 M |
350 | 'uploader': str_or_none(author_info.get('uniqueId') or aweme_detail.get('author')), |
351 | 'uploader_id': str_or_none(author_info.get('id') or aweme_detail.get('authorId')), | |
943d5ab1 M |
352 | 'uploader_url': user_url, |
353 | 'track': str_or_none(music_info.get('title')), | |
354 | 'album': str_or_none(music_info.get('album')) or None, | |
355 | 'artist': str_or_none(music_info.get('authorName')), | |
356 | 'formats': formats, | |
357 | 'thumbnails': thumbnails, | |
358 | 'description': str_or_none(aweme_detail.get('desc')), | |
359 | 'http_headers': { | |
0481e266 | 360 | 'Referer': webpage_url |
943d5ab1 M |
361 | } |
362 | } | |
363 | ||
0fd6661e M |
364 | |
365 | class TikTokIE(TikTokBaseIE): | |
b801cd71 | 366 | _VALID_URL = r'https?://www\.tiktok\.com/(?:embed|@(?P<user_id>[\w\.-]+)/video)/(?P<id>\d+)' |
0fd6661e M |
367 | |
368 | _TESTS = [{ | |
369 | 'url': 'https://www.tiktok.com/@leenabhushan/video/6748451240264420610', | |
0481e266 | 370 | 'md5': '736bb7a466c6f0a6afeb597da1e6f5b7', |
0fd6661e M |
371 | 'info_dict': { |
372 | 'id': '6748451240264420610', | |
373 | 'ext': 'mp4', | |
374 | 'title': '#jassmanak #lehanga #leenabhushan', | |
375 | 'description': '#jassmanak #lehanga #leenabhushan', | |
376 | 'duration': 13, | |
0481e266 | 377 | 'height': 1024, |
378 | 'width': 576, | |
0fd6661e M |
379 | 'uploader': 'leenabhushan', |
380 | 'uploader_id': '6691488002098119685', | |
0481e266 | 381 | 'uploader_url': 'https://www.tiktok.com/@MS4wLjABAAAA_Eb4t1vodM1IuTy_cvp9CY22RAb59xqrO0Xtz9CYQJvgXaDvZxYnZYRzDWhhgJmy', |
0fd6661e M |
382 | 'creator': 'facestoriesbyleenabh', |
383 | 'thumbnail': r're:^https?://[\w\/\.\-]+(~[\w\-]+\.image)?', | |
384 | 'upload_date': '20191016', | |
385 | 'timestamp': 1571246252, | |
386 | 'view_count': int, | |
387 | 'like_count': int, | |
388 | 'repost_count': int, | |
389 | 'comment_count': int, | |
a44ca5a4 | 390 | 'artist': 'Ysrbeats', |
391 | 'album': 'Lehanga', | |
392 | 'track': 'Lehanga', | |
0fd6661e M |
393 | } |
394 | }, { | |
395 | 'url': 'https://www.tiktok.com/@patroxofficial/video/6742501081818877190?langCountry=en', | |
0481e266 | 396 | 'md5': '6f3cf8cdd9b28cb8363fe0a9a160695b', |
0fd6661e M |
397 | 'info_dict': { |
398 | 'id': '6742501081818877190', | |
399 | 'ext': 'mp4', | |
400 | 'title': 'md5:5e2a23877420bb85ce6521dbee39ba94', | |
401 | 'description': 'md5:5e2a23877420bb85ce6521dbee39ba94', | |
402 | 'duration': 27, | |
403 | 'height': 960, | |
404 | 'width': 540, | |
405 | 'uploader': 'patrox', | |
406 | 'uploader_id': '18702747', | |
0481e266 | 407 | 'uploader_url': 'https://www.tiktok.com/@MS4wLjABAAAAiFnldaILebi5heDoVU6bn4jBWWycX6-9U3xuNPqZ8Ws', |
0fd6661e M |
408 | 'creator': 'patroX', |
409 | 'thumbnail': r're:^https?://[\w\/\.\-]+(~[\w\-]+\.image)?', | |
410 | 'upload_date': '20190930', | |
411 | 'timestamp': 1569860870, | |
412 | 'view_count': int, | |
413 | 'like_count': int, | |
414 | 'repost_count': int, | |
415 | 'comment_count': int, | |
a44ca5a4 | 416 | 'artist': 'Evan Todd, Jessica Keenan Wynn, Alice Lee, Barrett Wilbert Weed & Jon Eidson', |
417 | 'track': 'Big Fun', | |
0fd6661e M |
418 | } |
419 | }, { | |
96f13f01 M |
420 | # Banned audio, only available on the app |
421 | 'url': 'https://www.tiktok.com/@barudakhb_/video/6984138651336838402', | |
422 | 'info_dict': { | |
423 | 'id': '6984138651336838402', | |
424 | 'ext': 'mp4', | |
425 | 'title': 'Balas @yolaaftwsr hayu yu ? #SquadRandom_ 🔥', | |
426 | 'description': 'Balas @yolaaftwsr hayu yu ? #SquadRandom_ 🔥', | |
427 | 'uploader': 'barudakhb_', | |
428 | 'creator': 'md5:29f238c49bc0c176cb3cef1a9cea9fa6', | |
429 | 'uploader_id': '6974687867511718913', | |
430 | 'uploader_url': 'https://www.tiktok.com/@MS4wLjABAAAAbhBwQC-R1iKoix6jDFsF-vBdfx2ABoDjaZrM9fX6arU3w71q3cOWgWuTXn1soZ7d', | |
431 | 'track': 'Boka Dance', | |
432 | 'artist': 'md5:29f238c49bc0c176cb3cef1a9cea9fa6', | |
433 | 'timestamp': 1626121503, | |
434 | 'duration': 18, | |
435 | 'thumbnail': r're:^https?://[\w\/\.\-]+(~[\w\-]+\.image)?', | |
436 | 'upload_date': '20210712', | |
437 | 'view_count': int, | |
438 | 'like_count': int, | |
439 | 'repost_count': int, | |
440 | 'comment_count': int, | |
441 | } | |
442 | }, { | |
443 | # Sponsored video, only available with feed workaround | |
444 | 'url': 'https://www.tiktok.com/@MS4wLjABAAAATh8Vewkn0LYM7Fo03iec3qKdeCUOcBIouRk1mkiag6h3o_pQu_dUXvZ2EZlGST7_/video/7042692929109986561', | |
445 | 'info_dict': { | |
446 | 'id': '7042692929109986561', | |
447 | 'ext': 'mp4', | |
448 | 'title': 'Slap and Run!', | |
449 | 'description': 'Slap and Run!', | |
450 | 'uploader': 'user440922249', | |
451 | 'creator': 'Slap And Run', | |
452 | 'uploader_id': '7036055384943690754', | |
453 | 'uploader_url': 'https://www.tiktok.com/@MS4wLjABAAAATh8Vewkn0LYM7Fo03iec3qKdeCUOcBIouRk1mkiag6h3o_pQu_dUXvZ2EZlGST7_', | |
454 | 'track': 'Promoted Music', | |
455 | 'timestamp': 1639754738, | |
456 | 'duration': 30, | |
457 | 'thumbnail': r're:^https?://[\w\/\.\-]+(~[\w\-]+\.image)?', | |
458 | 'upload_date': '20211217', | |
459 | 'view_count': int, | |
460 | 'like_count': int, | |
461 | 'repost_count': int, | |
462 | 'comment_count': int, | |
463 | }, | |
464 | 'expected_warnings': ['Video not available'] | |
5fa3c9a8 HTL |
465 | }, { |
466 | # Video without title and description | |
467 | 'url': 'https://www.tiktok.com/@pokemonlife22/video/7059698374567611694', | |
468 | 'info_dict': { | |
469 | 'id': '7059698374567611694', | |
470 | 'ext': 'mp4', | |
b801cd71 | 471 | 'title': 'TikTok video #7059698374567611694', |
5fa3c9a8 HTL |
472 | 'description': '', |
473 | 'uploader': 'pokemonlife22', | |
474 | 'creator': 'Pokemon', | |
475 | 'uploader_id': '6820838815978423302', | |
476 | 'uploader_url': 'https://www.tiktok.com/@MS4wLjABAAAA0tF1nBwQVVMyrGu3CqttkNgM68Do1OXUFuCY0CRQk8fEtSVDj89HqoqvbSTmUP2W', | |
477 | 'track': 'original sound', | |
478 | 'timestamp': 1643714123, | |
479 | 'duration': 6, | |
480 | 'thumbnail': r're:^https?://[\w\/\.\-]+(~[\w\-]+\.image)?', | |
481 | 'upload_date': '20220201', | |
482 | 'artist': 'Pokemon', | |
483 | 'view_count': int, | |
484 | 'like_count': int, | |
485 | 'repost_count': int, | |
486 | 'comment_count': int, | |
487 | }, | |
a44ca5a4 | 488 | 'expected_warnings': ['Video not available', 'Creating a generic title'] |
e0585e65 M |
489 | }, { |
490 | # Auto-captions available | |
491 | 'url': 'https://www.tiktok.com/@hankgreen1/video/7047596209028074758', | |
492 | 'only_matching': True | |
0fd6661e M |
493 | }] |
494 | ||
b801cd71 | 495 | @classmethod |
496 | def _extract_urls(cls, webpage): | |
497 | return [mobj.group('url') for mobj in re.finditer( | |
498 | rf'<(?:script|iframe)[^>]+\bsrc=(["\'])(?P<url>{cls._VALID_URL})', webpage)] | |
499 | ||
0fd6661e | 500 | def _extract_aweme_app(self, aweme_id): |
e540c56f M |
501 | try: |
502 | aweme_detail = self._call_api('aweme/detail', {'aweme_id': aweme_id}, aweme_id, | |
503 | note='Downloading video details', errnote='Unable to download video details').get('aweme_detail') | |
504 | if not aweme_detail: | |
505 | raise ExtractorError('Video not available', video_id=aweme_id) | |
506 | except ExtractorError as e: | |
507 | self.report_warning(f'{e}; Retrying with feed workaround') | |
508 | feed_list = self._call_api('feed', {'aweme_id': aweme_id}, aweme_id, | |
509 | note='Downloading video feed', errnote='Unable to download video feed').get('aweme_list') or [] | |
be1f331f | 510 | aweme_detail = next((aweme for aweme in feed_list if str(aweme.get('aweme_id')) == aweme_id), None) |
e540c56f M |
511 | if not aweme_detail: |
512 | raise ExtractorError('Unable to find video in feed', video_id=aweme_id) | |
943d5ab1 | 513 | return self._parse_aweme_video_app(aweme_detail) |
0fd6661e | 514 | |
ce18a19b | 515 | def _real_extract(self, url): |
b801cd71 | 516 | video_id, user_id = self._match_valid_url(url).group('id', 'user_id') |
517 | url = self._create_url(user_id, video_id) | |
ce18a19b | 518 | |
bd9ff55b M |
519 | try: |
520 | return self._extract_aweme_app(video_id) | |
521 | except ExtractorError as e: | |
522 | self.report_warning(f'{e}; Retrying with webpage') | |
523 | ||
7bbc0bbc | 524 | # If we only call once, we get a 403 when downlaoding the video. |
61e76c1e | 525 | self._download_webpage(url, video_id) |
6fb11ca8 | 526 | webpage = self._download_webpage(url, video_id, note='Downloading video webpage') |
135dfa2c | 527 | next_data = self._search_nextjs_data(webpage, video_id, default='{}') |
11aa91a1 | 528 | |
135dfa2c | 529 | if next_data: |
11aa91a1 M |
530 | status = traverse_obj(next_data, ('props', 'pageProps', 'statusCode'), expected_type=int) or 0 |
531 | video_data = traverse_obj(next_data, ('props', 'pageProps', 'itemInfo', 'itemStruct'), expected_type=dict) | |
532 | else: | |
533 | sigi_json = self._search_regex( | |
534 | r'>\s*window\[[\'"]SIGI_STATE[\'"]\]\s*=\s*(?P<sigi_state>{.+});', | |
535 | webpage, 'sigi data', group='sigi_state') | |
536 | sigi_data = self._parse_json(sigi_json, video_id) | |
537 | status = traverse_obj(sigi_data, ('VideoPage', 'statusCode'), expected_type=int) or 0 | |
538 | video_data = traverse_obj(sigi_data, ('ItemModule', video_id), expected_type=dict) | |
539 | ||
1418a043 | 540 | if status == 0: |
11aa91a1 | 541 | return self._parse_aweme_video_web(video_data, url) |
1418a043 | 542 | elif status == 10216: |
543 | raise ExtractorError('This video is private', expected=True) | |
6fb11ca8 | 544 | raise ExtractorError('Video not available', video_id=video_id) |
f7f18f90 A |
545 | |
546 | ||
0fd6661e | 547 | class TikTokUserIE(TikTokBaseIE): |
f7f18f90 | 548 | IE_NAME = 'tiktok:user' |
0fd6661e | 549 | _VALID_URL = r'https?://(?:www\.)?tiktok\.com/@(?P<id>[\w\.-]+)/?(?:$|[#?])' |
f7f18f90 | 550 | _TESTS = [{ |
526d74ec | 551 | 'url': 'https://tiktok.com/@corgibobaa?lang=en', |
f7f18f90 A |
552 | 'playlist_mincount': 45, |
553 | 'info_dict': { | |
554 | 'id': '6935371178089399301', | |
0481e266 | 555 | 'title': 'corgibobaa', |
b3187433 | 556 | 'thumbnail': r're:https://.+_1080x1080\.webp' |
f7f18f90 | 557 | }, |
0481e266 | 558 | 'expected_warnings': ['Retrying'] |
5fa3c9a8 HTL |
559 | }, { |
560 | 'url': 'https://www.tiktok.com/@6820838815978423302', | |
561 | 'playlist_mincount': 5, | |
562 | 'info_dict': { | |
563 | 'id': '6820838815978423302', | |
564 | 'title': '6820838815978423302', | |
565 | 'thumbnail': r're:https://.+_1080x1080\.webp' | |
566 | }, | |
567 | 'expected_warnings': ['Retrying'] | |
f7f18f90 A |
568 | }, { |
569 | 'url': 'https://www.tiktok.com/@meme', | |
570 | 'playlist_mincount': 593, | |
571 | 'info_dict': { | |
572 | 'id': '79005827461758976', | |
0481e266 | 573 | 'title': 'meme', |
b3187433 | 574 | 'thumbnail': r're:https://.+_1080x1080\.webp' |
f7f18f90 | 575 | }, |
0481e266 | 576 | 'expected_warnings': ['Retrying'] |
f7f18f90 A |
577 | }] |
578 | ||
0fd6661e M |
579 | r''' # TODO: Fix by adding _signature to api_url |
580 | def _entries(self, webpage, user_id, username): | |
581 | secuid = self._search_regex(r'\"secUid\":\"(?P<secUid>[^\"]+)', webpage, username) | |
f7f18f90 A |
582 | verifyfp_cookie = self._get_cookies('https://www.tiktok.com').get('s_v_web_id') |
583 | if not verifyfp_cookie: | |
584 | raise ExtractorError('Improper cookies (missing s_v_web_id).', expected=True) | |
585 | api_url = f'https://m.tiktok.com/api/post/item_list/?aid=1988&cookie_enabled=true&count=30&verifyFp={verifyfp_cookie.value}&secUid={secuid}&cursor=' | |
586 | cursor = '0' | |
587 | for page in itertools.count(): | |
0fd6661e | 588 | data_json = self._download_json(api_url + cursor, username, note='Downloading Page %d' % page) |
f7f18f90 A |
589 | for video in data_json.get('itemList', []): |
590 | video_id = video['id'] | |
591 | video_url = f'https://www.tiktok.com/@{user_id}/video/{video_id}' | |
bd9ff55b | 592 | yield self._url_result(video_url, 'TikTok', video_id, str_or_none(video.get('desc'))) |
526d74ec | 593 | if not data_json.get('hasMore'): |
f7f18f90 A |
594 | break |
595 | cursor = data_json['cursor'] | |
0fd6661e M |
596 | ''' |
597 | ||
b3187433 | 598 | def _video_entries_api(self, webpage, user_id, username): |
0fd6661e M |
599 | query = { |
600 | 'user_id': user_id, | |
601 | 'count': 21, | |
602 | 'max_cursor': 0, | |
603 | 'min_cursor': 0, | |
604 | 'retry_type': 'no_retry', | |
0930b11f | 605 | 'device_id': ''.join(random.choice(string.digits) for _ in range(19)), # Some endpoints don't like randomized device_id, so it isn't directly set in _call_api. |
0fd6661e M |
606 | } |
607 | ||
608 | max_retries = self.get_param('extractor_retries', 3) | |
609 | for page in itertools.count(1): | |
610 | for retries in itertools.count(): | |
611 | try: | |
612 | post_list = self._call_api('aweme/post', query, username, | |
613 | note='Downloading user video list page %d%s' % (page, f' (attempt {retries})' if retries != 0 else ''), | |
614 | errnote='Unable to download user video list') | |
615 | except ExtractorError as e: | |
616 | if isinstance(e.cause, json.JSONDecodeError) and e.cause.pos == 0 and retries != max_retries: | |
617 | self.report_warning('%s. Retrying...' % str(e.cause or e.msg)) | |
618 | continue | |
619 | raise | |
620 | break | |
b3187433 | 621 | yield from post_list.get('aweme_list', []) |
0fd6661e M |
622 | if not post_list.get('has_more'): |
623 | break | |
624 | query['max_cursor'] = post_list['max_cursor'] | |
f7f18f90 | 625 | |
b3187433 | 626 | def _entries_api(self, user_id, videos): |
627 | for video in videos: | |
628 | yield { | |
629 | **self._parse_aweme_video_app(video), | |
630 | 'extractor_key': TikTokIE.ie_key(), | |
631 | 'extractor': 'TikTok', | |
632 | 'webpage_url': f'https://tiktok.com/@{user_id}/video/{video["aweme_id"]}', | |
633 | } | |
634 | ||
f7f18f90 | 635 | def _real_extract(self, url): |
0481e266 | 636 | user_name = self._match_id(url) |
637 | webpage = self._download_webpage(url, user_name, headers={ | |
0fd6661e M |
638 | 'User-Agent': 'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)' |
639 | }) | |
5fa3c9a8 | 640 | user_id = self._html_search_regex(r'snssdk\d*://user/profile/(\d+)', webpage, 'user ID', default=None) or user_name |
b3187433 | 641 | |
642 | videos = LazyList(self._video_entries_api(webpage, user_id, user_name)) | |
643 | thumbnail = traverse_obj(videos, (0, 'author', 'avatar_larger', 'url_list', 0)) | |
644 | ||
645 | return self.playlist_result(self._entries_api(user_id, videos), user_id, user_name, thumbnail=thumbnail) | |
943d5ab1 M |
646 | |
647 | ||
8126298c M |
648 | class TikTokBaseListIE(TikTokBaseIE): |
649 | def _entries(self, list_id, display_id): | |
650 | query = { | |
651 | self._QUERY_NAME: list_id, | |
652 | 'cursor': 0, | |
653 | 'count': 20, | |
654 | 'type': 5, | |
655 | 'device_id': ''.join(random.choice(string.digits) for i in range(19)) | |
656 | } | |
657 | ||
658 | max_retries = self.get_param('extractor_retries', 3) | |
659 | for page in itertools.count(1): | |
660 | for retries in itertools.count(): | |
661 | try: | |
662 | post_list = self._call_api(self._API_ENDPOINT, query, display_id, | |
663 | note='Downloading video list page %d%s' % (page, f' (attempt {retries})' if retries != 0 else ''), | |
664 | errnote='Unable to download video list') | |
665 | except ExtractorError as e: | |
666 | if isinstance(e.cause, json.JSONDecodeError) and e.cause.pos == 0 and retries != max_retries: | |
667 | self.report_warning('%s. Retrying...' % str(e.cause or e.msg)) | |
668 | continue | |
669 | raise | |
670 | break | |
671 | for video in post_list.get('aweme_list', []): | |
672 | yield { | |
673 | **self._parse_aweme_video_app(video), | |
0b77924a | 674 | 'extractor_key': TikTokIE.ie_key(), |
8126298c M |
675 | 'extractor': 'TikTok', |
676 | 'webpage_url': f'https://tiktok.com/@_/video/{video["aweme_id"]}', | |
677 | } | |
678 | if not post_list.get('has_more'): | |
679 | break | |
680 | query['cursor'] = post_list['cursor'] | |
681 | ||
682 | def _real_extract(self, url): | |
683 | list_id = self._match_id(url) | |
684 | return self.playlist_result(self._entries(list_id, list_id), list_id) | |
685 | ||
686 | ||
687 | class TikTokSoundIE(TikTokBaseListIE): | |
688 | IE_NAME = 'tiktok:sound' | |
689 | _VALID_URL = r'https?://(?:www\.)?tiktok\.com/music/[\w\.-]+-(?P<id>[\d]+)[/?#&]?' | |
690 | _QUERY_NAME = 'music_id' | |
691 | _API_ENDPOINT = 'music/aweme' | |
692 | _TESTS = [{ | |
693 | 'url': 'https://www.tiktok.com/music/Build-a-Btch-6956990112127585029?lang=en', | |
694 | 'playlist_mincount': 100, | |
695 | 'info_dict': { | |
696 | 'id': '6956990112127585029' | |
697 | }, | |
698 | 'expected_warnings': ['Retrying'] | |
699 | }, { | |
700 | # Actual entries are less than listed video count | |
701 | 'url': 'https://www.tiktok.com/music/jiefei-soap-remix-7036843036118469381', | |
702 | 'playlist_mincount': 2182, | |
703 | 'info_dict': { | |
704 | 'id': '7036843036118469381' | |
705 | }, | |
706 | 'expected_warnings': ['Retrying'] | |
707 | }] | |
708 | ||
709 | ||
710 | class TikTokEffectIE(TikTokBaseListIE): | |
711 | IE_NAME = 'tiktok:effect' | |
712 | _VALID_URL = r'https?://(?:www\.)?tiktok\.com/sticker/[\w\.-]+-(?P<id>[\d]+)[/?#&]?' | |
713 | _QUERY_NAME = 'sticker_id' | |
714 | _API_ENDPOINT = 'sticker/aweme' | |
715 | _TESTS = [{ | |
716 | 'url': 'https://www.tiktok.com/sticker/MATERIAL-GWOOORL-1258156', | |
717 | 'playlist_mincount': 100, | |
718 | 'info_dict': { | |
719 | 'id': '1258156', | |
720 | }, | |
721 | 'expected_warnings': ['Retrying'] | |
722 | }, { | |
723 | # Different entries between mobile and web, depending on region | |
724 | 'url': 'https://www.tiktok.com/sticker/Elf-Friend-479565', | |
725 | 'only_matching': True | |
726 | }] | |
727 | ||
728 | ||
729 | class TikTokTagIE(TikTokBaseListIE): | |
730 | IE_NAME = 'tiktok:tag' | |
731 | _VALID_URL = r'https?://(?:www\.)?tiktok\.com/tag/(?P<id>[^/?#&]+)' | |
732 | _QUERY_NAME = 'ch_id' | |
733 | _API_ENDPOINT = 'challenge/aweme' | |
734 | _TESTS = [{ | |
735 | 'url': 'https://tiktok.com/tag/hello2018', | |
736 | 'playlist_mincount': 39, | |
737 | 'info_dict': { | |
738 | 'id': '46294678', | |
739 | 'title': 'hello2018', | |
740 | }, | |
741 | 'expected_warnings': ['Retrying'] | |
742 | }, { | |
743 | 'url': 'https://tiktok.com/tag/fypシ?is_copy_url=0&is_from_webapp=v1', | |
744 | 'only_matching': True | |
745 | }] | |
746 | ||
747 | def _real_extract(self, url): | |
748 | display_id = self._match_id(url) | |
749 | webpage = self._download_webpage(url, display_id, headers={ | |
750 | 'User-Agent': 'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)' | |
751 | }) | |
752 | tag_id = self._html_search_regex(r'snssdk\d*://challenge/detail/(\d+)', webpage, 'tag ID') | |
753 | return self.playlist_result(self._entries(tag_id, display_id), tag_id, display_id) | |
754 | ||
755 | ||
943d5ab1 M |
756 | class DouyinIE(TikTokIE): |
757 | _VALID_URL = r'https?://(?:www\.)?douyin\.com/video/(?P<id>[0-9]+)' | |
758 | _TESTS = [{ | |
759 | 'url': 'https://www.douyin.com/video/6961737553342991651', | |
760 | 'md5': '10523312c8b8100f353620ac9dc8f067', | |
761 | 'info_dict': { | |
762 | 'id': '6961737553342991651', | |
763 | 'ext': 'mp4', | |
764 | 'title': '#杨超越 小小水手带你去远航❤️', | |
765 | 'uploader': '杨超越', | |
766 | 'upload_date': '20210513', | |
767 | 'timestamp': 1620905839, | |
768 | 'uploader_id': '110403406559', | |
769 | 'view_count': int, | |
770 | 'like_count': int, | |
771 | 'repost_count': int, | |
772 | 'comment_count': int, | |
773 | } | |
774 | }, { | |
775 | 'url': 'https://www.douyin.com/video/6982497745948921092', | |
776 | 'md5': 'd78408c984b9b5102904cf6b6bc2d712', | |
777 | 'info_dict': { | |
778 | 'id': '6982497745948921092', | |
779 | 'ext': 'mp4', | |
780 | 'title': '这个夏日和小羊@杨超越 一起遇见白色幻想', | |
781 | 'uploader': '杨超越工作室', | |
782 | 'upload_date': '20210708', | |
783 | 'timestamp': 1625739481, | |
784 | 'uploader_id': '408654318141572', | |
785 | 'view_count': int, | |
786 | 'like_count': int, | |
787 | 'repost_count': int, | |
788 | 'comment_count': int, | |
789 | } | |
790 | }, { | |
791 | 'url': 'https://www.douyin.com/video/6953975910773099811', | |
792 | 'md5': '72e882e24f75064c218b76c8b713c185', | |
793 | 'info_dict': { | |
794 | 'id': '6953975910773099811', | |
795 | 'ext': 'mp4', | |
796 | 'title': '#一起看海 出现在你的夏日里', | |
797 | 'uploader': '杨超越', | |
798 | 'upload_date': '20210422', | |
799 | 'timestamp': 1619098692, | |
800 | 'uploader_id': '110403406559', | |
801 | 'view_count': int, | |
802 | 'like_count': int, | |
803 | 'repost_count': int, | |
804 | 'comment_count': int, | |
805 | } | |
806 | }, { | |
807 | 'url': 'https://www.douyin.com/video/6950251282489675042', | |
808 | 'md5': 'b4db86aec367ef810ddd38b1737d2fed', | |
809 | 'info_dict': { | |
810 | 'id': '6950251282489675042', | |
811 | 'ext': 'mp4', | |
812 | 'title': '哈哈哈,成功了哈哈哈哈哈哈', | |
813 | 'uploader': '杨超越', | |
814 | 'upload_date': '20210412', | |
815 | 'timestamp': 1618231483, | |
816 | 'uploader_id': '110403406559', | |
817 | 'view_count': int, | |
818 | 'like_count': int, | |
819 | 'repost_count': int, | |
820 | 'comment_count': int, | |
821 | } | |
822 | }, { | |
823 | 'url': 'https://www.douyin.com/video/6963263655114722595', | |
824 | 'md5': '1abe1c477d05ee62efb40bf2329957cf', | |
825 | 'info_dict': { | |
826 | 'id': '6963263655114722595', | |
827 | 'ext': 'mp4', | |
828 | 'title': '#哪个爱豆的105度最甜 换个角度看看我哈哈', | |
829 | 'uploader': '杨超越', | |
830 | 'upload_date': '20210517', | |
831 | 'timestamp': 1621261163, | |
832 | 'uploader_id': '110403406559', | |
833 | 'view_count': int, | |
834 | 'like_count': int, | |
835 | 'repost_count': int, | |
836 | 'comment_count': int, | |
837 | } | |
838 | }] | |
046cab39 | 839 | _APP_VERSIONS = [('9.6.0', '960')] |
943d5ab1 M |
840 | _APP_NAME = 'aweme' |
841 | _AID = 1128 | |
842 | _API_HOSTNAME = 'aweme.snssdk.com' | |
843 | _UPLOADER_URL_FORMAT = 'https://www.douyin.com/user/%s' | |
53dad39e | 844 | _WEBPAGE_HOST = 'https://www.douyin.com/' |
943d5ab1 M |
845 | |
846 | def _real_extract(self, url): | |
847 | video_id = self._match_id(url) | |
848 | ||
849 | try: | |
850 | return self._extract_aweme_app(video_id) | |
851 | except ExtractorError as e: | |
852 | self.report_warning(f'{e}; Retrying with webpage') | |
853 | ||
854 | webpage = self._download_webpage(url, video_id) | |
855 | render_data_json = self._search_regex( | |
856 | r'<script [^>]*\bid=[\'"]RENDER_DATA[\'"][^>]*>(%7B.+%7D)</script>', | |
857 | webpage, 'render data', default=None) | |
858 | if not render_data_json: | |
859 | # TODO: Run verification challenge code to generate signature cookies | |
860 | raise ExtractorError('Fresh cookies (not necessarily logged in) are needed') | |
861 | ||
862 | render_data = self._parse_json( | |
863 | render_data_json, video_id, transform_source=compat_urllib_parse_unquote) | |
ff91cf74 | 864 | return self._parse_aweme_video_web(get_first(render_data, ('aweme', 'detail')), url) |
88afe056 | 865 | |
866 | ||
49895f06 | 867 | class TikTokVMIE(InfoExtractor): |
868 | _VALID_URL = r'https?://(?:vm|vt)\.tiktok\.com/(?P<id>\w+)' | |
88afe056 | 869 | IE_NAME = 'vm.tiktok' |
870 | ||
49895f06 | 871 | _TESTS = [{ |
872 | 'url': 'https://vm.tiktok.com/ZSe4FqkKd', | |
873 | 'info_dict': { | |
874 | 'id': '7023491746608712966', | |
875 | 'ext': 'mp4', | |
876 | 'title': 'md5:5607564db90271abbbf8294cca77eddd', | |
877 | 'description': 'md5:5607564db90271abbbf8294cca77eddd', | |
878 | 'duration': 11, | |
879 | 'upload_date': '20211026', | |
880 | 'uploader_id': '7007385080558846981', | |
881 | 'creator': 'Memes', | |
882 | 'artist': 'Memes', | |
883 | 'track': 'original sound', | |
884 | 'uploader': 'susmandem', | |
885 | 'timestamp': 1635284105, | |
886 | 'thumbnail': r're:https://.+\.webp.*', | |
887 | 'like_count': int, | |
888 | 'view_count': int, | |
889 | 'comment_count': int, | |
890 | 'repost_count': int, | |
891 | 'uploader_url': 'https://www.tiktok.com/@MS4wLjABAAAAXcNoOEOxVyBzuII_E--T0MeCrLP0ay1Sm6x_n3dluiWEoWZD0VlQOytwad4W0i0n', | |
892 | } | |
893 | }, { | |
894 | 'url': 'https://vt.tiktok.com/ZSe4FqkKd', | |
895 | 'only_matching': True, | |
896 | }] | |
897 | ||
88afe056 | 898 | def _real_extract(self, url): |
11e1c2e3 | 899 | new_url = self._request_webpage( |
900 | HEADRequest(url), self._match_id(url), headers={'User-Agent': 'facebookexternalhit/1.1'}).geturl() | |
901 | if self.suitable(new_url): # Prevent infinite loop in case redirect fails | |
902 | raise UnsupportedError(new_url) | |
903 | return self.url_result(new_url) |