naseif / tiktok-scraper

Scraper for TikTok. Download videos, music, fetch users info and more.
https://naseif.github.io/tiktok-scraper/
MIT License
90 stars 25 forks source link

`getAllVideosFromUser` function only fetch maximum 30 videos #2

Closed tonyquang closed 2 years ago

tonyquang commented 2 years ago

First of all, I wanna say thank you for your API it's amazing, almost function working perfectly except getAllVideosFromUser getAllVideosFromUser function only fetches a maximum of 30 videos, can we have a solution to fetch all videos of a user? I research before we need some signature and an endpoint for that

naseif commented 2 years ago

First of all, I wanna say thank you for your API it's amazing, almost function working perfectly except getAllVideosFromUser getAllVideosFromUser function only fetches a maximum of 30 videos, can we have a solution to fetch all videos of a user? I research before we need some signature and an endpoint for that

I am fully aware of this issue. I will be looking for a solution in the next few days.

tonyquang commented 2 years ago

First of all, I wanna say thank you for your API it's amazing, almost function working perfectly except getAllVideosFromUser getAllVideosFromUser function only fetches a maximum of 30 videos, can we have a solution to fetch all videos of a user? I research before we need some signature and an endpoint for that

I am fully aware of this issue. I will be looking for a solution in the next few days.

Perfect πŸ‘

bartek2341 commented 2 years ago

Any updates?

luckman212 commented 2 years ago

Came here to ask the same. Hoping for a solution!

james-elicx commented 2 years ago

Having implemented my own way of doing this, I thought I'd shed some light on how I did it.

I use puppeteer for all fetch requests to a user page. In the request with puppeteer function, I attach a listener to network response events and check if the request for that response included api/post/item_list. If it did, I insert each item in the parsed response text to a set.

In case you didn't know, api/list/item_list is the API endpoint TikTok uses to fetch additional videos when scrolling on a profile.

Using page.evaluate, I scroll down the page until there is no more distance to scroll, meaning there are no more videos to load.

I return the parsed network response data as well as the json object extracted from the page, and in the get videos from user function, I push each item in the object extracted from the page into the set.

And now I have the data for all videos uploaded by a user.

Combining this with tracking the video IDs for previously downloaded videos and stopping scrolling if a video matches one of the IDs, it will support only downloading newly uploaded videos.

If @naseif would like, I can clean up my implementation and make a PR in the next few days.

naseif commented 2 years ago

Hi @moodiest, what a coincidence, I just implemented it but in another way. Using puppeteer is a good idea, but it's slow as hell + too much code for such a simple thing. That's why I tried to fetch the data directly from the API and it works. You can check the last commit I did and see how I did it. Of course it requires Cookies and in my experience tiktok cookies do not expire very soon. Hit me up you have any ideas 🍺

naseif commented 2 years ago

Implemented πŸ€˜πŸΌπŸ±β€πŸ