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:
X4Lo committed 2026-11-05 11:39:15 +00:00
1 parent cee6f7f961
commit a9ff2d089a
33 files changed
+1722 -483

No files matched your search

+226 -12
View File
@@ -38,6 +38,12 @@ import {
Tv,
Clock,
CalendarDays,
Globe,
Languages,
Building2,
DollarSign,
ListVideo,
CircleDot,
} from "lucide-react";
import {
Tooltip,
@@ -47,6 +53,9 @@ import {
import { CastList } from "@/components/entries/CastList";
import { SeasonsContainer } from "@/components/entries/SeasonsContainer";
import { StreamingSection } from "@/components/streaming/StreamingSection";
import { WatchProvidersCard } from "@/components/entries/WatchProvidersCard";
import { TrailerDialog } from "@/components/entries/TrailerDialog";
import { RecommendationsSection } from "@/components/entries/RecommendationsSection";
import { EntrySettingsDialog } from "@/components/dialogs/EntrySettingsDialog";
import { EntrySeenDialog } from "@/components/dialogs/EntrySeenDialog";
import { EntryMediaDialog } from "@/components/dialogs/EntryMediaDialog";
@@ -61,6 +70,7 @@ import {
DialogTitle,
} from "@/components/ui/dialog";
import { EntryDetailsSkeleton } from "@/components/skeletons/PageSkeletons";
import { getTmdbImageUrl } from "@/lib/api";
import {
getPosterUrl,
getFullPosterUrl,
@@ -108,6 +118,26 @@ function getWatchStatusInfo(value: string | null | undefined) {
return WATCH_STATUSES.find((s) => s.value === value);
}
const formatMoney = (value: number) =>
new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
notation: "compact",
maximumFractionDigits: 1,
}).format(value);
const formatCount = (value: number) =>
new Intl.NumberFormat("en-US", { notation: "compact" }).format(value);
const languageName = (() => {
try {
const names = new Intl.DisplayNames(["en"], { type: "language" });
return (code: string) => names.of(code) ?? code;
} catch {
return (code: string) => code;
}
})();
export function EntryDetailsPage() {
const { id } = useParams<{ id: string }>();
const entryId = parseInt(id!, 10);
@@ -137,6 +167,7 @@ export function EntryDetailsPage() {
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
const [showStatusDialog, setShowStatusDialog] = useState(false);
const [showPosterDialog, setShowPosterDialog] = useState(false);
const [showTrailer, setShowTrailer] = useState(false);
const [editSeenRecord, setEditSeenRecord] = useState<EntrySeen | null>(null);
// Track recently viewed for command palette
@@ -171,6 +202,27 @@ export function EntryDetailsPage() {
? getWatchStatusInfo(e.watch_status)
: undefined;
const userRating = e.entryRatings?.user_rating ?? 0;
const videos = e.tmdb_videos ?? [];
const nextEpisode = e.is_tvseries ? e.next_episode_to_air : null;
const socialLinks = [
e.homepage && { label: "Website", href: e.homepage },
e.entryIds?.wikidata_id && {
label: "Wikidata",
href: `https://www.wikidata.org/wiki/${e.entryIds.wikidata_id}`,
},
e.entryIds?.instagram_id && {
label: "Instagram",
href: `https://www.instagram.com/${e.entryIds.instagram_id}`,
},
e.entryIds?.twitter_id && {
label: "X",
href: `https://x.com/${e.entryIds.twitter_id}`,
},
e.entryIds?.facebook_id && {
label: "Facebook",
href: `https://www.facebook.com/${e.entryIds.facebook_id}`,
},
].filter(Boolean) as { label: string; href: string }[];
const lastSeen =
watchHistory
.map((wh) => wh.date_seen)
@@ -227,6 +279,11 @@ export function EntryDetailsPage() {
)}
{e.is_tvseries ? "TV Series" : "Movie"}
</span>
{e.certification && (
<span className="rounded border border-foreground/30 px-1.5 py-px text-xs font-semibold tracking-wide text-foreground/90">
{e.certification}
</span>
)}
{e.is_tvseries && e.status && (
<span className="rounded-full border border-border/60 bg-background/60 px-2.5 py-0.5 text-xs font-medium text-muted-foreground backdrop-blur">
{e.status}
@@ -251,6 +308,11 @@ export function EntryDetailsPage() {
<h1 className="select-text text-4xl font-extrabold leading-[1.05] tracking-tight text-balance sm:text-5xl">
{e.title}
</h1>
{e.tagline && (
<p className="select-text text-base italic text-foreground/70">
{e.tagline}
</p>
)}
{e.original_title && e.original_title !== e.title && (
<p className="select-text text-sm text-muted-foreground italic">
{e.original_title}
@@ -283,6 +345,22 @@ export function EntryDetailsPage() {
{seasons.length === 1 ? "season" : "seasons"}
</MetaItem>
)}
{e.is_tvseries && e.created_by && e.created_by.length > 0 && (
<MetaItem>
Created by{" "}
{e.created_by.map((c, i) => (
<span key={c.id}>
{i > 0 && ", "}
<Link
to={`/people/tmdb/${c.id}`}
className="font-medium text-foreground hover:underline"
>
{c.name}
</Link>
</span>
))}
</MetaItem>
)}
{director?.people?.name && (
<MetaItem>
Directed by{" "}
@@ -314,15 +392,26 @@ export function EntryDetailsPage() {
{/* Actions */}
<div className="flex flex-wrap items-center justify-center gap-2 pt-1 sm:justify-start">
<StreamingSection entry={e} seasons={seasons} />
<a
href={`https://www.youtube.com/results?search_query=${encodeURIComponent(e.title + " official trailer")}`}
target="_blank"
rel="noopener noreferrer"
className="inline-flex h-11 items-center gap-2 rounded-md border border-border/60 bg-background/60 px-5 text-sm font-medium backdrop-blur transition-colors hover:bg-accent"
>
<Play className="h-4 w-4" />
Trailer
</a>
{videos.length > 0 ? (
<button
type="button"
onClick={() => setShowTrailer(true)}
className="inline-flex h-11 items-center gap-2 rounded-md border border-border/60 bg-background/60 px-5 text-sm font-medium backdrop-blur transition-colors hover:bg-accent"
>
<Play className="h-4 w-4" />
Trailer
</button>
) : (
<a
href={`https://www.youtube.com/results?search_query=${encodeURIComponent(e.title + " official trailer")}`}
target="_blank"
rel="noopener noreferrer"
className="inline-flex h-11 items-center gap-2 rounded-md border border-border/60 bg-background/60 px-5 text-sm font-medium backdrop-blur transition-colors hover:bg-accent"
>
<Play className="h-4 w-4" />
Trailer
</a>
)}
<div className="flex items-center gap-1.5">
<IconAction
@@ -449,6 +538,21 @@ export function EntryDetailsPage() {
</Section>
)}
{e.keywords && e.keywords.length > 0 && (
<Section title="Keywords">
<div className="flex flex-wrap gap-1.5">
{e.keywords.map((k) => (
<span
key={k}
className="rounded-md bg-muted px-2 py-0.5 text-xs text-muted-foreground"
>
{k}
</span>
))}
</div>
</Section>
)}
{credits.length > 0 && (
<CastList
credits={credits}
@@ -463,6 +567,8 @@ export function EntryDetailsPage() {
)}
<EntryCollectionsSection entryId={e.id} />
<RecommendationsSection entryId={e.id} isTvSeries={e.is_tvseries} />
</div>
{/* ── Sidebar ── */}
@@ -485,6 +591,11 @@ export function EntryDetailsPage() {
: null
}
accent="text-sky-500"
sub={
e.entryRatings?.tmdb_vote_count
? `${formatCount(e.entryRatings.tmdb_vote_count)} votes`
: undefined
}
/>
<RatingTile
label="You"
@@ -510,9 +621,80 @@ export function EntryDetailsPage() {
{formatRuntime(e.runtime)}
</DetailRow>
)}
{e.is_tvseries &&
(e.number_of_seasons || e.number_of_episodes) && (
<DetailRow icon={<ListVideo />} label="Episodes">
{[
e.number_of_seasons &&
`${e.number_of_seasons} ${e.number_of_seasons === 1 ? "season" : "seasons"}`,
e.number_of_episodes && `${e.number_of_episodes} eps`,
]
.filter(Boolean)
.join(" · ")}
</DetailRow>
)}
{e.is_tvseries && e.last_air_date && (
<DetailRow icon={<CalendarDays />} label="Last aired">
{formatDate(e.last_air_date)}
</DetailRow>
)}
{nextEpisode && (
<DetailRow icon={<CircleDot />} label="Next episode">
<span className="block">
S{nextEpisode.season_number}E{nextEpisode.episode_number}
{nextEpisode.air_date &&
` · ${formatDate(nextEpisode.air_date)}`}
</span>
<span className="block text-xs font-normal text-muted-foreground">
{nextEpisode.name}
</span>
</DetailRow>
)}
{e.is_tvseries && e.networks && e.networks.length > 0 && (
<DetailRow icon={<Tv />} label="Network">
{e.networks.map((n) => n.name).join(", ")}
<span className="inline-flex flex-wrap justify-end gap-2">
{e.networks.map((n) =>
n.logo_path ? (
<img
key={n.id}
src={getTmdbImageUrl(n.logo_path, "w92")}
alt={n.name}
title={n.name}
className="h-4 max-w-20 object-contain dark:invert dark:brightness-200"
/>
) : (
<span key={n.id}>{n.name}</span>
),
)}
</span>
</DetailRow>
)}
{e.tv_type && (
<DetailRow icon={<Film />} label="Type">
{e.tv_type}
</DetailRow>
)}
{e.original_language && (
<DetailRow icon={<Languages />} label="Language">
{languageName(e.original_language)}
</DetailRow>
)}
{!e.is_tvseries && e.budget ? (
<DetailRow icon={<DollarSign />} label="Budget">
{formatMoney(e.budget)}
</DetailRow>
) : null}
{!e.is_tvseries && e.revenue ? (
<DetailRow icon={<DollarSign />} label="Box office">
{formatMoney(e.revenue)}
</DetailRow>
) : null}
{e.production_companies && e.production_companies.length > 0 && (
<DetailRow icon={<Building2 />} label="Studio">
{e.production_companies
.slice(0, 3)
.map((c) => c.name)
.join(", ")}
</DetailRow>
)}
{e.country && (
@@ -545,8 +727,10 @@ export function EntryDetailsPage() {
)}
</dl>
{(e.entryIds?.tmdb_id || e.entryIds?.imdb_id) && (
<div className="mt-4 flex gap-2 border-t border-border/60 pt-4">
{(e.entryIds?.tmdb_id ||
e.entryIds?.imdb_id ||
socialLinks.length > 0) && (
<div className="mt-4 flex flex-wrap gap-2 border-t border-border/60 pt-4">
{e.entryIds?.tmdb_id && (
<ExternalChip
href={`https://www.themoviedb.org/${e.is_tvseries ? "tv" : "movie"}/${e.entryIds.tmdb_id}`}
@@ -561,9 +745,23 @@ export function EntryDetailsPage() {
IMDb
</ExternalChip>
)}
{socialLinks.map((l) => (
<ExternalChip key={l.label} href={l.href}>
{l.label === "Website" ? (
<span className="inline-flex items-center gap-1">
<Globe className="h-3 w-3" />
Website
</span>
) : (
l.label
)}
</ExternalChip>
))}
</div>
)}
</div>
<WatchProvidersCard providers={e.watch_providers} />
</aside>
</div>
@@ -649,6 +847,15 @@ export function EntryDetailsPage() {
}}
/>
{showTrailer && videos.length > 0 && (
<TrailerDialog
open={showTrailer}
onOpenChange={setShowTrailer}
title={e.title}
videos={videos}
/>
)}
<Dialog open={showPosterDialog} onOpenChange={setShowPosterDialog}>
<DialogContent className="w-auto max-w-[calc(100%-2rem)] sm:max-w-[calc(100%-2rem)] p-0 bg-transparent ring-0 overflow-hidden">
<DialogTitle className="sr-only">{e.title} poster</DialogTitle>
@@ -751,12 +958,14 @@ function RatingTile({
value,
accent,
emptyLabel = "—",
sub,
onClick,
}: {
label: string;
value: string | null;
accent: string;
emptyLabel?: string;
sub?: string;
onClick?: () => void;
}) {
const content = (
@@ -776,6 +985,11 @@ function RatingTile({
{emptyLabel}
</span>
)}
{sub && (
<span className="text-[10px] text-muted-foreground tabular-nums">
{sub}
</span>
)}
</>
);
const className =