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] Download videos doesn't work #83

Open vlad43210 opened 11 months ago

vlad43210 commented 11 months ago

Describe the bug If I search for videos by hashtag, I am able to get a number of videos, and get metadata on them, but not download them. There is no error, but on investigation I see that the code finds videos with the hashtag, goes to the first of them, and then just stops.

Here is my code:

from tiktokapipy.async_api import AsyncTikTokAPI
from tiktokapipy.models.video import Video
from tiktokapipy import TikTokAPIError
import aiohttp
import asyncio
import io
import yaml

async with AsyncTikTokAPI(navigation_retries=2, navigation_timeout=120) as api:
    challenge = await api.challenge(hashtag)
    videos = challenge.videos

    async for video in videos:  
        video_cover_url = video.video.cover
        try:
            timestamp = video_cover_url[video_cover_url.index("_") + 1: video_cover_url.index("?")]
        # some timestamps missing
        except:
            timestamp = '0000000000'
        # skip slideshows
        if video.image_post:
            print("video is slideshow, skipping")
            pass
        else:   
            #save video 
            clean_id = video.id.replace("/","*slash*")
            video_path = video.download(trim_file_name=False, \
                    paths={"home":f"{config_dict['data_path']}/{config_dict['map_id']}_tiktok_videos"},\
                    outtmpl={"default":f'{video.author}---{clean_id}---{timestamp}.%(ext)s'})

This code was working earlier and then just stopped working, so I am wondering if there is some secret throttling going on / if anything can be done about that.

To Reproduce Steps to reproduce the behavior:

  1. Wrap the above code in async function that takes a config file, run it. The config file should specify a hashtag (I used cop28) and data path
  2. Code completes but no videos are downloaded

Expected behavior Videos should be downloaded

Version Information Python 3.11.3 playwright 1.40.0 pydantic 2.5.2 tiktokapi 0.2.4.post2 yt-dlp 2023.11.16

System Information OS X Sonoma 14.2 laptop

Region Information US

Additional context Add any other context about the problem here.

Russell-Newton commented 11 months ago

This is likely due to changes tiktok has made with their data schema (#82). I'll need some time to address this, unfortunately.

vlad43210 commented 9 months ago

Hey just checking if you had any time to fix this or if this is still an issue

Russell-Newton commented 9 months ago

Hey just checking if you had any time to fix this or if this is still an issue

Unfortunately I haven't gotten a chance to look into this. I've been ridiculously busy with my master's degree and family. I'm honestly not sure when I'll next get a chance to work on it. In the meantime, I suggest using youtube-dl if you just want to download videos. Downloading videos from a user is also broken on youtube-dl.