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