Skip to content

Commit 8ffbf80

Browse files
author
TubeAgentKit
committed
v0.3.1: fix search pagination docs (continuation_token, not pagination.next_page_token); live test for the README example
1 parent a6f3935 commit 8ffbf80

5 files changed

Lines changed: 23 additions & 9 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ print(to_text(result)) # one block of plain text
8888
### Search
8989

9090
```python
91-
client.search("lofi beats", type="video", limit=10)
91+
first_page = client.search("lofi beats", type="video", limit=10)
9292

93-
# Pagination
94-
page2 = client.search(page_token=first_page["pagination"]["next_page_token"])
93+
# Pagination: pass continuation_token back as page_token
94+
if first_page.get("continuation_token"):
95+
page2 = client.search(page_token=first_page["continuation_token"])
9596
```
9697

9798
### Channels

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "getyoutubetranscript"
7-
version = "0.3.0"
7+
version = "0.3.1"
88
description = "YouTube transcript API for Python: get YouTube video transcripts, captions and subtitles with timestamps, search YouTube, and list channel and playlist videos. No proxies or headless browser."
99
readme = "README.md"
1010
requires-python = ">=3.9"

‎src/getyoutubetranscript/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .formatters import format_transcript, to_json, to_srt, to_text, to_timed_text, to_vtt
1414
from .types import Segment, TranscriptData
1515

16-
__version__ = "0.3.0"
16+
__version__ = "0.3.1"
1717

1818
__all__ = [
1919
"Client",

‎src/getyoutubetranscript/client.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ def search(
184184
Args:
185185
query: Search query. Required for a first page unless
186186
``page_token`` is given.
187-
page_token: Continuation token from a previous response's
188-
``pagination.next_page_token``, to fetch the next page. Treat
189-
as opaque - don't construct it yourself.
187+
page_token: The ``continuation_token`` from a previous response,
188+
to fetch the next page. Treat as opaque - don't construct it
189+
yourself. Expires after 24 hours.
190190
type: Restrict results to ``"video"`` (default) or ``"channel"``.
191191
Never mixes both kinds in one response.
192192
country: Two-letter region code, e.g. ``"us"``.
@@ -196,7 +196,8 @@ def search(
196196
Returns:
197197
dict with ``query``, and either ``video_results`` or
198198
``channel_results`` depending on ``type``, plus
199-
``pagination.next_page_token`` when more results are available.
199+
``continuation_token`` for the next page (missing or ``None`` when
200+
there are no more pages, so read it with ``.get()``).
200201
201202
Raises:
202203
ValueError: if neither ``query`` nor ``page_token`` is given.

‎tests/live/test_live_api.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ def test_search_live(client: Client):
7171
assert len(result["video_results"]) > 0
7272

7373

74+
def test_search_pagination_live(client: Client):
75+
"""The README pagination example: continuation_token goes back in as page_token."""
76+
first_page = client.search("lofi beats", type="video", limit=10)
77+
assert "pagination" not in first_page
78+
token = first_page.get("continuation_token")
79+
assert token, "first page should offer a next page"
80+
page2 = client.search(page_token=token)
81+
assert page2["video_results"]
82+
first_titles = {v.get("title") for v in first_page["video_results"]}
83+
assert not first_titles & {v.get("title") for v in page2["video_results"]}
84+
85+
7486
def test_get_credits_live(client: Client):
7587
"""Free endpoint - safe to run often."""
7688
result = client.get_credits()

0 commit comments

Comments
 (0)