Respect the count parameter in video list endpoints - #1306
Open
ennsharma wants to merge 1 commit into
Open
Conversation
Since the request count was hardcoded (to 30), user.videos(count=1) requested a full page and the page loop yielded every item in it, so callers always got a full page regardless of count (davidteather#1267). Following the approach discussed in davidteather#1267: - request "count": min(count - found, 30) so each page asks for only what is still needed - stop yielding once found >= count, so the generator returns exactly the requested number even if TikTok returns a larger page Applied to the identical pagination loops in user.videos, user.liked, user.playlists, hashtag.videos, sound.videos, and playlist.videos. Fixes davidteather#1267 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1267.
Since v6.4.0 the request
countis hardcoded (currently30), and the page loop yields every item in the response — soasync for video in user.videos(count=1)returns a full page instead of 1 video.This implements the fix the discussion in #1267 converged on (thanks @stolenvw and @mimo-om):
"count": min(count - found, 30)so each page asks only for what's still needed —count=70pages as 30 + 30 + 10.found >= count, so the generator returns exactly the requested number even when TikTok returns a larger page than requested (the original failure mode).Applied to the six identical pagination loops:
user.videos,user.liked,user.playlists,hashtag.videos,sound.videos, andplaylist.videos.Verified against a mocked
make_requestthat always returns 30-item pages withhasMore: true:count=1→ yields exactly 1, single request withcount=1count=70→ yields exactly 70, requests[30, 30, 10]count=35onsound.videos→ yields 35, requests[30, 5]hasMore: falseshort-circuit still terminates early🤖 Generated with Claude Code