pytok icon indicating copy to clipboard operation
pytok copied to clipboard

videos(count=x) not working

Open Dr-Yes opened this issue 1 year ago • 1 comments

I'm trying to only get 20 videos from a user so I changed the example like so:

`import asyncio import json

from pytok.tiktok import PyTok

async def main(): async with PyTok() as api: user = api.user(username="therock") user_data = await user.info()

    videos = []
    videos_bytes = []
    async for video in user.videos(count=20):
        video_data = await video.info()
        videos.append(video_data)

    assert len(videos) > 0, "No videos found"
    with open("rock.json", "w") as f:
        json.dump(videos, f)

if name == "main": asyncio.run(main())`

It prints "Failed to get videos all at once, trying in batches..." and returns 32 videos for this user and 35 for a different one I tried. Is async the problem? edit: can't get the code markdown to work, but I hope it's readable enough. Only thing I changed is add count=20 to videos parameter

Dr-Yes avatar May 17 '24 08:05 Dr-Yes

This is happening because there are not enough checks on the video method to ensure the number of videos returned is at or below the count number. I don't have time to fix this right now, so please feel free to create a PR!

bendavidsteel avatar May 29 '24 08:05 bendavidsteel