Russell-Newton / TikTokPy

Extract data from TikTok without needing any login information or API keys.
https://pypi.org/project/tiktokapipy/
MIT License
213 stars 28 forks source link

[BUG] can't get video info through shared link (vm.tiktok.com)only with link copied directly through browser (tiktok.com) #61

Closed Albert-Bruun-Thomsen closed 1 year ago

Albert-Bruun-Thomsen commented 1 year ago

Describe the bug can't get video info through shared link (vm.tiktok.com)only with link copied directly through browser (tiktok.com)

To Reproduce Steps to reproduce the behavior: writing

with TikTokAPI() as api:
    video = api.video("https://www.tiktok.com/@giaitrihaihuoc23/video/7248572478757391643?_r=1&_t=8eGXRQForn9")

does as you would expect and gets the video info however doing it through a link shared through the app like this:

with TikTokAPI() as api:
    video = api.video("https://vm.tiktok.com/ZGJq2Yobp/")

throws these errors:

Traceback (most recent call last):
  File "C:\Users\alber\PycharmProjects\TiktokToShorts\bot.py", line 22, in <module>
    video = api.video(video_url)
  File "C:\Users\alber\PycharmProjects\TiktokToShorts\venv\lib\site-packages\tiktokapipy\api.py", line 171, in video
    return self._extract_video_from_response(response)
  File "C:\Users\alber\PycharmProjects\TiktokToShorts\venv\lib\site-packages\tiktokapipy\api.py", line 297, in _extract_video_from_response
    raise TikTokAPIError(
tiktokapipy.TikTokAPIError: Error in video extraction: status code 10201 (Unknown Error)
Process finished with exit code 1

Version Information pydantic 2.0.4 playwright 1.36.0 tiktokapipy 0.2.1

System Information win11, pycharm, latest python version

Region Information Located in denmark

Russell-Newton commented 1 year ago

Seems to be a duplicate of #58. After looking closer, the issue is definitely on my end with a change I made in 0.2.0 to how video extraction works. I'll resolve this shortly.

Russell-Newton commented 1 year ago

This error should (hopefully) be fixed in version 0.2.2. It seems that the issue was actually related to a change I made to video extraction in 0.2.0. It looks for the video ID in the video URL, which is possible with a desktop URL, but the mobile app share links are shortened and don't contain that information.

Albert-Bruun-Thomsen commented 1 year ago

Perfect it's working with both links now thanks for the quick solution