2 from __future__
import unicode_literals
10 from .common
import InfoExtractor
11 from ..compat
import (
12 compat_urllib_parse_unquote
,
13 compat_urllib_parse_urlparse
28 class TikTokBaseIE(InfoExtractor
):
29 _APP_VERSION
= '20.1.0'
30 _MANIFEST_APP_VERSION
= '210'
33 _API_HOSTNAME
= 'api-h2.tiktokv.com'
34 _UPLOADER_URL_FORMAT
= 'https://www.tiktok.com/@%s'
35 _WEBPAGE_HOST
= 'https://www.tiktok.com/'
36 QUALITIES
= ('360p', '540p', '720p', '1080p')
38 def _call_api(self
, ep
, query
, video_id
, fatal
=True,
39 note
='Downloading API JSON', errnote
='Unable to download API page'):
42 'version_name': self
._APP
_VERSION
,
43 'version_code': self
._MANIFEST
_APP
_VERSION
,
44 'build_number': self
._APP
_VERSION
,
45 'manifest_version_code': self
._MANIFEST
_APP
_VERSION
,
46 'update_version_code': self
._MANIFEST
_APP
_VERSION
,
47 'openudid': ''.join(random
.choice('0123456789abcdef') for _
in range(16)),
48 'uuid': ''.join([random
.choice(string
.digits
) for _
in range(16)]),
49 '_rticket': int(time
.time() * 1000),
50 'ts': int(time
.time()),
51 'device_brand': 'Google',
52 'device_type': 'Pixel 4',
53 'device_platform': 'android',
54 'resolution': '1080*1920',
58 'carrier_region': 'US',
61 'app_name': self
._APP
_NAME
,
64 'timezone_name': 'America/New_York',
65 'timezone_offset': '-14400',
66 'channel': 'googleplay',
73 'cp': 'cbfhckdckkde1',
75 self
._set
_cookie
(self
._API
_HOSTNAME
, 'odin_tt', ''.join(random
.choice('0123456789abcdef') for _
in range(160)))
76 webpage_cookies
= self
._get
_cookies
(self
._WEBPAGE
_HOST
)
77 if webpage_cookies
.get('sid_tt'):
78 self
._set
_cookie
(self
._API
_HOSTNAME
, 'sid_tt', webpage_cookies
['sid_tt'].value
)
79 return self
._download
_json
(
80 'https://%s/aweme/v1/%s/' % (self
._API
_HOSTNAME
, ep
), video_id
=video_id
,
81 fatal
=fatal
, note
=note
, errnote
=errnote
, headers
={
82 'User-Agent': f
'com.ss.android.ugc.trill/{self._MANIFEST_APP_VERSION} (Linux; U; Android 10; en_US; Pixel 4; Build/QQ3A.200805.001; Cronet/58.0.2991.0)',
83 'Accept': 'application/json',
86 def _parse_aweme_video_app(self
, aweme_detail
):
87 aweme_id
= aweme_detail
['aweme_id']
88 video_info
= aweme_detail
['video']
90 def parse_url_key(url_key
):
91 format_id
, codec
, res
, bitrate
= self
._search
_regex
(
92 r
'v[^_]+_(?P<id>(?P<codec>[^_]+)_(?P<res>\d+p)_(?P<bitrate>\d+))', url_key
,
93 'url key', default
=(None, None, None, None), group
=('id', 'codec', 'res', 'bitrate'))
97 'format_id': format_id
,
98 'vcodec': 'h265' if codec
== 'bytevc1' else codec
,
99 'tbr': int_or_none(bitrate
, scale
=1000) or None,
100 'quality': qualities(self
.QUALITIES
)(res
),
103 known_resolutions
= {}
105 def extract_addr(addr
, add_meta
={}):
106 parsed_meta
, res
= parse_url_key(addr
.get('url_key', ''))
108 known_resolutions
.setdefault(res
, {}).setdefault('height', add_meta
.get('height'))
109 known_resolutions
[res
].setdefault('width', add_meta
.get('width'))
110 parsed_meta
.update(known_resolutions
.get(res
, {}))
111 add_meta
.setdefault('height', int_or_none(res
[:-1]))
114 'filesize': int_or_none(addr
.get('data_size')),
117 'source_preference': -2 if 'aweme/v1' in url
else -1, # Downloads from API might get blocked
118 **add_meta
, **parsed_meta
,
119 'format_note': join_nonempty(
120 add_meta
.get('format_note'), '(API)' if 'aweme/v1' in url
else None, delim
=' ')
121 } for url
in addr
.get('url_list') or []]
123 # Hack: Add direct video links first to prioritize them when removing duplicate formats
125 if video_info
.get('play_addr'):
126 formats
.extend(extract_addr(video_info
['play_addr'], {
127 'format_id': 'play_addr',
128 'format_note': 'Direct video',
129 'vcodec': 'h265' if traverse_obj(
130 video_info
, 'is_bytevc1', 'is_h265') else 'h264', # TODO: Check for "direct iOS" videos, like https://www.tiktok.com/@cookierun_dev/video/7039716639834656002
131 'width': video_info
.get('width'),
132 'height': video_info
.get('height'),
134 if video_info
.get('download_addr'):
135 formats
.extend(extract_addr(video_info
['download_addr'], {
136 'format_id': 'download_addr',
137 'format_note': 'Download video%s' % (', watermarked' if video_info
.get('has_watermark') else ''),
139 'width': video_info
.get('width'),
140 'height': video_info
.get('height'),
141 'preference': -2 if video_info
.get('has_watermark') else -1,
143 if video_info
.get('play_addr_h264'):
144 formats
.extend(extract_addr(video_info
['play_addr_h264'], {
145 'format_id': 'play_addr_h264',
146 'format_note': 'Direct video',
149 if video_info
.get('play_addr_bytevc1'):
150 formats
.extend(extract_addr(video_info
['play_addr_bytevc1'], {
151 'format_id': 'play_addr_bytevc1',
152 'format_note': 'Direct video',
156 for bitrate
in video_info
.get('bit_rate', []):
157 if bitrate
.get('play_addr'):
158 formats
.extend(extract_addr(bitrate
['play_addr'], {
159 'format_id': bitrate
.get('gear_name'),
160 'format_note': 'Playback video',
161 'tbr': try_get(bitrate
, lambda x
: x
['bit_rate'] / 1000),
162 'vcodec': 'h265' if traverse_obj(
163 bitrate
, 'is_bytevc1', 'is_h265') else 'h264',
164 'fps': bitrate
.get('FPS'),
167 self
._remove
_duplicate
_formats
(formats
)
168 auth_cookie
= self
._get
_cookies
(self
._WEBPAGE
_HOST
).get('sid_tt')
171 self
._set
_cookie
(compat_urllib_parse_urlparse(f
['url']).hostname
, 'sid_tt', auth_cookie
.value
)
172 self
._sort
_formats
(formats
, ('quality', 'codec', 'size', 'br'))
175 for cover_id
in ('cover', 'ai_dynamic_cover', 'animated_cover', 'ai_dynamic_cover_bak',
176 'origin_cover', 'dynamic_cover'):
177 cover
= video_info
.get(cover_id
)
179 for cover_url
in cover
['url_list']:
185 stats_info
= aweme_detail
.get('statistics', {})
186 author_info
= aweme_detail
.get('author', {})
187 music_info
= aweme_detail
.get('music', {})
188 user_url
= self
._UPLOADER
_URL
_FORMAT
% (traverse_obj(author_info
,
189 'sec_uid', 'id', 'uid', 'unique_id',
190 expected_type
=str_or_none
, get_all
=False))
191 labels
= traverse_obj(aweme_detail
, ('hybrid_label', ..., 'text'), expected_type
=str, default
=[])
193 contained_music_track
= traverse_obj(
194 music_info
, ('matched_song', 'title'), ('matched_pgc_sound', 'title'), expected_type
=str)
195 contained_music_author
= traverse_obj(
196 music_info
, ('matched_song', 'author'), ('matched_pgc_sound', 'author'), 'author', expected_type
=str)
198 is_generic_og_trackname
= music_info
.get('is_original_sound') and music_info
.get('title') == 'original sound - %s' % music_info
.get('owner_handle')
199 if is_generic_og_trackname
:
200 music_track
, music_author
= contained_music_track
or 'original sound', contained_music_author
202 music_track
, music_author
= music_info
.get('title'), music_info
.get('author')
206 'title': aweme_detail
['desc'],
207 'description': aweme_detail
['desc'],
208 'view_count': int_or_none(stats_info
.get('play_count')),
209 'like_count': int_or_none(stats_info
.get('digg_count')),
210 'repost_count': int_or_none(stats_info
.get('share_count')),
211 'comment_count': int_or_none(stats_info
.get('comment_count')),
212 'uploader': str_or_none(author_info
.get('unique_id')),
213 'creator': str_or_none(author_info
.get('nickname')),
214 'uploader_id': str_or_none(author_info
.get('uid')),
215 'uploader_url': user_url
,
216 'track': music_track
,
217 'album': str_or_none(music_info
.get('album')) or None,
218 'artist': music_author
,
219 'timestamp': int_or_none(aweme_detail
.get('create_time')),
221 'thumbnails': thumbnails
,
222 'duration': int_or_none(traverse_obj(video_info
, 'duration', ('download_addr', 'duration')), scale
=1000),
223 'availability': self
._availability
(
224 is_private
='Private' in labels
,
225 needs_subscription
='Friends only' in labels
,
226 is_unlisted
='Followers only' in labels
)
229 def _parse_aweme_video_web(self
, aweme_detail
, webpage_url
):
230 video_info
= aweme_detail
['video']
231 author_info
= traverse_obj(aweme_detail
, 'authorInfo', 'author', expected_type
=dict, default
={})
232 music_info
= aweme_detail
.get('music') or {}
233 stats_info
= aweme_detail
.get('stats') or {}
234 user_url
= self
._UPLOADER
_URL
_FORMAT
% (traverse_obj(author_info
,
235 'secUid', 'id', 'uid', 'uniqueId',
236 expected_type
=str_or_none
, get_all
=False)
237 or aweme_detail
.get('authorSecId'))
240 play_url
= video_info
.get('playAddr')
241 width
= video_info
.get('width')
242 height
= video_info
.get('height')
243 if isinstance(play_url
, str):
245 'url': self
._proto
_relative
_url
(play_url
),
250 elif isinstance(play_url
, list):
252 'url': self
._proto
_relative
_url
(url
),
256 } for url
in traverse_obj(play_url
, (..., 'src'), expected_type
=url_or_none
, default
=[]) if url
]
258 download_url
= url_or_none(video_info
.get('downloadAddr')) or traverse_obj(video_info
, ('download', 'url'), expected_type
=url_or_none
)
261 'format_id': 'download',
262 'url': self
._proto
_relative
_url
(download_url
),
267 self
._remove
_duplicate
_formats
(formats
)
268 self
._sort
_formats
(formats
)
271 for thumbnail_name
in ('thumbnail', 'cover', 'dynamicCover', 'originCover'):
272 if aweme_detail
.get(thumbnail_name
):
274 'url': self
._proto
_relative
_url
(aweme_detail
[thumbnail_name
]),
280 'id': traverse_obj(aweme_detail
, 'id', 'awemeId', expected_type
=str_or_none
),
281 'title': aweme_detail
.get('desc'),
282 'duration': try_get(aweme_detail
, lambda x
: x
['video']['duration'], int),
283 'view_count': int_or_none(stats_info
.get('playCount')),
284 'like_count': int_or_none(stats_info
.get('diggCount')),
285 'repost_count': int_or_none(stats_info
.get('shareCount')),
286 'comment_count': int_or_none(stats_info
.get('commentCount')),
287 'timestamp': int_or_none(aweme_detail
.get('createTime')),
288 'creator': str_or_none(author_info
.get('nickname')),
289 'uploader': str_or_none(author_info
.get('uniqueId') or aweme_detail
.get('author')),
290 'uploader_id': str_or_none(author_info
.get('id') or aweme_detail
.get('authorId')),
291 'uploader_url': user_url
,
292 'track': str_or_none(music_info
.get('title')),
293 'album': str_or_none(music_info
.get('album')) or None,
294 'artist': str_or_none(music_info
.get('authorName')),
296 'thumbnails': thumbnails
,
297 'description': str_or_none(aweme_detail
.get('desc')),
299 'Referer': webpage_url
304 class TikTokIE(TikTokBaseIE
):
305 _VALID_URL
= r
'https?://www\.tiktok\.com/@[\w\.-]+/video/(?P<id>\d+)'
308 'url': 'https://www.tiktok.com/@leenabhushan/video/6748451240264420610',
309 'md5': '736bb7a466c6f0a6afeb597da1e6f5b7',
311 'id': '6748451240264420610',
313 'title': '#jassmanak #lehanga #leenabhushan',
314 'description': '#jassmanak #lehanga #leenabhushan',
318 'uploader': 'leenabhushan',
319 'uploader_id': '6691488002098119685',
320 'uploader_url': 'https://www.tiktok.com/@MS4wLjABAAAA_Eb4t1vodM1IuTy_cvp9CY22RAb59xqrO0Xtz9CYQJvgXaDvZxYnZYRzDWhhgJmy',
321 'creator': 'facestoriesbyleenabh',
322 'thumbnail': r
're:^https?://[\w\/\.\-]+(~[\w\-]+\.image)?',
323 'upload_date': '20191016',
324 'timestamp': 1571246252,
328 'comment_count': int,
331 'url': 'https://www.tiktok.com/@patroxofficial/video/6742501081818877190?langCountry=en',
332 'md5': '6f3cf8cdd9b28cb8363fe0a9a160695b',
334 'id': '6742501081818877190',
336 'title': 'md5:5e2a23877420bb85ce6521dbee39ba94',
337 'description': 'md5:5e2a23877420bb85ce6521dbee39ba94',
341 'uploader': 'patrox',
342 'uploader_id': '18702747',
343 'uploader_url': 'https://www.tiktok.com/@MS4wLjABAAAAiFnldaILebi5heDoVU6bn4jBWWycX6-9U3xuNPqZ8Ws',
345 'thumbnail': r
're:^https?://[\w\/\.\-]+(~[\w\-]+\.image)?',
346 'upload_date': '20190930',
347 'timestamp': 1569860870,
351 'comment_count': int,
354 # Banned audio, only available on the app
355 'url': 'https://www.tiktok.com/@barudakhb_/video/6984138651336838402',
357 'id': '6984138651336838402',
359 'title': 'Balas @yolaaftwsr hayu yu ? #SquadRandom_ 🔥',
360 'description': 'Balas @yolaaftwsr hayu yu ? #SquadRandom_ 🔥',
361 'uploader': 'barudakhb_',
362 'creator': 'md5:29f238c49bc0c176cb3cef1a9cea9fa6',
363 'uploader_id': '6974687867511718913',
364 'uploader_url': 'https://www.tiktok.com/@MS4wLjABAAAAbhBwQC-R1iKoix6jDFsF-vBdfx2ABoDjaZrM9fX6arU3w71q3cOWgWuTXn1soZ7d',
365 'track': 'Boka Dance',
366 'artist': 'md5:29f238c49bc0c176cb3cef1a9cea9fa6',
367 'timestamp': 1626121503,
369 'thumbnail': r
're:^https?://[\w\/\.\-]+(~[\w\-]+\.image)?',
370 'upload_date': '20210712',
374 'comment_count': int,
377 # Sponsored video, only available with feed workaround
378 'url': 'https://www.tiktok.com/@MS4wLjABAAAATh8Vewkn0LYM7Fo03iec3qKdeCUOcBIouRk1mkiag6h3o_pQu_dUXvZ2EZlGST7_/video/7042692929109986561',
380 'id': '7042692929109986561',
382 'title': 'Slap and Run!',
383 'description': 'Slap and Run!',
384 'uploader': 'user440922249',
385 'creator': 'Slap And Run',
386 'uploader_id': '7036055384943690754',
387 'uploader_url': 'https://www.tiktok.com/@MS4wLjABAAAATh8Vewkn0LYM7Fo03iec3qKdeCUOcBIouRk1mkiag6h3o_pQu_dUXvZ2EZlGST7_',
388 'track': 'Promoted Music',
389 'timestamp': 1639754738,
391 'thumbnail': r
're:^https?://[\w\/\.\-]+(~[\w\-]+\.image)?',
392 'upload_date': '20211217',
396 'comment_count': int,
398 'expected_warnings': ['Video not available']
401 def _extract_aweme_app(self
, aweme_id
):
403 aweme_detail
= self
._call
_api
('aweme/detail', {'aweme_id': aweme_id}
, aweme_id
,
404 note
='Downloading video details', errnote
='Unable to download video details').get('aweme_detail')
406 raise ExtractorError('Video not available', video_id
=aweme_id
)
407 except ExtractorError
as e
:
408 self
.report_warning(f
'{e}; Retrying with feed workaround')
409 feed_list
= self
._call
_api
('feed', {'aweme_id': aweme_id}
, aweme_id
,
410 note
='Downloading video feed', errnote
='Unable to download video feed').get('aweme_list') or []
411 aweme_detail
= next((aweme
for aweme
in feed_list
if str(aweme
.get('aweme_id')) == aweme_id
), None)
413 raise ExtractorError('Unable to find video in feed', video_id
=aweme_id
)
414 return self
._parse
_aweme
_video
_app
(aweme_detail
)
416 def _real_extract(self
, url
):
417 video_id
= self
._match
_id
(url
)
420 return self
._extract
_aweme
_app
(video_id
)
421 except ExtractorError
as e
:
422 self
.report_warning(f
'{e}; Retrying with webpage')
424 # If we only call once, we get a 403 when downlaoding the video.
425 self
._download
_webpage
(url
, video_id
)
426 webpage
= self
._download
_webpage
(url
, video_id
, note
='Downloading video webpage')
427 next_json
= self
._search
_regex
(
428 r
'id=\"__NEXT_DATA__\"\s+type=\"application\/json\"\s*[^>]+>\s*(?P<next_data>[^<]+)',
429 webpage
, 'next data', group
='next_data', default
=None)
432 next_data
= self
._parse
_json
(next_json
, video_id
)
433 status
= traverse_obj(next_data
, ('props', 'pageProps', 'statusCode'), expected_type
=int) or 0
434 video_data
= traverse_obj(next_data
, ('props', 'pageProps', 'itemInfo', 'itemStruct'), expected_type
=dict)
436 sigi_json
= self
._search
_regex
(
437 r
'>\s*window\[[\'"]SIGI_STATE[\'"]\
]\s
*=\s
*(?P
<sigi_state
>{.+}
);',
438 webpage, 'sigi data
', group='sigi_state
')
439 sigi_data = self._parse_json(sigi_json, video_id)
440 status = traverse_obj(sigi_data, ('VideoPage
', 'statusCode
'), expected_type=int) or 0
441 video_data = traverse_obj(sigi_data, ('ItemModule
', video_id), expected_type=dict)
444 return self._parse_aweme_video_web(video_data, url)
445 elif status == 10216:
446 raise ExtractorError('This video
is private
', expected=True)
447 raise ExtractorError('Video
not available
', video_id=video_id)
450 class TikTokUserIE(TikTokBaseIE):
451 IE_NAME = 'tiktok
:user
'
452 _VALID_URL = r'https?
://(?
:www\
.)?tiktok\
.com
/@(?P
<id>[\w\
.-]+)/?
(?
:$|
[#?])'
454 'url': 'https://tiktok.com/@corgibobaa?lang=en',
455 'playlist_mincount': 45,
457 'id': '6935371178089399301',
458 'title': 'corgibobaa',
459 'thumbnail': r
're:https://.+_1080x1080\.webp'
461 'expected_warnings': ['Retrying']
463 'url': 'https://www.tiktok.com/@meme',
464 'playlist_mincount': 593,
466 'id': '79005827461758976',
468 'thumbnail': r
're:https://.+_1080x1080\.webp'
470 'expected_warnings': ['Retrying']
473 r
''' # TODO: Fix by adding _signature to api_url
474 def _entries(self, webpage, user_id, username):
475 secuid = self._search_regex(r'\"secUid\":\"(?P<secUid>[^\"]+)', webpage, username)
476 verifyfp_cookie = self._get_cookies('https://www.tiktok.com').get('s_v_web_id')
477 if not verifyfp_cookie:
478 raise ExtractorError('Improper cookies (missing s_v_web_id).', expected=True)
479 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='
481 for page in itertools.count():
482 data_json = self._download_json(api_url + cursor, username, note='Downloading Page %d' % page)
483 for video in data_json.get('itemList', []):
484 video_id = video['id']
485 video_url = f'https://www.tiktok.com/@{user_id}/video/{video_id}'
486 yield self._url_result(video_url, 'TikTok', video_id, str_or_none(video.get('desc')))
487 if not data_json.get('hasMore'):
489 cursor = data_json['cursor']
492 def _video_entries_api(self
, webpage
, user_id
, username
):
498 'retry_type': 'no_retry',
499 '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.
502 max_retries
= self
.get_param('extractor_retries', 3)
503 for page
in itertools
.count(1):
504 for retries
in itertools
.count():
506 post_list
= self
._call
_api
('aweme/post', query
, username
,
507 note
='Downloading user video list page %d%s' % (page
, f
' (attempt {retries})' if retries
!= 0 else ''),
508 errnote
='Unable to download user video list')
509 except ExtractorError
as e
:
510 if isinstance(e
.cause
, json
.JSONDecodeError
) and e
.cause
.pos
== 0 and retries
!= max_retries
:
511 self
.report_warning('%s. Retrying...' % str(e
.cause
or e
.msg
))
515 yield from post_list
.get('aweme_list', [])
516 if not post_list
.get('has_more'):
518 query
['max_cursor'] = post_list
['max_cursor']
520 def _entries_api(self
, user_id
, videos
):
523 **self
._parse
_aweme
_video
_app
(video
),
524 'extractor_key': TikTokIE
.ie_key(),
525 'extractor': 'TikTok',
526 'webpage_url': f
'https://tiktok.com/@{user_id}/video/{video["aweme_id"]}',
529 def _real_extract(self
, url
):
530 user_name
= self
._match
_id
(url
)
531 webpage
= self
._download
_webpage
(url
, user_name
, headers
={
532 'User-Agent': 'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)'
534 user_id
= self
._html
_search
_regex
(r
'snssdk\d*://user/profile/(\d+)', webpage
, 'user ID')
536 videos
= LazyList(self
._video
_entries
_api
(webpage
, user_id
, user_name
))
537 thumbnail
= traverse_obj(videos
, (0, 'author', 'avatar_larger', 'url_list', 0))
539 return self
.playlist_result(self
._entries
_api
(user_id
, videos
), user_id
, user_name
, thumbnail
=thumbnail
)
542 class TikTokBaseListIE(TikTokBaseIE
):
543 def _entries(self
, list_id
, display_id
):
545 self
._QUERY
_NAME
: list_id
,
549 'device_id': ''.join(random
.choice(string
.digits
) for i
in range(19))
552 max_retries
= self
.get_param('extractor_retries', 3)
553 for page
in itertools
.count(1):
554 for retries
in itertools
.count():
556 post_list
= self
._call
_api
(self
._API
_ENDPOINT
, query
, display_id
,
557 note
='Downloading video list page %d%s' % (page
, f
' (attempt {retries})' if retries
!= 0 else ''),
558 errnote
='Unable to download video list')
559 except ExtractorError
as e
:
560 if isinstance(e
.cause
, json
.JSONDecodeError
) and e
.cause
.pos
== 0 and retries
!= max_retries
:
561 self
.report_warning('%s. Retrying...' % str(e
.cause
or e
.msg
))
565 for video
in post_list
.get('aweme_list', []):
567 **self
._parse
_aweme
_video
_app
(video
),
568 'extractor_key': TikTokIE
.ie_key(),
569 'extractor': 'TikTok',
570 'webpage_url': f
'https://tiktok.com/@_/video/{video["aweme_id"]}',
572 if not post_list
.get('has_more'):
574 query
['cursor'] = post_list
['cursor']
576 def _real_extract(self
, url
):
577 list_id
= self
._match
_id
(url
)
578 return self
.playlist_result(self
._entries
(list_id
, list_id
), list_id
)
581 class TikTokSoundIE(TikTokBaseListIE
):
582 IE_NAME
= 'tiktok:sound'
583 _VALID_URL
= r
'https?://(?:www\.)?tiktok\.com/music/[\w\.-]+-(?P<id>[\d]+)[/?#&]?'
584 _QUERY_NAME
= 'music_id'
585 _API_ENDPOINT
= 'music/aweme'
587 'url': 'https://www.tiktok.com/music/Build-a-Btch-6956990112127585029?lang=en',
588 'playlist_mincount': 100,
590 'id': '6956990112127585029'
592 'expected_warnings': ['Retrying']
594 # Actual entries are less than listed video count
595 'url': 'https://www.tiktok.com/music/jiefei-soap-remix-7036843036118469381',
596 'playlist_mincount': 2182,
598 'id': '7036843036118469381'
600 'expected_warnings': ['Retrying']
604 class TikTokEffectIE(TikTokBaseListIE
):
605 IE_NAME
= 'tiktok:effect'
606 _VALID_URL
= r
'https?://(?:www\.)?tiktok\.com/sticker/[\w\.-]+-(?P<id>[\d]+)[/?#&]?'
607 _QUERY_NAME
= 'sticker_id'
608 _API_ENDPOINT
= 'sticker/aweme'
610 'url': 'https://www.tiktok.com/sticker/MATERIAL-GWOOORL-1258156',
611 'playlist_mincount': 100,
615 'expected_warnings': ['Retrying']
617 # Different entries between mobile and web, depending on region
618 'url': 'https://www.tiktok.com/sticker/Elf-Friend-479565',
619 'only_matching': True
623 class TikTokTagIE(TikTokBaseListIE
):
624 IE_NAME
= 'tiktok:tag'
625 _VALID_URL
= r
'https?://(?:www\.)?tiktok\.com/tag/(?P<id>[^/?#&]+)'
626 _QUERY_NAME
= 'ch_id'
627 _API_ENDPOINT
= 'challenge/aweme'
629 'url': 'https://tiktok.com/tag/hello2018',
630 'playlist_mincount': 39,
633 'title': 'hello2018',
635 'expected_warnings': ['Retrying']
637 'url': 'https://tiktok.com/tag/fypシ?is_copy_url=0&is_from_webapp=v1',
638 'only_matching': True
641 def _real_extract(self
, url
):
642 display_id
= self
._match
_id
(url
)
643 webpage
= self
._download
_webpage
(url
, display_id
, headers
={
644 'User-Agent': 'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)'
646 tag_id
= self
._html
_search
_regex
(r
'snssdk\d*://challenge/detail/(\d+)', webpage
, 'tag ID')
647 return self
.playlist_result(self
._entries
(tag_id
, display_id
), tag_id
, display_id
)
650 class DouyinIE(TikTokIE
):
651 _VALID_URL
= r
'https?://(?:www\.)?douyin\.com/video/(?P<id>[0-9]+)'
653 'url': 'https://www.douyin.com/video/6961737553342991651',
654 'md5': '10523312c8b8100f353620ac9dc8f067',
656 'id': '6961737553342991651',
658 'title': '#杨超越 小小水手带你去远航❤️',
660 'upload_date': '20210513',
661 'timestamp': 1620905839,
662 'uploader_id': '110403406559',
666 'comment_count': int,
669 'url': 'https://www.douyin.com/video/6982497745948921092',
670 'md5': 'd78408c984b9b5102904cf6b6bc2d712',
672 'id': '6982497745948921092',
674 'title': '这个夏日和小羊@杨超越 一起遇见白色幻想',
675 'uploader': '杨超越工作室',
676 'upload_date': '20210708',
677 'timestamp': 1625739481,
678 'uploader_id': '408654318141572',
682 'comment_count': int,
685 'url': 'https://www.douyin.com/video/6953975910773099811',
686 'md5': '72e882e24f75064c218b76c8b713c185',
688 'id': '6953975910773099811',
690 'title': '#一起看海 出现在你的夏日里',
692 'upload_date': '20210422',
693 'timestamp': 1619098692,
694 'uploader_id': '110403406559',
698 'comment_count': int,
701 'url': 'https://www.douyin.com/video/6950251282489675042',
702 'md5': 'b4db86aec367ef810ddd38b1737d2fed',
704 'id': '6950251282489675042',
706 'title': '哈哈哈,成功了哈哈哈哈哈哈',
708 'upload_date': '20210412',
709 'timestamp': 1618231483,
710 'uploader_id': '110403406559',
714 'comment_count': int,
717 'url': 'https://www.douyin.com/video/6963263655114722595',
718 'md5': '1abe1c477d05ee62efb40bf2329957cf',
720 'id': '6963263655114722595',
722 'title': '#哪个爱豆的105度最甜 换个角度看看我哈哈',
724 'upload_date': '20210517',
725 'timestamp': 1621261163,
726 'uploader_id': '110403406559',
730 'comment_count': int,
733 _APP_VERSION
= '9.6.0'
734 _MANIFEST_APP_VERSION
= '960'
737 _API_HOSTNAME
= 'aweme.snssdk.com'
738 _UPLOADER_URL_FORMAT
= 'https://www.douyin.com/user/%s'
739 _WEBPAGE_HOST
= 'https://www.douyin.com/'
741 def _real_extract(self
, url
):
742 video_id
= self
._match
_id
(url
)
745 return self
._extract
_aweme
_app
(video_id
)
746 except ExtractorError
as e
:
747 self
.report_warning(f
'{e}; Retrying with webpage')
749 webpage
= self
._download
_webpage
(url
, video_id
)
750 render_data_json
= self
._search
_regex
(
751 r
'<script [^>]*\bid=[\'"]RENDER_DATA[\'"][^
>]*>(%7B
.+%7D
)</script
>',
752 webpage, 'render data
', default=None)
753 if not render_data_json:
754 # TODO: Run verification challenge code to generate signature cookies
755 raise ExtractorError('Fresh
cookies (not necessarily logged
in) are needed
')
757 render_data = self._parse_json(
758 render_data_json, video_id, transform_source=compat_urllib_parse_unquote)
759 return self._parse_aweme_video_web(
760 traverse_obj(render_data, (..., 'aweme
', 'detail
'), get_all=False), url)