Skip to content

Respect the count parameter in video list endpoints - #1306

Open
ennsharma wants to merge 1 commit into
davidteather:mainfrom
ennsharma:fix/respect-count-parameter
Open

Respect the count parameter in video list endpoints#1306
ennsharma wants to merge 1 commit into
davidteather:mainfrom
ennsharma:fix/respect-count-parameter

Conversation

@ennsharma

Copy link
Copy Markdown

Fixes #1267.

Since v6.4.0 the request count is hardcoded (currently 30), and the page loop yields every item in the response — so async 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):

  1. Request "count": min(count - found, 30) so each page asks only for what's still needed — count=70 pages as 30 + 30 + 10.
  2. Stop yielding once 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, and playlist.videos.

Verified against a mocked make_request that always returns 30-item pages with hasMore: true:

  • count=1 → yields exactly 1, single request with count=1
  • count=70 → yields exactly 70, requests [30, 30, 10]
  • count=35 on sound.videos → yields 35, requests [30, 5]
  • hasMore: false short-circuit still terminates early

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] - user.videos() count is ignored

1 participant