mirror of
https://github.com/blackjack4494/yt-dlc.git
synced 2024-11-09 04:22:41 +01:00
Merge branch 'merval-merval/fix_tiktok'
This commit is contained in:
commit
ff3c7af428
@ -12,19 +12,20 @@ from ..utils import (
|
|||||||
|
|
||||||
|
|
||||||
class TikTokBaseIE(InfoExtractor):
|
class TikTokBaseIE(InfoExtractor):
|
||||||
def _extract_aweme(self, video_data, webpage, url):
|
def _extract_aweme(self, props_data, webpage, url):
|
||||||
|
video_data = try_get(props_data, lambda x: x['pageProps'], expected_type=dict)
|
||||||
video_info = try_get(
|
video_info = try_get(
|
||||||
video_data, lambda x: x['videoData']['itemInfos'], dict)
|
video_data, lambda x: x['itemInfo']['itemStruct'], dict)
|
||||||
author_info = try_get(
|
author_info = try_get(
|
||||||
video_data, lambda x: x['videoData']['authorInfos'], dict)
|
video_data, lambda x: x['itemInfo']['itemStruct']['author'], dict)
|
||||||
share_info = try_get(video_data, lambda x: x['shareMeta'], dict)
|
share_info = try_get(video_data, lambda x: x['itemInfo']['shareMeta'], dict)
|
||||||
|
|
||||||
unique_id = str_or_none(author_info.get('uniqueId'))
|
unique_id = str_or_none(author_info.get('uniqueId'))
|
||||||
timestamp = try_get(video_info, lambda x: int(x['createTime']), int)
|
timestamp = try_get(video_info, lambda x: int(x['createTime']), int)
|
||||||
date = datetime.fromtimestamp(timestamp).strftime('%Y%m%d')
|
date = datetime.fromtimestamp(timestamp).strftime('%Y%m%d')
|
||||||
|
|
||||||
height = try_get(video_info, lambda x: x['video']['videoMeta']['height'], int)
|
height = try_get(video_info, lambda x: x['video']['height'], int)
|
||||||
width = try_get(video_info, lambda x: x['video']['videoMeta']['width'], int)
|
width = try_get(video_info, lambda x: x['video']['width'], int)
|
||||||
thumbnails = []
|
thumbnails = []
|
||||||
thumbnails.append({
|
thumbnails.append({
|
||||||
'url': video_info.get('thumbnail') or self._og_search_thumbnail(webpage),
|
'url': video_info.get('thumbnail') or self._og_search_thumbnail(webpage),
|
||||||
@ -32,14 +33,20 @@ class TikTokBaseIE(InfoExtractor):
|
|||||||
'height': height
|
'height': height
|
||||||
})
|
})
|
||||||
|
|
||||||
|
url = ''
|
||||||
|
if not url:
|
||||||
|
url = try_get(video_info, lambda x: x['video']['playAddr'])
|
||||||
|
if not url:
|
||||||
|
url = try_get(video_info, lambda x: x['video']['downloadAddr'])
|
||||||
formats = []
|
formats = []
|
||||||
formats.append({
|
formats.append({
|
||||||
'url': try_get(video_info, lambda x: x['video']['urls'][0]),
|
'url': url,
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'height': height,
|
'height': height,
|
||||||
'width': width
|
'width': width
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tracker = try_get(props_data, lambda x: x['initialProps']['$wid'])
|
||||||
return {
|
return {
|
||||||
'comment_count': int_or_none(video_info.get('commentCount')),
|
'comment_count': int_or_none(video_info.get('commentCount')),
|
||||||
'duration': try_get(video_info, lambda x: x['video']['videoMeta']['duration'], int),
|
'duration': try_get(video_info, lambda x: x['video']['videoMeta']['duration'], int),
|
||||||
@ -63,6 +70,7 @@ class TikTokBaseIE(InfoExtractor):
|
|||||||
'formats': formats,
|
'formats': formats,
|
||||||
'http_headers': {
|
'http_headers': {
|
||||||
'Referer': url,
|
'Referer': url,
|
||||||
|
'Cookie': 'tt_webid=%s; tt_webid_v2=%s' % (tracker, tracker),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,10 +138,10 @@ class TikTokIE(TikTokBaseIE):
|
|||||||
r'id=\"__NEXT_DATA__\"\s+type=\"application\/json\"\s*[^>]+>\s*(?P<json_string_ld>[^<]+)',
|
r'id=\"__NEXT_DATA__\"\s+type=\"application\/json\"\s*[^>]+>\s*(?P<json_string_ld>[^<]+)',
|
||||||
webpage, 'json_string', group='json_string_ld')
|
webpage, 'json_string', group='json_string_ld')
|
||||||
json_data = self._parse_json(json_string, video_id)
|
json_data = self._parse_json(json_string, video_id)
|
||||||
video_data = try_get(json_data, lambda x: x['props']['pageProps'], expected_type=dict)
|
props_data = try_get(json_data, lambda x: x['props'], expected_type=dict)
|
||||||
|
|
||||||
# Chech statusCode for success
|
# Chech statusCode for success
|
||||||
if video_data.get('statusCode') == 0:
|
if props_data.get('pageProps').get('statusCode') == 0:
|
||||||
return self._extract_aweme(video_data, webpage, url)
|
return self._extract_aweme(props_data, webpage, url)
|
||||||
|
|
||||||
raise ExtractorError('Video not available', video_id=video_id)
|
raise ExtractorError('Video not available', video_id=video_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user