feat: search pagination

adds support for getting past the first page of search results
This commit is contained in:
2025-10-03 01:16:56 +02:00
parent 7eb4452fec
commit 468795a7a2
3 changed files with 27 additions and 5 deletions

View File

@@ -23,7 +23,7 @@ import ythdd_struct_parser
# [✓] /api/v1/stats (stats())
# [✓] /streams/dQw4w9WgXcQ (does nothing)
# [✓] /vi/:videoIdXXXX/maxresdefault.jpg
# [✓] /api/v1/search?q=... (videos and playlists)
# [✓] /api/v1/search?q=... (videos and playlists), pagination
# [✓] /api/v1/search/suggestions?q=...&pq=...
# [✓] /api/v1/channel/:ucid
# [✓] /api/v1/channel/:ucid/videos, shorts, playlists, streams
@@ -38,6 +38,7 @@ import ythdd_struct_parser
# [X] /api/v1/videos/:videoIdXXXX does not depend on yt-dlp and offloads stream retrieval elsewhere (making initial response fast)
# [X] /api/v1/manifest/:videoIdXXXX (above is prerequisite)
# [X] rewrite the awful lookup logic
# [X] /api/v1/search?q=... complex filtering options (https://gitea.invidious.io/iv-org/invidious/src/branch/master/src/invidious/search/filters.cr)
# ----------
# IDEAS:
# [*] /api/v1/popular returns last requested videos by the IP (serving as multi-device history?)
@@ -579,14 +580,19 @@ def search(data, req):
# ignore paginated requests as we do nothing with the continuation token
page = req.args.get('page')
if page is not None and page != '1':
return send(404, [])
try:
page = int(page)
except:
return send(400, {"error": "Wrong page."})
else:
page = None # when page is "1"
if (data[-2].lower() != "search" or data[-1].lower() != "") and data[-1].lower() != "search":
previous_query = req.args.get('pq')
suggestions = ythdd_extractor.WEBgetSearchSuggestions(search_query, previous_query)
return send(200, suggestions)
results = ythdd_extractor.WEBextractSearchResults(search_query)
results = ythdd_extractor.WEBextractSearchResults(search_query, page)
results_list = []
for entry in results: