[tiktok] support short URLs (vt.tiktok.com)

This commit is contained in:
Mort Yao 2024-08-02 20:20:53 +02:00
parent 79aaec4317
commit bc0e680ed5
No known key found for this signature in database
GPG Key ID: 07DA00CB78203251
2 changed files with 7 additions and 3 deletions

View File

@ -16,6 +16,8 @@ def tiktok_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
m = re.match('(https?://)?([^/]+)(/.*)', url) m = re.match('(https?://)?([^/]+)(/.*)', url)
host = m.group(2) host = m.group(2)
if host != 'www.tiktok.com': # non-canonical URL if host != 'www.tiktok.com': # non-canonical URL
if host == 'vt.tiktok.com': # short URL
url = get_location(url)
vid = r1(r'/video/(\d+)', url) vid = r1(r'/video/(\d+)', url)
url = 'https://www.tiktok.com/@/video/%s/' % vid url = 'https://www.tiktok.com/@/video/%s/' % vid
host = 'www.tiktok.com' host = 'www.tiktok.com'

View File

@ -57,12 +57,14 @@ class YouGetTests(unittest.TestCase):
#) #)
def test_tiktok(self): def test_tiktok(self):
tiktok.download('https://www.tiktok.com/@nmb48_official/video/6850796940293164290', info_only=True) tiktok.download('https://www.tiktok.com/@zukky_48/video/7398162058153315605', info_only=True)
tiktok.download('https://www.tiktok.com/@/video/6850796940293164290', info_only=True) tiktok.download('https://www.tiktok.com/@/video/7398162058153315605', info_only=True)
tiktok.download('https://t.tiktok.com/i18n/share/video/6850796940293164290/', info_only=True) tiktok.download('https://t.tiktok.com/i18n/share/video/7398162058153315605/', info_only=True)
tiktok.download('https://vt.tiktok.com/ZSYKjKt6M/', info_only=True)
def test_twitter(self): def test_twitter(self):
twitter.download('https://twitter.com/elonmusk/status/1530516552084234244', info_only=True) twitter.download('https://twitter.com/elonmusk/status/1530516552084234244', info_only=True)
twitter.download('https://x.com/elonmusk/status/1530516552084234244', info_only=True)
def test_weibo(self): def test_weibo(self):
miaopai.download('https://video.weibo.com/show?fid=1034:4825403706245135', info_only=True) miaopai.download('https://video.weibo.com/show?fid=1034:4825403706245135', info_only=True)