feat(catalog): a video's related videos, without what the user has seen
GET /api/search/related/{video_id} reads the list YouTube shows beside a
video from the website's InnerTube "next" endpoint (no quota), and brings
it into the catalog the way live-search results come in. It leaves out
what the user watched or hid, here or in their Takeout history (unless
taken back to "new" since), blocked channels and the video itself, and
pages on until 20 are gathered (at most 4 pages). region=topical|hu picks
the locale the list is filled in. Its own per-user daily cap
(related_daily_limit_per_user, one event per opened list); a failed
scrape answers 422 youtube/unavailable.
The InnerTube request (live key, consent cookie, errors) moves into
youtube/innertube.py, shared by the search scrape and the related one.
This commit is contained in:
@@ -9,7 +9,7 @@ import json
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from app.youtube import search_scrape
|
||||
from app.youtube import innertube, search_scrape
|
||||
|
||||
RESULTS_HTML = (
|
||||
'<script>{"INNERTUBE_API_KEY":"live-key","INNERTUBE_CLIENT_VERSION":"2.20261001"}</script>'
|
||||
@@ -79,11 +79,11 @@ def net(monkeypatch):
|
||||
|
||||
real = httpx.Client
|
||||
monkeypatch.setattr(
|
||||
search_scrape.httpx,
|
||||
innertube.httpx,
|
||||
"Client",
|
||||
lambda **kw: real(transport=httpx.MockTransport(transport), **kw),
|
||||
)
|
||||
monkeypatch.setattr(search_scrape, "_config", None)
|
||||
monkeypatch.setattr(innertube, "_config", None)
|
||||
state["calls"] = calls
|
||||
return state
|
||||
|
||||
@@ -171,7 +171,7 @@ def test_a_failed_key_fetch_falls_back_for_now_and_tries_again_next_time(net, re
|
||||
with no error anywhere."""
|
||||
net["handler"] = _serve(results_html=results_html)
|
||||
search_scrape.search("a")
|
||||
assert net["calls"][-1].url.params["key"] == search_scrape._FALLBACK_KEY
|
||||
assert net["calls"][-1].url.params["key"] == innertube._FALLBACK_KEY
|
||||
|
||||
net["handler"] = _serve()
|
||||
search_scrape.search("b")
|
||||
|
||||
Reference in New Issue
Block a user