feat(youtube): optional egress proxy for YouTube API calls
New youtube_api_proxy setting (env fallback + admin Config UI, env YOUTUBE_API_PROXY): when set, the YouTubeClient routes all its httpx traffic through that HTTP(S) proxy. Lets a dynamic-IP host send API calls through a fixed-IP host (e.g. the server over private tunnel) so an IP-restricted API key keeps working. Empty = direct.
This commit is contained in:
parent
6c4c33f956
commit
d047ed7e15
6 changed files with 13 additions and 1 deletions
|
|
@ -65,6 +65,10 @@ class Settings(BaseSettings):
|
|||
# Optional API key for public reads (channels/videos/playlistItems). When set it is
|
||||
# preferred for shared backfill/enrichment so it doesn't depend on a specific user.
|
||||
youtube_api_key: str = ""
|
||||
# Optional HTTP(S) proxy for outbound YouTube Data API calls. Set this to send the
|
||||
# scheduler's googleapis traffic through a fixed-IP host (e.g. the VPS over WireGuard) so an
|
||||
# IP-restricted API key keeps working even when this host's public IP is dynamic.
|
||||
youtube_api_proxy: str = ""
|
||||
# Daily quota budget (units). Default leaves headroom under the 10,000/day free limit.
|
||||
quota_daily_budget: int = 9000
|
||||
# Recent-first backfill: how far back to fetch on the first pass per channel.
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@ SPECS: tuple[ConfigSpec, ...] = (
|
|||
ConfigSpec("autotag_title_sample", "int", "batch", "autotag_title_sample", min=1, max=1_000),
|
||||
# --- YouTube Data API key (secret; optional — public reads prefer it over OAuth) ---
|
||||
ConfigSpec("youtube_api_key", "str", "youtube", "youtube_api_key", secret=True),
|
||||
# Optional egress proxy for YouTube API calls (fixed-IP host for an IP-restricted key).
|
||||
ConfigSpec("youtube_api_proxy", "str", "youtube", "youtube_api_proxy"),
|
||||
# --- Google OAuth client (Sign in with Google; both encrypted, env fallback). Set from the
|
||||
# install wizard / Configuration page so no restart is needed when the creds change. ---
|
||||
ConfigSpec("google_client_id", "str", "google", "google_client_id", secret=True),
|
||||
|
|
|
|||
|
|
@ -44,7 +44,10 @@ class YouTubeClient:
|
|||
def __init__(self, db, user: User):
|
||||
self.db = db
|
||||
self.user = user
|
||||
self._http = httpx.Client(timeout=30.0)
|
||||
# Optionally route all YouTube traffic through a fixed-IP egress proxy (e.g. the VPS
|
||||
# over WireGuard) so an IP-restricted API key keeps working from a dynamic-IP host.
|
||||
proxy = sysconfig.get_str(db, "youtube_api_proxy") or None
|
||||
self._http = httpx.Client(timeout=30.0, proxy=proxy)
|
||||
|
||||
def __enter__(self) -> "YouTubeClient":
|
||||
return self
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue