[tiktok] fix extraction

This commit is contained in:
Mort Yao 2020-07-26 15:06:03 +02:00
parent 5da4245ed0
commit 80d88a1331
No known key found for this signature in database
GPG Key ID: 07DA00CB78203251
2 changed files with 29 additions and 12 deletions

View File

@ -6,15 +6,25 @@ 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) html = get_html(url, faker=True)
title = r1(r'<title.*?>(.*?)</title>', html)
video_id = r1(r'/video/(\d+)', url) or r1(r'musical\?id=(\d+)', html) data = r1(r'<script id="__NEXT_DATA__".*?>(.*?)</script>', html)
title = '%s [%s]' % (title, video_id) info = json.loads(data)
source = r1(r'<video .*?src="([^"]+)"', html) or r1(r'"contentUrl":"([^"]+)"', html) videoData = info['props']['pageProps']['videoData']
mime, ext, size = url_info(source) urls = videoData['itemInfos']['video']['urls']
videoId = videoData['itemInfos']['id']
uniqueId = videoData['authorInfos'].get('uniqueId')
nickName = videoData['authorInfos'].get('nickName')
for i, url in enumerate(urls):
title = '%s [%s]' % (nickName or uniqueId, videoId)
if len(urls) > 1:
title = '%s [%s]' % (title, i)
mime, ext, size = url_info(url)
print_info(site_info, title, mime, size) print_info(site_info, title, mime, size)
if not info_only: if not info_only:
download_urls([source], title, ext, size, output_dir, merge=merge) download_urls([url], title, ext, size, output_dir=output_dir, merge=merge)
site_info = "TikTok.com" site_info = "TikTok.com"
download = tiktok_download download = tiktok_download

View File

@ -9,7 +9,8 @@ from you_get.extractors import (
missevan, missevan,
acfun, acfun,
bilibili, bilibili,
soundcloud soundcloud,
tiktok
) )
@ -53,9 +54,15 @@ class YouGetTests(unittest.TestCase):
'https://soundcloud.com/keiny-pham/impure-bird', info_only=True 'https://soundcloud.com/keiny-pham/impure-bird', info_only=True
) )
## playlist ## playlist
soundcloud.download( #soundcloud.download(
'https://soundcloud.com/anthony-flieger/sets/cytus', info_only=True # 'https://soundcloud.com/anthony-flieger/sets/cytus', info_only=True
) #)
def tests_tiktok(self):
tiktok.download('https://www.tiktok.com/@nmb48_official/video/6850796940293164290', info_only=True)
tiktok.download('https://t.tiktok.com/i18n/share/video/6850796940293164290/', info_only=True)
tiktok.download('https://vt.tiktok.com/UGJR4R/', info_only=True)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()