mirror of
https://github.com/soimort/you-get.git
synced 2025-02-03 00:33:58 +03:00
[tiktok] fix extraction
This commit is contained in:
parent
c271363585
commit
5d59f76a41
@ -5,26 +5,42 @@ __all__ = ['tiktok_download']
|
|||||||
from ..common import *
|
from ..common import *
|
||||||
|
|
||||||
def tiktok_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
|
def tiktok_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
|
||||||
html = get_html(url, faker=True)
|
referUrl = url.split('?')[0]
|
||||||
|
headers = fake_headers
|
||||||
|
|
||||||
|
# trick or treat
|
||||||
|
html = get_content(url, headers=headers)
|
||||||
data = r1(r'<script id="__NEXT_DATA__".*?>(.*?)</script>', html)
|
data = r1(r'<script id="__NEXT_DATA__".*?>(.*?)</script>', html)
|
||||||
info = json.loads(data)
|
info = json.loads(data)
|
||||||
videoData = info['props']['pageProps']['videoData']
|
wid = info['props']['initialProps']['$wid']
|
||||||
urls = videoData['itemInfos']['video']['urls']
|
cookie = 'tt_webid=%s; tt_webid_v2=%s' % (wid, wid)
|
||||||
videoId = videoData['itemInfos']['id']
|
|
||||||
uniqueId = videoData['authorInfos'].get('uniqueId')
|
|
||||||
nickName = videoData['authorInfos'].get('nickName')
|
|
||||||
|
|
||||||
for i, videoUrl in enumerate(urls):
|
# here's the cookie
|
||||||
title = '%s [%s]' % (nickName or uniqueId, videoId)
|
headers['Cookie'] = cookie
|
||||||
if len(urls) > 1:
|
|
||||||
title = '%s [%s]' % (title, i)
|
|
||||||
|
|
||||||
mime, ext, size = url_info(videoUrl, headers={'Referer': url})
|
# try again
|
||||||
|
html = get_content(url, headers=headers)
|
||||||
|
data = r1(r'<script id="__NEXT_DATA__".*?>(.*?)</script>', html)
|
||||||
|
info = json.loads(data)
|
||||||
|
wid = info['props']['initialProps']['$wid']
|
||||||
|
cookie = 'tt_webid=%s; tt_webid_v2=%s' % (wid, wid)
|
||||||
|
|
||||||
print_info(site_info, title, mime, size)
|
videoData = info['props']['pageProps']['itemInfo']['itemStruct']
|
||||||
if not info_only:
|
videoId = videoData['id']
|
||||||
download_urls([videoUrl], title, ext, size, output_dir=output_dir, merge=merge, headers={'Referer': url})
|
videoUrl = videoData['video']['downloadAddr']
|
||||||
|
uniqueId = videoData['author'].get('uniqueId')
|
||||||
|
nickName = videoData['author'].get('nickname')
|
||||||
|
|
||||||
|
title = '%s [%s]' % (nickName or uniqueId, videoId)
|
||||||
|
|
||||||
|
# we also need the referer
|
||||||
|
headers['Referer'] = referUrl
|
||||||
|
|
||||||
|
mime, ext, size = url_info(videoUrl, headers=headers)
|
||||||
|
|
||||||
|
print_info(site_info, title, mime, size)
|
||||||
|
if not info_only:
|
||||||
|
download_urls([videoUrl], title, ext, size, output_dir=output_dir, merge=merge, headers=headers)
|
||||||
|
|
||||||
site_info = "TikTok.com"
|
site_info = "TikTok.com"
|
||||||
download = tiktok_download
|
download = tiktok_download
|
||||||
|
Loading…
Reference in New Issue
Block a user