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
@@ -13,6 +13,8 @@ interface CastListProps {
|
||||
maxItems?: number;
|
||||
/** Override link for "All Cast & Crew" — if unset, uses /entry/:entryId/cast */
|
||||
allCastHref?: string;
|
||||
/** Section heading (default: "Cast") */
|
||||
title?: string;
|
||||
}
|
||||
|
||||
export function CastList({
|
||||
@@ -21,6 +23,7 @@ export function CastList({
|
||||
isTvSeries,
|
||||
maxItems,
|
||||
allCastHref,
|
||||
title = "Cast",
|
||||
}: CastListProps) {
|
||||
let castCredits = credits.filter((c) => c.cast_type === "cast");
|
||||
const hasMore = maxItems != null && castCredits.length > maxItems;
|
||||
@@ -36,7 +39,7 @@ export function CastList({
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-lg font-semibold">Cast</h3>
|
||||
<h3 className="text-lg font-semibold">{title}</h3>
|
||||
{allCastLink && (
|
||||
<Link
|
||||
to={allCastLink}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { useEntryRecommendations } from "@/hooks/useEntries";
|
||||
import { EntryCard } from "@/components/entries/EntryCard";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
|
||||
const GRID =
|
||||
"grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-4 xl:grid-cols-6";
|
||||
const MAX_ITEMS = 12;
|
||||
|
||||
/** "More like this": live TMDB recommendations for a library entry. */
|
||||
export function RecommendationsSection({
|
||||
entryId,
|
||||
isTvSeries,
|
||||
}: {
|
||||
entryId: number;
|
||||
isTvSeries: boolean;
|
||||
}) {
|
||||
const { data, isLoading, isError } = useEntryRecommendations(entryId);
|
||||
|
||||
if (isError) return null;
|
||||
|
||||
const results = (data?.results ?? [])
|
||||
.filter((r) => r.poster_path)
|
||||
.slice(0, MAX_ITEMS)
|
||||
// Recommendations don't always carry media_type; it matches the entry's
|
||||
.map((r) => ({
|
||||
...r,
|
||||
media_type: r.media_type ?? (isTvSeries ? "tv" : "movie"),
|
||||
}));
|
||||
|
||||
if (!isLoading && results.length === 0) return null;
|
||||
|
||||
return (
|
||||
<section className="space-y-3">
|
||||
<h3 className="text-lg font-semibold">More like this</h3>
|
||||
<div className={GRID}>
|
||||
{isLoading
|
||||
? Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="aspect-2/3 rounded-lg" />
|
||||
))
|
||||
: results.map((r) => <EntryCard key={r.id} tmdbEntry={r} />)}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import { useState } from "react";
|
||||
import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog";
|
||||
import type { TmdbVideo } from "@/types";
|
||||
|
||||
/** Plays an entry's stored TMDB YouTube videos; trailers come first. */
|
||||
export function TrailerDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
title,
|
||||
videos,
|
||||
}: {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
title: string;
|
||||
videos: TmdbVideo[];
|
||||
}) {
|
||||
const [activeKey, setActiveKey] = useState(videos[0]?.key);
|
||||
const active = videos.find((v) => v.key === activeKey) ?? videos[0];
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="w-full max-w-4xl! gap-3 p-3">
|
||||
<DialogTitle className="pr-8 text-sm">
|
||||
{title} · {active?.name}
|
||||
</DialogTitle>
|
||||
{active && (
|
||||
<div className="aspect-video w-full overflow-hidden rounded-lg bg-black">
|
||||
<iframe
|
||||
key={active.key}
|
||||
src={`https://www.youtube-nocookie.com/embed/${active.key}?autoplay=1&rel=0`}
|
||||
title={active.name}
|
||||
allow="autoplay; encrypted-media; picture-in-picture; fullscreen"
|
||||
allowFullScreen
|
||||
className="h-full w-full"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{videos.length > 1 && (
|
||||
<div className="flex gap-2 overflow-x-auto pb-1">
|
||||
{videos.map((v) => (
|
||||
<button
|
||||
key={v.key}
|
||||
type="button"
|
||||
onClick={() => setActiveKey(v.key)}
|
||||
className={`shrink-0 rounded-md border px-2.5 py-1 text-xs transition-colors ${
|
||||
v.key === active?.key
|
||||
? "border-foreground/30 bg-accent font-medium"
|
||||
: "border-border/60 text-muted-foreground hover:text-foreground"
|
||||
}`}
|
||||
>
|
||||
{v.type}: {v.name}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -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