Russell-Newton / TikTokPy

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

Change type of SubtitleData.format field to str #86

Open amadejkastelic opened 4 months ago

amadejkastelic commented 4 months ago

SubtitleData.format field can also be a string. Here is one such example:

video-embed-bot_1  | 2024-07-04 22:04:07,035 ERROR Failed downloading https://vm.tiktok.com/ZGesWbcYj/: 1 validation error for VideoPage
video-embed-bot_1  | itemInfo.itemStruct.video.subtitleInfos.0.Version
video-embed-bot_1  |   Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value='1:whisper_lid', input_type=str]
video-embed-bot_1  |     For further information visit https://errors.pydantic.dev/2.7/v/int_parsing
video-embed-bot_1  | 2024-07-04 22:04:07,534 ERROR Ignoring exception in on_message
video-embed-bot_1  | Traceback (most recent call last):
video-embed-bot_1  |   File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.12/site-packages/discord/client.py", line 449, in _run_event
video-embed-bot_1  |     await coro(*args, **kwargs)
video-embed-bot_1  |   File "/app/bots/discord/client.py", line 73, in on_message
video-embed-bot_1  |     raise e
video-embed-bot_1  |   File "/app/bots/discord/client.py", line 66, in on_message
video-embed-bot_1  |     post = await client.get_post()
video-embed-bot_1  |            ^^^^^^^^^^^^^^^^^^^^^^^
video-embed-bot_1  |   File "/app/downloader/tiktok.py", line 31, in get_post
video-embed-bot_1  |     video = await api.video(clean_url)
video-embed-bot_1  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^
video-embed-bot_1  |   File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.12/site-packages/tiktokapipy/async_api.py", line 191, in video
video-embed-bot_1  |     response = VideoPage.model_validate(
video-embed-bot_1  |                ^^^^^^^^^^^^^^^^^^^^^^^^^
video-embed-bot_1  |   File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.12/site-packages/pydantic/main.py", line 551, in model_validate
video-embed-bot_1  |     return cls.__pydantic_validator__.validate_python(
video-embed-bot_1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
video-embed-bot_1  | pydantic_core._pydantic_core.ValidationError: 1 validation error for VideoPage
video-embed-bot_1  | itemInfo.itemStruct.video.subtitleInfos.0.Version
video-embed-bot_1  |   Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value='1:whisper_lid', input_type=str]

Tested by monkey-patching the lib.

amadejkastelic commented 4 months ago

Tests failed due to #82. I think this is safe to merge.

hytradebridge commented 1 month ago

any updates?

amadejkastelic commented 1 month ago

You can monkeypatch it like this in your code until (if ever) this gets merged: https://github.com/amadejkastelic/discord-video-embed-bot/blob/develop/bot%2Fintegrations%2Ftiktok%2F__init__.py

edshee commented 1 month ago

You can monkeypatch it like this in your code until (if ever) this gets merged: https://github.com/amadejkastelic/discord-video-embed-bot/blob/develop/bot%2Fintegrations%2Ftiktok%2F__init__.py

Just wanted to say thank you for this. It's fixed the formatting error for me. Hopefully it'll get merged soon.