mirror of
https://github.com/soimort/you-get.git
synced 2025-01-23 13:35:16 +03:00
[tiktok] fix extraction
This commit is contained in:
parent
5da4245ed0
commit
80d88a1331
@ -6,15 +6,25 @@ from ..common import *
|
||||
|
||||
def tiktok_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
|
||||
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)
|
||||
title = '%s [%s]' % (title, video_id)
|
||||
source = r1(r'<video .*?src="([^"]+)"', html) or r1(r'"contentUrl":"([^"]+)"', html)
|
||||
mime, ext, size = url_info(source)
|
||||
|
||||
data = r1(r'<script id="__NEXT_DATA__".*?>(.*?)</script>', html)
|
||||
info = json.loads(data)
|
||||
videoData = info['props']['pageProps']['videoData']
|
||||
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)
|
||||
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"
|
||||
download = tiktok_download
|
||||
|
@ -9,7 +9,8 @@ from you_get.extractors import (
|
||||
missevan,
|
||||
acfun,
|
||||
bilibili,
|
||||
soundcloud
|
||||
soundcloud,
|
||||
tiktok
|
||||
)
|
||||
|
||||
|
||||
@ -53,9 +54,15 @@ class YouGetTests(unittest.TestCase):
|
||||
'https://soundcloud.com/keiny-pham/impure-bird', info_only=True
|
||||
)
|
||||
## playlist
|
||||
soundcloud.download(
|
||||
'https://soundcloud.com/anthony-flieger/sets/cytus', info_only=True
|
||||
)
|
||||
#soundcloud.download(
|
||||
# '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__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user