Russell-Newton / TikTokPy

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

A good way to count the number of videos for a specific user? #63

Closed konax3 closed 11 months ago

konax3 commented 11 months ago

Hi to all, Do you know if there is a good way to obtain the number of published videos for a specific user?

I'm using this piece of code to confirm if a video with the same title already exists and return the number of uploaded videos:

def find_uploaded_video(username, uploaded_title):
    with TikTokAPI() as api:
        user = api.user(username)
        for video in user.videos:
            video_title = video.desc.split(" // ")[0]
            video_title = re.sub(r'#\w+', '', video_title)  # Remove tags from video title
            video_title = video_title.strip()  # Remove leading/trailing whitespace

            try:
                if uploaded_title == video_title:
                    video_id = video.video.id
                    link = video_link(video_id)
                    return link, user.stats.video_count
            except requests.exceptions.RequestException as e:
                print(f"Error accessing video URL: {link}")
                print(e)
    return "Video not found", user.stats.video_count

This piece of code works with a few amount of videos but the lasts weeks i'm always obtaning this error:

Data scraping unable to complete in 30.0s (retries: 0)

I've modified the time in a variable navigation_timeout: float at api.py but i'm only obtain the message with the new value, but it not spent this amount of time, it finished at 30 seconds like before.

Data scraping unable to complete in 30000000.0s (retries: 0)

Do you have any idea to solve this issue?

Thanks in advance.

san1rope commented 11 months ago

Can you tell me what version of TikTokApi and playwright-python you are using

Russell-Newton commented 11 months ago

You can just use user.stats.video_count to get the number of videos published by a user. There's no need to loop through the videos to find out.

With regards to the navigation timeout, you need to pass it in as a parameter to TikTokAPI, otherwise it won't get set correctly. Also what region are you in?

konax3 commented 11 months ago

Can you tell me what version of TikTokApi and playwright-python you are using

i'm using these versions: tiktokapipy 0.1.13.post1 playwright 1.30.0

konax3 commented 11 months ago

You can just use user.stats.video_count to get the number of videos published by a user. There's no need to loop through the videos to find out.

With regards to the navigation timeout, you need to pass it in as a parameter to TikTokAPI, otherwise it won't get set correctly. Also what region are you in?

Thanks!! i'm going to check this. But i'm iterating through them to check if there is a video already uploaded with the same title. I'm from Spain.

konax3 commented 11 months ago

passing the timeout like a parameter is working a little better. Few times i get the same error but i think if i put a longer timeout it will be solved. Thanks again.