Store full TMDB data, add rate limiting and stale-entry refresh
Backend - Route all TMDB requests through a rate limiter (20 req/s, 8 concurrent) with 429/5xx retries; stop logging the API key - Fetch external ids, certification, keywords, videos, watch providers and alternative titles in the entry details request - Shared entry mapper used by create, refresh, season refresh and importer - New columns on entries, ids, ratings, seasons, episodes and people, with an idempotent startup migration (adds missing columns, widens types) - Fix TV IMDb ids, network country/logo, episode tmdb_id on refresh, and genre/network removal on refresh - Add stale-entries maintenance job (count, start, cancel) and live recommendations endpoint Frontend - Entry page: certification, tagline, creators, in-app trailer, vote count, TV/movie details, network logos, external links, keywords, where to watch, and recommendations - Episode page: directors, writers and guest stars - Settings: TMDB refresh card with live progress
This commit is contained in:
1 parent
cee6f7f961
commit
a9ff2d089a
33 files changed
+1722
-483
No files matched your search
@@ -0,0 +1,121 @@
|
||||
import { useState } from "react";
|
||||
import { ExternalLink } from "lucide-react";
|
||||
import { getTmdbImageUrl } from "@/lib/api";
|
||||
import type { WatchProvider, WatchProviderRegion } from "@/types";
|
||||
|
||||
const CATEGORIES: { key: keyof WatchProviderRegion; label: string }[] = [
|
||||
{ key: "flatrate", label: "Stream" },
|
||||
{ key: "free", label: "Free" },
|
||||
{ key: "ads", label: "With ads" },
|
||||
{ key: "rent", label: "Rent" },
|
||||
{ key: "buy", label: "Buy" },
|
||||
];
|
||||
|
||||
/** Country from the browser locale (en-US → US), falling back to US. */
|
||||
function defaultRegion(available: string[]): string {
|
||||
const fromLocale = navigator.language?.split("-")[1]?.toUpperCase();
|
||||
if (fromLocale && available.includes(fromLocale)) return fromLocale;
|
||||
if (available.includes("US")) return "US";
|
||||
return available[0];
|
||||
}
|
||||
|
||||
const regionName = (() => {
|
||||
try {
|
||||
const names = new Intl.DisplayNames(["en"], { type: "region" });
|
||||
return (code: string) => names.of(code) ?? code;
|
||||
} catch {
|
||||
return (code: string) => code;
|
||||
}
|
||||
})();
|
||||
|
||||
export function WatchProvidersCard({
|
||||
providers,
|
||||
}: {
|
||||
providers: Record<string, WatchProviderRegion> | null | undefined;
|
||||
}) {
|
||||
const regions = Object.keys(providers ?? {}).sort((a, b) =>
|
||||
regionName(a).localeCompare(regionName(b)),
|
||||
);
|
||||
const [region, setRegion] = useState(() =>
|
||||
regions.length ? defaultRegion(regions) : "",
|
||||
);
|
||||
|
||||
if (!providers || regions.length === 0) return null;
|
||||
|
||||
const info = providers[region] ?? providers[regions[0]];
|
||||
const groups = CATEGORIES.map((c) => ({
|
||||
...c,
|
||||
list: (info[c.key] as WatchProvider[] | null | undefined) ?? [],
|
||||
})).filter((g) => g.list.length > 0);
|
||||
|
||||
return (
|
||||
<div className="rounded-xl border border-border/60 bg-card/50 p-4">
|
||||
<div className="mb-3 flex items-center justify-between gap-2">
|
||||
<h3 className="text-xs font-semibold uppercase tracking-wider text-muted-foreground">
|
||||
Where to watch
|
||||
</h3>
|
||||
<select
|
||||
value={region}
|
||||
onChange={(e) => setRegion(e.target.value)}
|
||||
className="max-w-36 rounded-md border border-border/60 bg-background px-1.5 py-0.5 text-xs"
|
||||
aria-label="Country"
|
||||
>
|
||||
{regions.map((r) => (
|
||||
<option key={r} value={r}>
|
||||
{regionName(r)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{groups.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Not available in {regionName(region)}.
|
||||
</p>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{groups.map((g) => (
|
||||
<div key={g.key} className="space-y-1.5">
|
||||
<p className="text-[11px] font-medium text-muted-foreground">
|
||||
{g.label}
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{g.list
|
||||
.slice()
|
||||
.sort(
|
||||
(a, b) =>
|
||||
(a.display_priority ?? 99) - (b.display_priority ?? 99),
|
||||
)
|
||||
.map((p) => (
|
||||
<img
|
||||
key={p.provider_id}
|
||||
src={
|
||||
p.logo_path
|
||||
? getTmdbImageUrl(p.logo_path, "w92")
|
||||
: undefined
|
||||
}
|
||||
alt={p.provider_name}
|
||||
title={p.provider_name}
|
||||
className="h-9 w-9 rounded-lg object-cover ring-1 ring-border/60"
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{info.link && (
|
||||
<a
|
||||
href={info.link}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="mt-3 inline-flex items-center gap-1 text-[11px] text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<ExternalLink className="h-3 w-3" />
|
||||
Data from JustWatch via TMDB
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user