Feat/tmdb full data #5
No files matched your search
@@ -3,6 +3,12 @@ const collectionManager = require("../services/collectionManager");
|
|||||||
const entryManager = require("../services/entryManager");
|
const entryManager = require("../services/entryManager");
|
||||||
const entryService = require("../services/entryService");
|
const entryService = require("../services/entryService");
|
||||||
const tmdbService = require("../services/tmdbService");
|
const tmdbService = require("../services/tmdbService");
|
||||||
|
const artworkService = require("../services/artworkService");
|
||||||
|
const {
|
||||||
|
mapEntryFields,
|
||||||
|
mapEntryIds,
|
||||||
|
mapEntryRatings,
|
||||||
|
} = require("../mappers/entryMapper");
|
||||||
const asyncWrapper = require("../utils/asyncWrapper");
|
const asyncWrapper = require("../utils/asyncWrapper");
|
||||||
|
|
||||||
const _collectionManager = collectionManager;
|
const _collectionManager = collectionManager;
|
||||||
@@ -145,6 +151,40 @@ class EntryController {
|
|||||||
res.status(200).json(data);
|
res.status(200).json(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// * GET - TMDB RECOMMENDATIONS BY TMDB ID (entries not in the library)
|
||||||
|
getTmdbRecommendations = asyncWrapper(async (req, res) => {
|
||||||
|
const { type, tmdbId } = req.params;
|
||||||
|
const data = await tmdbService.fetchEntryRecommendations(
|
||||||
|
tmdbId,
|
||||||
|
type === "tv",
|
||||||
|
req.query.page || 1,
|
||||||
|
);
|
||||||
|
if (!data)
|
||||||
|
return res
|
||||||
|
.status(500)
|
||||||
|
.json({ message: "Failed to fetch recommendations" });
|
||||||
|
res.status(200).json(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
// * GET - ARTWORK: TMDB images merged with the entry's media table
|
||||||
|
getEntryArtwork = asyncWrapper(async (req, res) => {
|
||||||
|
const artwork = await artworkService.getEntryArtwork(req.params.id);
|
||||||
|
res.status(200).json(artwork);
|
||||||
|
});
|
||||||
|
|
||||||
|
// * POST - ARTWORK: download a TMDB image into the entry's media table
|
||||||
|
addEntryArtwork = asyncWrapper(async (req, res) => {
|
||||||
|
const media = await artworkService.addEntryArtwork(req.params.id, req.body);
|
||||||
|
res.status(201).json(media);
|
||||||
|
});
|
||||||
|
|
||||||
|
// * GET - ARTWORK BY TMDB ID (entries not in the library)
|
||||||
|
getTmdbArtwork = asyncWrapper(async (req, res) => {
|
||||||
|
const { type, tmdbId } = req.params;
|
||||||
|
const artwork = await artworkService.getTmdbArtwork(type, tmdbId);
|
||||||
|
res.status(200).json(artwork);
|
||||||
|
});
|
||||||
|
|
||||||
// * PUT - REQUEST COLLECTION REFRECH
|
// * PUT - REQUEST COLLECTION REFRECH
|
||||||
fetchEntryCollection = asyncWrapper(async (req, res, next) => {
|
fetchEntryCollection = asyncWrapper(async (req, res, next) => {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
@@ -242,6 +282,59 @@ class EntryController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Directors, so the preview page can show "Directed by"
|
||||||
|
for (const c of creditsData?.crew ?? []) {
|
||||||
|
const jobs = Array.isArray(c.jobs) ? c.jobs.map((j) => j.job) : [c.job];
|
||||||
|
if (!jobs.includes("Director")) continue;
|
||||||
|
credits.push({
|
||||||
|
id: c.credit_id || c.jobs?.[0]?.credit_id || "crew-" + c.id,
|
||||||
|
cast_type: "crew",
|
||||||
|
job: "Director",
|
||||||
|
department: "Directing",
|
||||||
|
character: null,
|
||||||
|
people_id: c.id,
|
||||||
|
people: {
|
||||||
|
id: c.id,
|
||||||
|
name: c.name || c.original_name,
|
||||||
|
profile_path: c.profile_path,
|
||||||
|
tmdb_id: c.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Same shape as a library entry, so the details page can render either
|
||||||
|
const entry = {
|
||||||
|
id: 0,
|
||||||
|
...mapEntryFields(data),
|
||||||
|
is_tvseries: is_tvserie,
|
||||||
|
isInLibrary: false,
|
||||||
|
entryIds: { tmdb_id: data.id, ...mapEntryIds(data) },
|
||||||
|
entryRatings: {
|
||||||
|
user_rating: null,
|
||||||
|
imdb_rating: null,
|
||||||
|
rotten_tomatoes_rating: null,
|
||||||
|
...mapEntryRatings(data),
|
||||||
|
},
|
||||||
|
genres: data.genres || [],
|
||||||
|
networks: (data.networks || []).map((n) => ({
|
||||||
|
id: n.id,
|
||||||
|
name: n.name,
|
||||||
|
origin_country: n.origin_country || null,
|
||||||
|
logo_path: n.logo_path || null,
|
||||||
|
homepage: null,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
const seasons = (data.seasons || []).map((s) => ({
|
||||||
|
id: s.id,
|
||||||
|
name: s.name,
|
||||||
|
season_number: s.season_number,
|
||||||
|
episode_count: s.episode_count,
|
||||||
|
air_date: s.air_date,
|
||||||
|
poster_path: s.poster_path,
|
||||||
|
overview: s.overview,
|
||||||
|
tmdb_rating: s.vote_average,
|
||||||
|
}));
|
||||||
|
|
||||||
// Normalize to a shape similar to our Entry model
|
// Normalize to a shape similar to our Entry model
|
||||||
const preview = {
|
const preview = {
|
||||||
tmdb_id: data.id,
|
tmdb_id: data.id,
|
||||||
@@ -267,6 +360,8 @@ class EntryController {
|
|||||||
homepage: data.homepage || null,
|
homepage: data.homepage || null,
|
||||||
imdb_id: data.imdb_id || data.external_ids?.imdb_id || null,
|
imdb_id: data.imdb_id || data.external_ids?.imdb_id || null,
|
||||||
credits,
|
credits,
|
||||||
|
entry,
|
||||||
|
seasons,
|
||||||
};
|
};
|
||||||
|
|
||||||
res.status(200).json(preview);
|
res.status(200).json(preview);
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ const Media = sequelize.define("media", {
|
|||||||
|
|
||||||
type: { type: DataTypes.STRING(50) },
|
type: { type: DataTypes.STRING(50) },
|
||||||
path: { type: DataTypes.STRING(200) },
|
path: { type: DataTypes.STRING(200) },
|
||||||
|
// TMDB file_path this image was downloaded from (null for custom uploads)
|
||||||
|
tmdbPath: { type: DataTypes.STRING(200), field: "tmdb_path" },
|
||||||
|
|
||||||
isLocal: { type: DataTypes.BOOLEAN, field: "is_local" },
|
isLocal: { type: DataTypes.BOOLEAN, field: "is_local" },
|
||||||
isSelected: {
|
isSelected: {
|
||||||
|
|||||||
@@ -18,6 +18,11 @@ entryRouter.get("/tmdb/top-rated/:type", entryController.getTmdbTopRated);
|
|||||||
entryRouter.get("/tmdb/upcoming/movie", entryController.getTmdbUpcoming);
|
entryRouter.get("/tmdb/upcoming/movie", entryController.getTmdbUpcoming);
|
||||||
entryRouter.get("/tmdb/search", entryController.getTmdbSearch);
|
entryRouter.get("/tmdb/search", entryController.getTmdbSearch);
|
||||||
entryRouter.get("/tmdb/preview/:type/:tmdbId", entryController.getTmdbPreview);
|
entryRouter.get("/tmdb/preview/:type/:tmdbId", entryController.getTmdbPreview);
|
||||||
|
entryRouter.get(
|
||||||
|
"/tmdb/recommendations/:type/:tmdbId",
|
||||||
|
entryController.getTmdbRecommendations,
|
||||||
|
);
|
||||||
|
entryRouter.get("/tmdb/artwork/:type/:tmdbId", entryController.getTmdbArtwork);
|
||||||
|
|
||||||
entryRouter.get("/sync-series", entryController.syncSeries);
|
entryRouter.get("/sync-series", entryController.syncSeries);
|
||||||
|
|
||||||
@@ -35,6 +40,8 @@ entryRouter.get(
|
|||||||
"/:id/recommendations",
|
"/:id/recommendations",
|
||||||
entryController.getEntryRecommendations,
|
entryController.getEntryRecommendations,
|
||||||
);
|
);
|
||||||
|
entryRouter.get("/:id/artwork", entryController.getEntryArtwork);
|
||||||
|
entryRouter.post("/:id/artwork", entryController.addEntryArtwork);
|
||||||
entryRouter.put("/:id/refresh", entryController.refrechEntry);
|
entryRouter.put("/:id/refresh", entryController.refrechEntry);
|
||||||
entryRouter.put("/:id/fetch-collection", entryController.fetchEntryCollection);
|
entryRouter.put("/:id/fetch-collection", entryController.fetchEntryCollection);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,207 @@
|
|||||||
|
const path = require("path");
|
||||||
|
const { v4: uuidv4 } = require("uuid");
|
||||||
|
|
||||||
|
const Entry = require("../models/Entry");
|
||||||
|
const EntryId = require("../models/EntryId");
|
||||||
|
const Media = require("../models/Media");
|
||||||
|
|
||||||
|
const BadRequestError = require("../errors/BadRequestError");
|
||||||
|
const NotFoundError = require("../errors/NotFoundError");
|
||||||
|
const InternalServerError = require("../errors/InternalServerError");
|
||||||
|
|
||||||
|
const configService = require("./configService");
|
||||||
|
const tmdbService = require("./tmdbService");
|
||||||
|
const mediaDownloaderService = require("./mediaDownloaderService");
|
||||||
|
const mediaOptimizerService = require("./mediaOptimizerService");
|
||||||
|
const { logToFile } = require("./logService");
|
||||||
|
|
||||||
|
// TMDB images response key → our Media.type
|
||||||
|
const ARTWORK_TYPES = {
|
||||||
|
posters: "poster",
|
||||||
|
backdrops: "backdrop",
|
||||||
|
logos: "logo",
|
||||||
|
};
|
||||||
|
const MEDIA_TYPES = Object.values(ARTWORK_TYPES);
|
||||||
|
|
||||||
|
function mapTmdbImage(image) {
|
||||||
|
return {
|
||||||
|
file_path: image.file_path,
|
||||||
|
width: image.width,
|
||||||
|
height: image.height,
|
||||||
|
aspect_ratio: image.aspect_ratio,
|
||||||
|
language: image.iso_639_1 || null,
|
||||||
|
vote_average: image.vote_average ?? 0,
|
||||||
|
vote_count: image.vote_count ?? 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function sortByVotes(a, b) {
|
||||||
|
return b.vote_count - a.vote_count || b.vote_average - a.vote_average;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** TMDB artwork grouped by type, best-voted first. */
|
||||||
|
async function fetchTmdbArtwork(tmdbId, isTv) {
|
||||||
|
const data = await tmdbService.fetchEntryMedia(tmdbId, isTv);
|
||||||
|
if (!data) {
|
||||||
|
throw new InternalServerError("Couldn't fetch artwork from TMDB");
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = {};
|
||||||
|
for (const [tmdbKey, type] of Object.entries(ARTWORK_TYPES)) {
|
||||||
|
result[`${type}s`] = (data[tmdbKey] ?? [])
|
||||||
|
.map(mapTmdbImage)
|
||||||
|
.sort(sortByVotes);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ArtworkService {
|
||||||
|
constructor() {
|
||||||
|
if (!ArtworkService.instance) {
|
||||||
|
ArtworkService.instance = this;
|
||||||
|
}
|
||||||
|
return ArtworkService.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Artwork for an entry that is not in the library (TMDB only). */
|
||||||
|
async getTmdbArtwork(type, tmdbId) {
|
||||||
|
const result = await fetchTmdbArtwork(tmdbId, type === "tv");
|
||||||
|
for (const key of Object.keys(result)) {
|
||||||
|
result[key] = result[key].map((img) => ({ ...img, in_library: false }));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TMDB artwork merged with the entry's media table. TMDB images we already
|
||||||
|
* have are flagged `in_library` with their media id; local images that
|
||||||
|
* don't match a TMDB image (custom uploads, older downloads) are appended.
|
||||||
|
*/
|
||||||
|
async getEntryArtwork(entryId) {
|
||||||
|
const entry = await Entry.findByPk(entryId, {
|
||||||
|
attributes: ["id", "is_tvseries"],
|
||||||
|
include: [{ model: EntryId, as: "entryId" }],
|
||||||
|
});
|
||||||
|
if (!entry) throw new NotFoundError("Entry not found");
|
||||||
|
|
||||||
|
const medias = await Media.findAll({
|
||||||
|
where: { mediaable: "entry", mediaableId: entryId, type: MEDIA_TYPES },
|
||||||
|
order: [["id", "ASC"]],
|
||||||
|
});
|
||||||
|
|
||||||
|
const tmdbId = entry.entryId?.tmdb_id;
|
||||||
|
const tmdb = tmdbId
|
||||||
|
? await fetchTmdbArtwork(tmdbId, entry.is_tvseries)
|
||||||
|
: { posters: [], backdrops: [], logos: [] };
|
||||||
|
|
||||||
|
const result = {};
|
||||||
|
for (const type of MEDIA_TYPES) {
|
||||||
|
const key = `${type}s`;
|
||||||
|
const ofType = medias.filter((m) => m.type === type);
|
||||||
|
const byTmdbPath = new Map(
|
||||||
|
ofType.filter((m) => m.tmdbPath).map((m) => [m.tmdbPath, m]),
|
||||||
|
);
|
||||||
|
|
||||||
|
const merged = tmdb[key].map((img) => {
|
||||||
|
const media = byTmdbPath.get(img.file_path);
|
||||||
|
return {
|
||||||
|
...img,
|
||||||
|
in_library: !!media,
|
||||||
|
media_id: media?.id ?? null,
|
||||||
|
media_path: media?.path ?? null,
|
||||||
|
is_selected: !!media?.isSelected,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const localOnly = ofType
|
||||||
|
.filter(
|
||||||
|
(m) =>
|
||||||
|
!m.tmdbPath || !tmdb[key].some((i) => i.file_path === m.tmdbPath),
|
||||||
|
)
|
||||||
|
.map((m) => ({
|
||||||
|
file_path: null,
|
||||||
|
width: null,
|
||||||
|
height: null,
|
||||||
|
aspect_ratio: null,
|
||||||
|
language: null,
|
||||||
|
vote_average: 0,
|
||||||
|
vote_count: 0,
|
||||||
|
in_library: true,
|
||||||
|
media_id: m.id,
|
||||||
|
media_path: m.path,
|
||||||
|
is_selected: !!m.isSelected,
|
||||||
|
is_custom: !!m.isCustom,
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Library images first so what you already have is easy to find
|
||||||
|
result[key] = [
|
||||||
|
...localOnly,
|
||||||
|
...merged.filter((i) => i.in_library),
|
||||||
|
...merged.filter((i) => !i.in_library),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Downloads a TMDB image into the entry's media table. If the entry has no
|
||||||
|
* selected image of that type yet, the new one becomes selected.
|
||||||
|
* @param {number} entryId
|
||||||
|
* @param {{type: "poster"|"backdrop"|"logo", file_path: string}} data
|
||||||
|
*/
|
||||||
|
async addEntryArtwork(entryId, { type, file_path }) {
|
||||||
|
if (!MEDIA_TYPES.includes(type)) {
|
||||||
|
throw new BadRequestError(`Invalid artwork type: ${type}`);
|
||||||
|
}
|
||||||
|
if (!file_path || !/^\/[\w.-]+$/.test(file_path)) {
|
||||||
|
throw new BadRequestError("Invalid TMDB file path");
|
||||||
|
}
|
||||||
|
|
||||||
|
const entry = await Entry.findByPk(entryId, { attributes: ["id"] });
|
||||||
|
if (!entry) throw new NotFoundError("Entry not found");
|
||||||
|
|
||||||
|
const where = { mediaable: "entry", mediaableId: entryId, type };
|
||||||
|
const existing = await Media.findOne({
|
||||||
|
where: { ...where, tmdbPath: file_path },
|
||||||
|
});
|
||||||
|
if (existing) return existing;
|
||||||
|
|
||||||
|
configService.createMediaFolders();
|
||||||
|
const extension = file_path.split(".").pop();
|
||||||
|
const filename = `${uuidv4()}.${extension}`;
|
||||||
|
const dir = path.join(
|
||||||
|
configService.getSettings().userDataPath,
|
||||||
|
"images",
|
||||||
|
"entries",
|
||||||
|
`${type}s`,
|
||||||
|
);
|
||||||
|
|
||||||
|
await mediaDownloaderService.downloadImage(
|
||||||
|
`https://image.tmdb.org/t/p/original${file_path}`,
|
||||||
|
path.join(dir, filename),
|
||||||
|
);
|
||||||
|
|
||||||
|
const hasSelected = await Media.count({
|
||||||
|
where: { ...where, isSelected: true },
|
||||||
|
});
|
||||||
|
const media = await Media.create({
|
||||||
|
...where,
|
||||||
|
path: filename,
|
||||||
|
tmdbPath: file_path,
|
||||||
|
isLocal: true,
|
||||||
|
isSelected: hasSelected === 0,
|
||||||
|
isCustom: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
mediaOptimizerService
|
||||||
|
.doGeneratePreview("entries", `${type}s`, filename)
|
||||||
|
.catch((err) =>
|
||||||
|
logToFile(`Artwork | Error generating preview for ${filename}: ${err}`),
|
||||||
|
);
|
||||||
|
|
||||||
|
logToFile(`Artwork | Added ${type} ${file_path} to entry ${entryId}`);
|
||||||
|
return media;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = new ArtworkService();
|
||||||
@@ -98,6 +98,7 @@ class CollectionManager {
|
|||||||
mediaableId: collection.id,
|
mediaableId: collection.id,
|
||||||
type: image.type,
|
type: image.type,
|
||||||
path: image.path,
|
path: image.path,
|
||||||
|
tmdbPath: image.tmdb_path || null,
|
||||||
isLocal: true,
|
isLocal: true,
|
||||||
isSelected: true,
|
isSelected: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -502,6 +502,7 @@ class EntryManager {
|
|||||||
mediaableId: oldEntry.id,
|
mediaableId: oldEntry.id,
|
||||||
type: image.type,
|
type: image.type,
|
||||||
path: image.path,
|
path: image.path,
|
||||||
|
tmdbPath: image.tmdb_path || null,
|
||||||
isLocal: true,
|
isLocal: true,
|
||||||
isSelected: true,
|
isSelected: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -375,6 +375,7 @@ class EntryService {
|
|||||||
mediaableId: savedEntry.id,
|
mediaableId: savedEntry.id,
|
||||||
type: image.type,
|
type: image.type,
|
||||||
path: image.path,
|
path: image.path,
|
||||||
|
tmdbPath: image.tmdb_path || null,
|
||||||
isLocal: true,
|
isLocal: true,
|
||||||
isSelected: true,
|
isSelected: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -151,7 +151,11 @@ class MediaDownloaderService {
|
|||||||
logToFile(
|
logToFile(
|
||||||
`Media Service | downloaded: ${mediaType}, path:${downloadPath} url:${url}`,
|
`Media Service | downloaded: ${mediaType}, path:${downloadPath} url:${url}`,
|
||||||
);
|
);
|
||||||
downloadedImages.push({ type: mediaType, path: filename });
|
downloadedImages.push({
|
||||||
|
type: mediaType,
|
||||||
|
path: filename,
|
||||||
|
tmdb_path: media.file_path,
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
logToFile(
|
logToFile(
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ async function saveEntry(data) {
|
|||||||
mediaableId: savedEntry.id,
|
mediaableId: savedEntry.id,
|
||||||
type: image.type,
|
type: image.type,
|
||||||
path: image.path,
|
path: image.path,
|
||||||
|
tmdbPath: image.tmdb_path || null,
|
||||||
isLocal: true,
|
isLocal: true,
|
||||||
isSelected: true,
|
isSelected: true,
|
||||||
});
|
});
|
||||||
@@ -519,6 +520,7 @@ async function refrechEntry(entryId) {
|
|||||||
mediaableId: oldEntry.id,
|
mediaableId: oldEntry.id,
|
||||||
type: image.type,
|
type: image.type,
|
||||||
path: image.path,
|
path: image.path,
|
||||||
|
tmdbPath: image.tmdb_path || null,
|
||||||
isLocal: true,
|
isLocal: true,
|
||||||
isSelected: true,
|
isSelected: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ class PeopleManager {
|
|||||||
mediaableId: person.id,
|
mediaableId: person.id,
|
||||||
type: image.type,
|
type: image.type,
|
||||||
path: image.path,
|
path: image.path,
|
||||||
|
tmdbPath: image.tmdb_path || null,
|
||||||
isLocal: true,
|
isLocal: true,
|
||||||
isSelected: true,
|
isSelected: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ import type {
|
|||||||
TmdbPreview,
|
TmdbPreview,
|
||||||
TmdbEntry,
|
TmdbEntry,
|
||||||
TmdbPaginatedResponse,
|
TmdbPaginatedResponse,
|
||||||
|
ArtworkResponse,
|
||||||
|
ArtworkType,
|
||||||
|
Media,
|
||||||
} from "@/types";
|
} from "@/types";
|
||||||
|
|
||||||
export const entriesApi = {
|
export const entriesApi = {
|
||||||
@@ -69,6 +72,24 @@ export const entriesApi = {
|
|||||||
.get<TmdbPaginatedResponse<TmdbEntry>>(`/entries/${id}/recommendations`)
|
.get<TmdbPaginatedResponse<TmdbEntry>>(`/entries/${id}/recommendations`)
|
||||||
.then((r) => r.data),
|
.then((r) => r.data),
|
||||||
|
|
||||||
|
getTmdbRecommendations: (type: "movie" | "tv", tmdbId: number) =>
|
||||||
|
api
|
||||||
|
.get<TmdbPaginatedResponse<TmdbEntry>>(
|
||||||
|
`/entries/tmdb/recommendations/${type}/${tmdbId}`,
|
||||||
|
)
|
||||||
|
.then((r) => r.data),
|
||||||
|
|
||||||
|
getArtwork: (id: number) =>
|
||||||
|
api.get<ArtworkResponse>(`/entries/${id}/artwork`).then((r) => r.data),
|
||||||
|
|
||||||
|
getTmdbArtwork: (type: "movie" | "tv", tmdbId: number) =>
|
||||||
|
api
|
||||||
|
.get<ArtworkResponse>(`/entries/tmdb/artwork/${type}/${tmdbId}`)
|
||||||
|
.then((r) => r.data),
|
||||||
|
|
||||||
|
addArtwork: (id: number, data: { type: ArtworkType; file_path: string }) =>
|
||||||
|
api.post<Media>(`/entries/${id}/artwork`, data).then((r) => r.data),
|
||||||
|
|
||||||
syncSeries: () => api.get("/entries/sync-series").then((r) => r.data),
|
syncSeries: () => api.get("/entries/sync-series").then((r) => r.data),
|
||||||
|
|
||||||
previewTmdb: (tmdbId: number, type: "movie" | "tv") =>
|
previewTmdb: (tmdbId: number, type: "movie" | "tv") =>
|
||||||
|
|||||||
@@ -0,0 +1,445 @@
|
|||||||
|
import { useEffect, useMemo, useState } from "react";
|
||||||
|
import { Check, Download, Loader2, Star } from "lucide-react";
|
||||||
|
import { useAddArtwork, useArtwork } from "@/hooks/useEntries";
|
||||||
|
import { getMediaUrl, getTmdbImageUrl } from "@/lib/api";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
|
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||||
|
import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog";
|
||||||
|
import type { ArtworkItem, ArtworkType } from "@/types";
|
||||||
|
|
||||||
|
// Rows shown at first and added per "Show more"
|
||||||
|
const ROWS_STEP = 2;
|
||||||
|
// Checkerboard behind logos so transparent/dark logos stay visible
|
||||||
|
const CHECKER =
|
||||||
|
"bg-[repeating-conic-gradient(#8883_0_25%,transparent_0_50%)] bg-size-[16px_16px]";
|
||||||
|
|
||||||
|
const TYPES: {
|
||||||
|
type: ArtworkType;
|
||||||
|
key: "posters" | "backdrops" | "logos";
|
||||||
|
label: string;
|
||||||
|
thumbSize: string;
|
||||||
|
grid: string;
|
||||||
|
/** Columns per breakpoint; must match `grid` */
|
||||||
|
cols: { base: number; sm?: number; md?: number; xl?: number };
|
||||||
|
aspect: string;
|
||||||
|
}[] = [
|
||||||
|
{
|
||||||
|
type: "poster",
|
||||||
|
key: "posters",
|
||||||
|
label: "Posters",
|
||||||
|
thumbSize: "w342",
|
||||||
|
grid: "grid-cols-3 sm:grid-cols-4 md:grid-cols-5 xl:grid-cols-6",
|
||||||
|
cols: { base: 3, sm: 4, md: 5, xl: 6 },
|
||||||
|
aspect: "aspect-2/3",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "backdrop",
|
||||||
|
key: "backdrops",
|
||||||
|
label: "Backdrops",
|
||||||
|
thumbSize: "w780",
|
||||||
|
grid: "grid-cols-1 sm:grid-cols-2 xl:grid-cols-3",
|
||||||
|
cols: { base: 1, sm: 2, xl: 3 },
|
||||||
|
aspect: "aspect-video",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "logo",
|
||||||
|
key: "logos",
|
||||||
|
label: "Logos",
|
||||||
|
thumbSize: "w500",
|
||||||
|
grid: "grid-cols-2 sm:grid-cols-3 xl:grid-cols-4",
|
||||||
|
cols: { base: 2, sm: 3, xl: 4 },
|
||||||
|
aspect: "aspect-[2/1]",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const languageName = (() => {
|
||||||
|
try {
|
||||||
|
const names = new Intl.DisplayNames(["en"], { type: "language" });
|
||||||
|
return (code: string) => names.of(code) ?? code;
|
||||||
|
} catch {
|
||||||
|
return (code: string) => code;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
function imageUrls(item: ArtworkItem, type: ArtworkType, thumbSize: string) {
|
||||||
|
if (item.file_path) {
|
||||||
|
return {
|
||||||
|
thumb: getTmdbImageUrl(item.file_path, thumbSize),
|
||||||
|
full: getTmdbImageUrl(item.file_path, "original"),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const folder = `${type}s`;
|
||||||
|
return {
|
||||||
|
thumb: getMediaUrl("entries", folder, "preview", item.media_path!),
|
||||||
|
full: getMediaUrl("entries", folder, "full", item.media_path!),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const BREAKPOINTS = [
|
||||||
|
["xl", 1280],
|
||||||
|
["md", 768],
|
||||||
|
["sm", 640],
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
/** Current column count for a grid, following the Tailwind breakpoints. */
|
||||||
|
function useGridColumns(cols: {
|
||||||
|
base: number;
|
||||||
|
sm?: number;
|
||||||
|
md?: number;
|
||||||
|
xl?: number;
|
||||||
|
}) {
|
||||||
|
const compute = () => {
|
||||||
|
for (const [bp, minWidth] of BREAKPOINTS) {
|
||||||
|
const value = cols[bp];
|
||||||
|
if (value && window.matchMedia(`(min-width: ${minWidth}px)`).matches) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cols.base;
|
||||||
|
};
|
||||||
|
const [columns, setColumns] = useState(compute);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const update = () => setColumns(compute());
|
||||||
|
update();
|
||||||
|
const queries = BREAKPOINTS.map(([, w]) =>
|
||||||
|
window.matchMedia(`(min-width: ${w}px)`),
|
||||||
|
);
|
||||||
|
queries.forEach((q) => q.addEventListener("change", update));
|
||||||
|
return () =>
|
||||||
|
queries.forEach((q) => q.removeEventListener("change", update));
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [cols.base, cols.sm, cols.md, cols.xl]);
|
||||||
|
|
||||||
|
return columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
const itemKey = (item: ArtworkItem) =>
|
||||||
|
item.file_path ?? `media-${item.media_id}`;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Posters, backdrops and logos from TMDB merged with the entry's media table.
|
||||||
|
* For library entries, TMDB images can be added (downloaded) to the library.
|
||||||
|
*/
|
||||||
|
export function ArtworkSection({
|
||||||
|
entryId = 0,
|
||||||
|
tmdbId = 0,
|
||||||
|
isTvSeries,
|
||||||
|
originalLanguage,
|
||||||
|
}: {
|
||||||
|
entryId?: number;
|
||||||
|
tmdbId?: number;
|
||||||
|
isTvSeries: boolean;
|
||||||
|
originalLanguage?: string | null;
|
||||||
|
}) {
|
||||||
|
const isLibrary = !!entryId;
|
||||||
|
const { data, isLoading, isError } = useArtwork(
|
||||||
|
isLibrary ? { entryId } : { tmdbId, type: isTvSeries ? "tv" : "movie" },
|
||||||
|
);
|
||||||
|
const addArtwork = useAddArtwork(entryId);
|
||||||
|
|
||||||
|
const [activeType, setActiveType] = useState<ArtworkType>("poster");
|
||||||
|
const [language, setLanguage] = useState("all");
|
||||||
|
const [libraryOnly, setLibraryOnly] = useState(false);
|
||||||
|
const [rows, setRows] = useState(ROWS_STEP);
|
||||||
|
const [pendingPath, setPendingPath] = useState<string | null>(null);
|
||||||
|
const [viewing, setViewing] = useState<ArtworkItem | null>(null);
|
||||||
|
|
||||||
|
const config = TYPES.find((t) => t.type === activeType)!;
|
||||||
|
const columns = useGridColumns(config.cols);
|
||||||
|
const visible = columns * rows;
|
||||||
|
const items = useMemo(() => data?.[config.key] ?? [], [data, config.key]);
|
||||||
|
|
||||||
|
// Languages present for this type, most common first ("none" = no text)
|
||||||
|
const languages = useMemo(() => {
|
||||||
|
const counts = new Map<string, number>();
|
||||||
|
for (const item of items) {
|
||||||
|
if (!item.file_path) continue;
|
||||||
|
const lang = item.language ?? "none";
|
||||||
|
counts.set(lang, (counts.get(lang) ?? 0) + 1);
|
||||||
|
}
|
||||||
|
const preferred = ["none", "en", originalLanguage].filter(Boolean);
|
||||||
|
return [...counts.entries()].sort(([a, ca], [b, cb]) => {
|
||||||
|
const pa = preferred.indexOf(a);
|
||||||
|
const pb = preferred.indexOf(b);
|
||||||
|
if (pa !== -1 || pb !== -1)
|
||||||
|
return (pa === -1 ? 99 : pa) - (pb === -1 ? 99 : pb);
|
||||||
|
return cb - ca;
|
||||||
|
});
|
||||||
|
}, [items, originalLanguage]);
|
||||||
|
|
||||||
|
const filtered = items.filter((item) => {
|
||||||
|
if (libraryOnly && !item.in_library) return false;
|
||||||
|
if (language === "all" || !item.file_path) return true;
|
||||||
|
return (item.language ?? "none") === language;
|
||||||
|
});
|
||||||
|
|
||||||
|
const changeType = (type: ArtworkType) => {
|
||||||
|
setActiveType(type);
|
||||||
|
setLanguage("all");
|
||||||
|
setRows(ROWS_STEP);
|
||||||
|
};
|
||||||
|
|
||||||
|
const add = (item: ArtworkItem) => {
|
||||||
|
if (!item.file_path) return;
|
||||||
|
setPendingPath(item.file_path);
|
||||||
|
addArtwork.mutate(
|
||||||
|
{ type: activeType, file_path: item.file_path },
|
||||||
|
{
|
||||||
|
onSuccess: () =>
|
||||||
|
setViewing((v) =>
|
||||||
|
v?.file_path === item.file_path ? { ...v, in_library: true } : v,
|
||||||
|
),
|
||||||
|
onSettled: () => setPendingPath(null),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isError) return null;
|
||||||
|
|
||||||
|
const total = data
|
||||||
|
? data.posters.length + data.backdrops.length + data.logos.length
|
||||||
|
: 0;
|
||||||
|
if (!isLoading && total === 0) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section className="space-y-3">
|
||||||
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||||
|
<h3 className="text-lg font-semibold">Artwork</h3>
|
||||||
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
|
<select
|
||||||
|
value={language}
|
||||||
|
onChange={(e) => {
|
||||||
|
setLanguage(e.target.value);
|
||||||
|
setRows(ROWS_STEP);
|
||||||
|
}}
|
||||||
|
className="h-8 rounded-md border border-border/60 bg-background px-2 text-xs"
|
||||||
|
aria-label="Language"
|
||||||
|
>
|
||||||
|
<option value="all">All languages</option>
|
||||||
|
{languages.map(([lang, count]) => (
|
||||||
|
<option key={lang} value={lang}>
|
||||||
|
{lang === "none" ? "No text" : languageName(lang)} ({count})
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
{isLibrary && (
|
||||||
|
<Button
|
||||||
|
variant={libraryOnly ? "default" : "outline"}
|
||||||
|
size="sm"
|
||||||
|
aria-pressed={libraryOnly}
|
||||||
|
onClick={() => {
|
||||||
|
setLibraryOnly((v) => !v);
|
||||||
|
setRows(ROWS_STEP);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Check />
|
||||||
|
In library
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Tabs
|
||||||
|
value={activeType}
|
||||||
|
onValueChange={(v) => changeType(v as ArtworkType)}
|
||||||
|
>
|
||||||
|
<TabsList>
|
||||||
|
{TYPES.map((t) => (
|
||||||
|
<TabsTrigger key={t.type} value={t.type}>
|
||||||
|
{t.label}
|
||||||
|
{data && (
|
||||||
|
<span className="ml-1 text-muted-foreground tabular-nums">
|
||||||
|
{data[t.key].length}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</TabsTrigger>
|
||||||
|
))}
|
||||||
|
</TabsList>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
|
{isLoading ? (
|
||||||
|
<div className={`grid gap-3 ${config.grid}`}>
|
||||||
|
{Array.from({ length: columns * ROWS_STEP }).map((_, i) => (
|
||||||
|
<Skeleton key={i} className={`${config.aspect} rounded-lg`} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : filtered.length === 0 ? (
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
No {config.label.toLowerCase()} match these filters.
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div className={`grid gap-3 ${config.grid}`}>
|
||||||
|
{filtered.slice(0, visible).map((item) => (
|
||||||
|
<ArtworkTile
|
||||||
|
key={itemKey(item)}
|
||||||
|
item={item}
|
||||||
|
type={activeType}
|
||||||
|
thumbSize={config.thumbSize}
|
||||||
|
aspect={config.aspect}
|
||||||
|
canAdd={isLibrary}
|
||||||
|
adding={pendingPath === item.file_path}
|
||||||
|
onAdd={() => add(item)}
|
||||||
|
onOpen={() => setViewing(item)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
{filtered.length > visible && (
|
||||||
|
<div className="flex justify-center">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setRows((r) => r + ROWS_STEP)}
|
||||||
|
>
|
||||||
|
Show more ({filtered.length - visible} left)
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Dialog
|
||||||
|
open={!!viewing}
|
||||||
|
onOpenChange={(open) => !open && setViewing(null)}
|
||||||
|
>
|
||||||
|
<DialogContent className="w-auto max-w-[calc(100%-2rem)] sm:max-w-[calc(100%-2rem)] gap-3 p-3">
|
||||||
|
<DialogTitle className="sr-only">{config.label} preview</DialogTitle>
|
||||||
|
{viewing && (
|
||||||
|
<>
|
||||||
|
<img
|
||||||
|
src={imageUrls(viewing, activeType, config.thumbSize).full}
|
||||||
|
alt=""
|
||||||
|
className={`max-h-[80vh] max-w-full rounded-lg object-contain ${
|
||||||
|
activeType === "logo" ? `${CHECKER} p-4` : ""
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
<div className="flex flex-wrap items-center justify-between gap-2 text-xs text-muted-foreground">
|
||||||
|
<span>
|
||||||
|
{viewing.width && viewing.height
|
||||||
|
? `${viewing.width}×${viewing.height}`
|
||||||
|
: "Local file"}
|
||||||
|
{viewing.file_path &&
|
||||||
|
` · ${viewing.language ? languageName(viewing.language) : "No text"}`}
|
||||||
|
</span>
|
||||||
|
{viewing.in_library ? (
|
||||||
|
<LibraryBadge selected={viewing.is_selected} />
|
||||||
|
) : (
|
||||||
|
isLibrary &&
|
||||||
|
viewing.file_path && (
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
onClick={() => add(viewing)}
|
||||||
|
disabled={pendingPath === viewing.file_path}
|
||||||
|
>
|
||||||
|
{pendingPath === viewing.file_path ? (
|
||||||
|
<Loader2 className="animate-spin" />
|
||||||
|
) : (
|
||||||
|
<Download />
|
||||||
|
)}
|
||||||
|
Add to library
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function LibraryBadge({ selected }: { selected?: boolean }) {
|
||||||
|
return (
|
||||||
|
<span className="inline-flex items-center gap-1 rounded-full bg-emerald-500/90 px-2 py-0.5 text-[10px] font-semibold text-white shadow">
|
||||||
|
<Check className="h-3 w-3" />
|
||||||
|
{selected ? "Selected" : "In library"}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ArtworkTile({
|
||||||
|
item,
|
||||||
|
type,
|
||||||
|
thumbSize,
|
||||||
|
aspect,
|
||||||
|
canAdd,
|
||||||
|
adding,
|
||||||
|
onAdd,
|
||||||
|
onOpen,
|
||||||
|
}: {
|
||||||
|
item: ArtworkItem;
|
||||||
|
type: ArtworkType;
|
||||||
|
thumbSize: string;
|
||||||
|
aspect: string;
|
||||||
|
canAdd: boolean;
|
||||||
|
adding: boolean;
|
||||||
|
onAdd: () => void;
|
||||||
|
onOpen: () => void;
|
||||||
|
}) {
|
||||||
|
const { thumb } = imageUrls(item, type, thumbSize);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`group relative overflow-hidden rounded-lg bg-muted ring-1 ${
|
||||||
|
item.in_library ? "ring-emerald-500/60" : "ring-border/60"
|
||||||
|
} ${aspect}`}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={onOpen}
|
||||||
|
className="block h-full w-full cursor-zoom-in"
|
||||||
|
aria-label="View full size"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={thumb}
|
||||||
|
alt=""
|
||||||
|
loading="lazy"
|
||||||
|
className={`h-full w-full transition-transform duration-300 group-hover:scale-[1.03] ${
|
||||||
|
type === "logo" ? `${CHECKER} object-contain p-3` : "object-cover"
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{/* Top: library badge / language */}
|
||||||
|
<div className="pointer-events-none absolute inset-x-1.5 top-1.5 flex items-start justify-between gap-1">
|
||||||
|
{item.in_library ? (
|
||||||
|
<LibraryBadge selected={item.is_selected} />
|
||||||
|
) : (
|
||||||
|
<span />
|
||||||
|
)}
|
||||||
|
{item.file_path && item.language && (
|
||||||
|
<span className="rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium uppercase text-white">
|
||||||
|
{item.language}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Bottom: votes + add */}
|
||||||
|
<div className="absolute inset-x-1.5 bottom-1.5 flex items-end justify-between gap-1 opacity-0 transition-opacity group-hover:opacity-100 focus-within:opacity-100">
|
||||||
|
{item.vote_count > 0 ? (
|
||||||
|
<span className="inline-flex items-center gap-0.5 rounded bg-black/60 px-1.5 py-0.5 text-[10px] text-white tabular-nums">
|
||||||
|
<Star className="h-2.5 w-2.5 fill-yellow-400 text-yellow-400" />
|
||||||
|
{item.vote_average.toFixed(1)}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span />
|
||||||
|
)}
|
||||||
|
{canAdd && !item.in_library && item.file_path && (
|
||||||
|
<Button
|
||||||
|
size="xs"
|
||||||
|
onClick={onAdd}
|
||||||
|
disabled={adding}
|
||||||
|
className="shadow"
|
||||||
|
aria-label="Add to library"
|
||||||
|
>
|
||||||
|
{adding ? <Loader2 className="animate-spin" /> : <Download />}
|
||||||
|
Add
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
import { useEntryRecommendations } from "@/hooks/useEntries";
|
import {
|
||||||
|
useEntryRecommendations,
|
||||||
|
useTmdbRecommendations,
|
||||||
|
} from "@/hooks/useEntries";
|
||||||
import { EntryCard } from "@/components/entries/EntryCard";
|
import { EntryCard } from "@/components/entries/EntryCard";
|
||||||
import { Skeleton } from "@/components/ui/skeleton";
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
|
|
||||||
@@ -6,15 +9,23 @@ const GRID =
|
|||||||
"grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-4 xl:grid-cols-6";
|
"grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-4 xl:grid-cols-6";
|
||||||
const MAX_ITEMS = 12;
|
const MAX_ITEMS = 12;
|
||||||
|
|
||||||
/** "More like this": live TMDB recommendations for a library entry. */
|
/**
|
||||||
|
* "More like this": live TMDB recommendations. Pass `entryId` for a library
|
||||||
|
* entry, or `tmdbId` for one that is not in the library.
|
||||||
|
*/
|
||||||
export function RecommendationsSection({
|
export function RecommendationsSection({
|
||||||
entryId,
|
entryId = 0,
|
||||||
|
tmdbId = 0,
|
||||||
isTvSeries,
|
isTvSeries,
|
||||||
}: {
|
}: {
|
||||||
entryId: number;
|
entryId?: number;
|
||||||
|
tmdbId?: number;
|
||||||
isTvSeries: boolean;
|
isTvSeries: boolean;
|
||||||
}) {
|
}) {
|
||||||
const { data, isLoading, isError } = useEntryRecommendations(entryId);
|
const type = isTvSeries ? "tv" : "movie";
|
||||||
|
const library = useEntryRecommendations(entryId);
|
||||||
|
const tmdb = useTmdbRecommendations(entryId ? 0 : tmdbId, type);
|
||||||
|
const { data, isLoading, isError } = entryId ? library : tmdb;
|
||||||
|
|
||||||
if (isError) return null;
|
if (isError) return null;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
|||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { entriesApi } from "@/api/entries";
|
import { entriesApi } from "@/api/entries";
|
||||||
import { useLibraryStore } from "@/stores/useLibraryStore";
|
import { useLibraryStore } from "@/stores/useLibraryStore";
|
||||||
import type { Entry } from "@/types";
|
import type { ArtworkType, Entry } from "@/types";
|
||||||
|
|
||||||
export const entryKeys = {
|
export const entryKeys = {
|
||||||
all: ["entries"] as const,
|
all: ["entries"] as const,
|
||||||
@@ -10,6 +10,11 @@ export const entryKeys = {
|
|||||||
seasons: (id: number) => ["entries", id, "seasons"] as const,
|
seasons: (id: number) => ["entries", id, "seasons"] as const,
|
||||||
credits: (id: number) => ["entries", id, "credits"] as const,
|
credits: (id: number) => ["entries", id, "credits"] as const,
|
||||||
recommendations: (id: number) => ["entries", id, "recommendations"] as const,
|
recommendations: (id: number) => ["entries", id, "recommendations"] as const,
|
||||||
|
artwork: (id: number) => ["entries", id, "artwork"] as const,
|
||||||
|
tmdbArtwork: (tmdbId: number, type: string) =>
|
||||||
|
["entries", "tmdb-artwork", type, tmdbId] as const,
|
||||||
|
tmdbRecommendations: (tmdbId: number, type: string) =>
|
||||||
|
["entries", "tmdb-recommendations", type, tmdbId] as const,
|
||||||
tmdbPreview: (tmdbId: number, type: string) =>
|
tmdbPreview: (tmdbId: number, type: string) =>
|
||||||
["entries", "tmdb-preview", type, tmdbId] as const,
|
["entries", "tmdb-preview", type, tmdbId] as const,
|
||||||
};
|
};
|
||||||
@@ -53,6 +58,52 @@ export function useEntryRecommendations(id: number) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useTmdbRecommendations(
|
||||||
|
tmdbId: number,
|
||||||
|
type: "movie" | "tv",
|
||||||
|
) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: entryKeys.tmdbRecommendations(tmdbId, type),
|
||||||
|
queryFn: () => entriesApi.getTmdbRecommendations(type, tmdbId),
|
||||||
|
enabled: !!tmdbId,
|
||||||
|
staleTime: 30 * 60 * 1000,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Artwork for a library entry (TMDB + media table), or by TMDB id otherwise. */
|
||||||
|
export function useArtwork(
|
||||||
|
source: { entryId: number } | { tmdbId: number; type: "movie" | "tv" },
|
||||||
|
) {
|
||||||
|
const isLibrary = "entryId" in source;
|
||||||
|
return useQuery({
|
||||||
|
queryKey: isLibrary
|
||||||
|
? entryKeys.artwork(source.entryId)
|
||||||
|
: entryKeys.tmdbArtwork(source.tmdbId, source.type),
|
||||||
|
queryFn: () =>
|
||||||
|
isLibrary
|
||||||
|
? entriesApi.getArtwork(source.entryId)
|
||||||
|
: entriesApi.getTmdbArtwork(source.type, source.tmdbId),
|
||||||
|
enabled: isLibrary ? !!source.entryId : !!source.tmdbId,
|
||||||
|
staleTime: 10 * 60 * 1000,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useAddArtwork(entryId: number) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (data: { type: ArtworkType; file_path: string }) =>
|
||||||
|
entriesApi.addArtwork(entryId, data),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({ queryKey: entryKeys.artwork(entryId) });
|
||||||
|
queryClient.invalidateQueries({ queryKey: entryKeys.detail(entryId) });
|
||||||
|
queryClient.invalidateQueries({ queryKey: entryKeys.all, exact: true });
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error("Failed to add artwork");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function useEntryCredits(id: number) {
|
export function useEntryCredits(id: number) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: entryKeys.credits(id),
|
queryKey: entryKeys.credits(id),
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ interface TmdbEntryLink {
|
|||||||
/**
|
/**
|
||||||
* Resolves the correct navigation link for a TmdbEntry.
|
* Resolves the correct navigation link for a TmdbEntry.
|
||||||
* If the entry is already in the library, links directly to EntryDetailsPage.
|
* If the entry is already in the library, links directly to EntryDetailsPage.
|
||||||
* Otherwise, links to the TmdbPreviewPage.
|
* Otherwise, links to the TMDB preview of the entry details page.
|
||||||
*/
|
*/
|
||||||
export function useTmdbEntryLink(entry: TmdbEntry): TmdbEntryLink {
|
export function useTmdbEntryLink(entry: TmdbEntry): TmdbEntryLink {
|
||||||
const libraryEntries = useLibraryStore((s) => s.entries);
|
const libraryEntries = useLibraryStore((s) => s.entries);
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import {
|
|||||||
useEntrySeasons,
|
useEntrySeasons,
|
||||||
useRefreshEntry,
|
useRefreshEntry,
|
||||||
useEntryCredits,
|
useEntryCredits,
|
||||||
|
useTmdbPreview,
|
||||||
|
useCreateEntry,
|
||||||
} from "@/hooks/useEntries";
|
} from "@/hooks/useEntries";
|
||||||
import { useEntrySeenByEntry, useDeleteEntrySeen } from "@/hooks/useEntrySeen";
|
import { useEntrySeenByEntry, useDeleteEntrySeen } from "@/hooks/useEntrySeen";
|
||||||
import { useCollections } from "@/hooks/useCollections";
|
import { useCollections } from "@/hooks/useCollections";
|
||||||
@@ -44,6 +46,8 @@ import {
|
|||||||
DollarSign,
|
DollarSign,
|
||||||
ListVideo,
|
ListVideo,
|
||||||
CircleDot,
|
CircleDot,
|
||||||
|
Plus,
|
||||||
|
Loader2,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import {
|
import {
|
||||||
Tooltip,
|
Tooltip,
|
||||||
@@ -56,6 +60,7 @@ import { StreamingSection } from "@/components/streaming/StreamingSection";
|
|||||||
import { WatchProvidersCard } from "@/components/entries/WatchProvidersCard";
|
import { WatchProvidersCard } from "@/components/entries/WatchProvidersCard";
|
||||||
import { TrailerDialog } from "@/components/entries/TrailerDialog";
|
import { TrailerDialog } from "@/components/entries/TrailerDialog";
|
||||||
import { RecommendationsSection } from "@/components/entries/RecommendationsSection";
|
import { RecommendationsSection } from "@/components/entries/RecommendationsSection";
|
||||||
|
import { ArtworkSection } from "@/components/entries/ArtworkSection";
|
||||||
import { EntrySettingsDialog } from "@/components/dialogs/EntrySettingsDialog";
|
import { EntrySettingsDialog } from "@/components/dialogs/EntrySettingsDialog";
|
||||||
import { EntrySeenDialog } from "@/components/dialogs/EntrySeenDialog";
|
import { EntrySeenDialog } from "@/components/dialogs/EntrySeenDialog";
|
||||||
import { EntryMediaDialog } from "@/components/dialogs/EntryMediaDialog";
|
import { EntryMediaDialog } from "@/components/dialogs/EntryMediaDialog";
|
||||||
@@ -81,7 +86,13 @@ import {
|
|||||||
formatDate,
|
formatDate,
|
||||||
} from "@/lib/media-utils";
|
} from "@/lib/media-utils";
|
||||||
import { useUpdateEntry, useDeleteEntry } from "@/hooks/useEntries";
|
import { useUpdateEntry, useDeleteEntry } from "@/hooks/useEntries";
|
||||||
import type { Collection, Entry, EntrySeen } from "@/types";
|
import type {
|
||||||
|
Collection,
|
||||||
|
Credit,
|
||||||
|
Entry,
|
||||||
|
EntrySeen,
|
||||||
|
TmdbPreviewSeason,
|
||||||
|
} from "@/types";
|
||||||
|
|
||||||
const WATCH_STATUSES = [
|
const WATCH_STATUSES = [
|
||||||
{
|
{
|
||||||
@@ -138,25 +149,60 @@ const languageName = (() => {
|
|||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entry details for both sources:
|
||||||
|
* - `/entry/:id`: a library entry, loaded from the local DB.
|
||||||
|
* - `/entry/tmdb/:type/:tmdbId`: not in the library; everything comes from
|
||||||
|
* the TMDB preview (same shape), and library-only actions are hidden. If
|
||||||
|
* the title is already in the library, redirect to its page.
|
||||||
|
*/
|
||||||
export function EntryDetailsPage() {
|
export function EntryDetailsPage() {
|
||||||
const { id } = useParams<{ id: string }>();
|
const { id, type, tmdbId } = useParams<{
|
||||||
const entryId = parseInt(id!, 10);
|
id?: string;
|
||||||
|
type?: string;
|
||||||
|
tmdbId?: string;
|
||||||
|
}>();
|
||||||
|
const entryId = id ? parseInt(id, 10) : 0;
|
||||||
|
const isLibrary = !!entryId;
|
||||||
|
const previewTmdbId = !isLibrary && tmdbId ? parseInt(tmdbId, 10) : 0;
|
||||||
|
const previewType = type === "tv" ? "tv" : "movie";
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
// Library queries are disabled when entryId is 0, the preview when tmdbId is 0
|
||||||
const { data: entry, isLoading } = useEntry(entryId);
|
const { data: entry, isLoading } = useEntry(entryId);
|
||||||
const { data: seasons } = useEntrySeasons(entryId);
|
const { data: seasons } = useEntrySeasons(entryId);
|
||||||
const { data: allCredits = [] } = useEntryCredits(entryId);
|
const { data: allCredits = [] } = useEntryCredits(entryId);
|
||||||
const { data: watchHistory = [] } = useEntrySeenByEntry(entryId);
|
const { data: watchHistory = [] } = useEntrySeenByEntry(entryId);
|
||||||
|
const {
|
||||||
|
data: preview,
|
||||||
|
isLoading: previewLoading,
|
||||||
|
isError: previewError,
|
||||||
|
} = useTmdbPreview(previewTmdbId, previewType);
|
||||||
const updateEntry = useUpdateEntry();
|
const updateEntry = useUpdateEntry();
|
||||||
const refreshEntry = useRefreshEntry();
|
const refreshEntry = useRefreshEntry();
|
||||||
const deleteEntrySeen = useDeleteEntrySeen();
|
const deleteEntrySeen = useDeleteEntrySeen();
|
||||||
const deleteEntry = useDeleteEntry();
|
const deleteEntry = useDeleteEntry();
|
||||||
|
const createEntry = useCreateEntry();
|
||||||
|
|
||||||
// Merge library entry with detail entry so we get both library flags AND full details (credits, etc.)
|
// Merge library entry with detail entry so we get both library flags AND full details (credits, etc.)
|
||||||
const libraryEntry = useLibraryStore((s) => s.entries.get(entryId));
|
const libraryEntry = useLibraryStore((s) => s.entries.get(entryId));
|
||||||
const displayEntry =
|
const libraryMatch = useLibraryStore((s) => {
|
||||||
libraryEntry && entry
|
if (!previewTmdbId) return null;
|
||||||
|
for (const le of s.entries.values()) {
|
||||||
|
if (le.entryIds?.tmdb_id === previewTmdbId) return le;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
const displayEntry: Entry | undefined = isLibrary
|
||||||
|
? libraryEntry && entry
|
||||||
? { ...libraryEntry, ...entry, isInLibrary: true }
|
? { ...libraryEntry, ...entry, isInLibrary: true }
|
||||||
: entry || libraryEntry;
|
: entry || libraryEntry
|
||||||
|
: preview?.entry;
|
||||||
|
|
||||||
|
// Already in the library: show the library page instead of the preview
|
||||||
|
useEffect(() => {
|
||||||
|
if (libraryMatch) navigate(`/entry/${libraryMatch.id}`, { replace: true });
|
||||||
|
}, [libraryMatch, navigate]);
|
||||||
|
|
||||||
const [showSettings, setShowSettings] = useState(false);
|
const [showSettings, setShowSettings] = useState(false);
|
||||||
const [showSeenDialog, setShowSeenDialog] = useState(false);
|
const [showSeenDialog, setShowSeenDialog] = useState(false);
|
||||||
@@ -175,24 +221,59 @@ export function EntryDetailsPage() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (displayEntry) {
|
if (displayEntry) {
|
||||||
addRecentlyViewed({
|
addRecentlyViewed({
|
||||||
id: `lib-${entryId}`,
|
id: isLibrary ? `lib-${entryId}` : `tmdb-${previewTmdbId}`,
|
||||||
title: displayEntry.title,
|
title: displayEntry.title,
|
||||||
type: displayEntry.is_tvseries ? "tv" : "movie",
|
type: displayEntry.is_tvseries ? "tv" : "movie",
|
||||||
poster_path: displayEntry.poster_path,
|
poster_path: displayEntry.poster_path,
|
||||||
libraryId: entryId,
|
libraryId: isLibrary ? entryId : undefined,
|
||||||
tmdbId: displayEntry.entryIds?.tmdb_id ?? undefined,
|
tmdbId: displayEntry.entryIds?.tmdb_id ?? undefined,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [entryId, displayEntry?.title]);
|
}, [entryId, previewTmdbId, displayEntry?.title]);
|
||||||
|
|
||||||
if (isLoading || !displayEntry) {
|
if (!isLibrary && previewError) {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col items-center justify-center gap-4 py-20">
|
||||||
|
<p className="text-muted-foreground">Could not load entry from TMDB.</p>
|
||||||
|
<Button variant="outline" onClick={() => navigate(-1)}>
|
||||||
|
Go back
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
(isLibrary ? isLoading : previewLoading) ||
|
||||||
|
!displayEntry ||
|
||||||
|
libraryMatch
|
||||||
|
) {
|
||||||
return <EntryDetailsSkeleton />;
|
return <EntryDetailsSkeleton />;
|
||||||
}
|
}
|
||||||
|
|
||||||
const e = displayEntry;
|
const e = displayEntry;
|
||||||
// Use useEntryCredits (allCredits) which includes both cast AND crew (director).
|
// Library: useEntryCredits (allCredits) includes both cast AND crew (director);
|
||||||
// e.credits from useEntry is a limited preview (10 items).
|
// e.credits from useEntry is a limited preview (10 items).
|
||||||
const credits = allCredits.length > 0 ? allCredits : e.credits || [];
|
// Preview: the TMDB preview's cast + directors, linked by TMDB id.
|
||||||
|
const credits: Credit[] = isLibrary
|
||||||
|
? allCredits.length > 0
|
||||||
|
? allCredits
|
||||||
|
: e.credits || []
|
||||||
|
: ((preview?.credits ?? []) as unknown as Credit[]);
|
||||||
|
const previewSeasons = isLibrary ? [] : (preview?.seasons ?? []);
|
||||||
|
const seasonCount = isLibrary
|
||||||
|
? (seasons?.length ?? 0)
|
||||||
|
: previewSeasons.length;
|
||||||
|
const tmdbType = e.is_tvseries ? "tv" : "movie";
|
||||||
|
|
||||||
|
const addToLibrary = () => {
|
||||||
|
createEntry.mutate(
|
||||||
|
{ tmdb_id: previewTmdbId, is_tvserie: e.is_tvseries },
|
||||||
|
{
|
||||||
|
onSuccess: (newEntry) =>
|
||||||
|
navigate(`/entry/${newEntry.id}`, { replace: true }),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
const backdrop = getBackdropUrl(e);
|
const backdrop = getBackdropUrl(e);
|
||||||
const poster = getPosterUrl(e);
|
const poster = getPosterUrl(e);
|
||||||
const director = credits.find(
|
const director = credits.find(
|
||||||
@@ -289,7 +370,7 @@ export function EntryDetailsPage() {
|
|||||||
{e.status}
|
{e.status}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{e.is_tvseries && (
|
{e.is_tvseries && isLibrary && (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setShowStatusDialog(true)}
|
onClick={() => setShowStatusDialog(true)}
|
||||||
@@ -339,10 +420,9 @@ export function EntryDetailsPage() {
|
|||||||
{e.runtime && !e.is_tvseries && (
|
{e.runtime && !e.is_tvseries && (
|
||||||
<MetaItem>{formatRuntime(e.runtime)}</MetaItem>
|
<MetaItem>{formatRuntime(e.runtime)}</MetaItem>
|
||||||
)}
|
)}
|
||||||
{e.is_tvseries && seasons && seasons.length > 0 && (
|
{e.is_tvseries && seasonCount > 0 && (
|
||||||
<MetaItem>
|
<MetaItem>
|
||||||
{seasons.length}{" "}
|
{seasonCount} {seasonCount === 1 ? "season" : "seasons"}
|
||||||
{seasons.length === 1 ? "season" : "seasons"}
|
|
||||||
</MetaItem>
|
</MetaItem>
|
||||||
)}
|
)}
|
||||||
{e.is_tvseries && e.created_by && e.created_by.length > 0 && (
|
{e.is_tvseries && e.created_by && e.created_by.length > 0 && (
|
||||||
@@ -365,7 +445,11 @@ export function EntryDetailsPage() {
|
|||||||
<MetaItem>
|
<MetaItem>
|
||||||
Directed by{" "}
|
Directed by{" "}
|
||||||
<Link
|
<Link
|
||||||
to={`/people/${director.people_id}`}
|
to={
|
||||||
|
isLibrary
|
||||||
|
? `/people/${director.people_id}`
|
||||||
|
: `/people/tmdb/${director.people_id}`
|
||||||
|
}
|
||||||
className="font-medium text-foreground hover:underline"
|
className="font-medium text-foreground hover:underline"
|
||||||
>
|
>
|
||||||
{director.people.name}
|
{director.people.name}
|
||||||
@@ -391,7 +475,23 @@ export function EntryDetailsPage() {
|
|||||||
|
|
||||||
{/* Actions */}
|
{/* Actions */}
|
||||||
<div className="flex flex-wrap items-center justify-center gap-2 pt-1 sm:justify-start">
|
<div className="flex flex-wrap items-center justify-center gap-2 pt-1 sm:justify-start">
|
||||||
<StreamingSection entry={e} seasons={seasons} />
|
{isLibrary ? (
|
||||||
|
<StreamingSection entry={e} seasons={seasons} />
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
size="lg"
|
||||||
|
onClick={addToLibrary}
|
||||||
|
disabled={createEntry.isPending}
|
||||||
|
className="h-11 gap-2 px-6 text-sm font-medium"
|
||||||
|
>
|
||||||
|
{createEntry.isPending ? (
|
||||||
|
<Loader2 className="h-4 w-4 animate-spin" />
|
||||||
|
) : (
|
||||||
|
<Plus className="h-4 w-4" />
|
||||||
|
)}
|
||||||
|
{createEntry.isPending ? "Adding..." : "Add to Library"}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
{videos.length > 0 ? (
|
{videos.length > 0 ? (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -413,114 +513,116 @@ export function EntryDetailsPage() {
|
|||||||
</a>
|
</a>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="flex items-center gap-1.5">
|
{isLibrary && (
|
||||||
<IconAction
|
<div className="flex items-center gap-1.5">
|
||||||
label="Mark as watched"
|
<IconAction
|
||||||
onClick={() => setShowSeenDialog(true)}
|
label="Mark as watched"
|
||||||
>
|
onClick={() => setShowSeenDialog(true)}
|
||||||
<Eye className="h-4 w-4" />
|
|
||||||
</IconAction>
|
|
||||||
<IconAction
|
|
||||||
label={userRating > 0 ? "Change rating" : "Rate this"}
|
|
||||||
onClick={() => setShowRatingDialog(true)}
|
|
||||||
active={userRating > 0}
|
|
||||||
>
|
|
||||||
<Star
|
|
||||||
className={`h-4 w-4 ${userRating > 0 ? "fill-yellow-400 text-yellow-400" : ""}`}
|
|
||||||
/>
|
|
||||||
</IconAction>
|
|
||||||
<IconAction
|
|
||||||
label={
|
|
||||||
e.favorit ? "Remove from favorites" : "Add to favorites"
|
|
||||||
}
|
|
||||||
onClick={toggleFavorite}
|
|
||||||
disabled={updateEntry.isPending}
|
|
||||||
active={e.favorit}
|
|
||||||
>
|
|
||||||
<Heart
|
|
||||||
className={`h-4 w-4 ${e.favorit ? "fill-red-500 text-red-500" : ""}`}
|
|
||||||
/>
|
|
||||||
</IconAction>
|
|
||||||
<IconAction
|
|
||||||
label="Add to collection"
|
|
||||||
onClick={() => setShowCollectionDialog(true)}
|
|
||||||
>
|
|
||||||
<FolderPlus className="h-4 w-4" />
|
|
||||||
</IconAction>
|
|
||||||
|
|
||||||
<DropdownMenu>
|
|
||||||
<DropdownMenuTrigger
|
|
||||||
render={
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon-lg"
|
|
||||||
className="h-11 w-11 rounded-full border-border/60 bg-background/60 backdrop-blur"
|
|
||||||
aria-label="More actions"
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<MoreHorizontal className="h-4 w-4" />
|
<Eye className="h-4 w-4" />
|
||||||
</DropdownMenuTrigger>
|
</IconAction>
|
||||||
<DropdownMenuContent align="end" className="w-56">
|
<IconAction
|
||||||
{e.is_tvseries ? (
|
label={userRating > 0 ? "Change rating" : "Rate this"}
|
||||||
<DropdownMenuItem
|
onClick={() => setShowRatingDialog(true)}
|
||||||
onClick={() => setShowStatusDialog(true)}
|
active={userRating > 0}
|
||||||
>
|
>
|
||||||
<BookmarkCheck className="mr-2 h-4 w-4" />
|
<Star
|
||||||
Set status
|
className={`h-4 w-4 ${userRating > 0 ? "fill-yellow-400 text-yellow-400" : ""}`}
|
||||||
</DropdownMenuItem>
|
/>
|
||||||
) : (
|
</IconAction>
|
||||||
<DropdownMenuItem
|
<IconAction
|
||||||
onClick={() => setShowWatchHistoryDialog(true)}
|
label={
|
||||||
>
|
e.favorit ? "Remove from favorites" : "Add to favorites"
|
||||||
<History className="mr-2 h-4 w-4" />
|
}
|
||||||
Watch history
|
onClick={toggleFavorite}
|
||||||
</DropdownMenuItem>
|
disabled={updateEntry.isPending}
|
||||||
)}
|
active={e.favorit}
|
||||||
<DropdownMenuItem
|
>
|
||||||
onClick={() =>
|
<Heart
|
||||||
updateEntry.mutate({
|
className={`h-4 w-4 ${e.favorit ? "fill-red-500 text-red-500" : ""}`}
|
||||||
id: e.id,
|
/>
|
||||||
data: { hidden: !e.hidden },
|
</IconAction>
|
||||||
})
|
<IconAction
|
||||||
|
label="Add to collection"
|
||||||
|
onClick={() => setShowCollectionDialog(true)}
|
||||||
|
>
|
||||||
|
<FolderPlus className="h-4 w-4" />
|
||||||
|
</IconAction>
|
||||||
|
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger
|
||||||
|
render={
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon-lg"
|
||||||
|
className="h-11 w-11 rounded-full border-border/60 bg-background/60 backdrop-blur"
|
||||||
|
aria-label="More actions"
|
||||||
|
/>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<EyeOff className="mr-2 h-4 w-4" />
|
<MoreHorizontal className="h-4 w-4" />
|
||||||
{e.hidden ? "Unhide" : "Hide"}
|
</DropdownMenuTrigger>
|
||||||
</DropdownMenuItem>
|
<DropdownMenuContent align="end" className="w-56">
|
||||||
<DropdownMenuSeparator />
|
{e.is_tvseries ? (
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => refreshEntry.mutate(e.id)}
|
onClick={() => setShowStatusDialog(true)}
|
||||||
disabled={refreshEntry.isPending}
|
>
|
||||||
>
|
<BookmarkCheck className="mr-2 h-4 w-4" />
|
||||||
<RefreshCw
|
Set status
|
||||||
className={`mr-2 h-4 w-4 ${refreshEntry.isPending ? "animate-spin" : ""}`}
|
</DropdownMenuItem>
|
||||||
/>
|
) : (
|
||||||
{refreshEntry.isPending
|
<DropdownMenuItem
|
||||||
? "Refreshing..."
|
onClick={() => setShowWatchHistoryDialog(true)}
|
||||||
: "Refresh details"}
|
>
|
||||||
</DropdownMenuItem>
|
<History className="mr-2 h-4 w-4" />
|
||||||
<DropdownMenuItem
|
Watch history
|
||||||
onClick={() => setShowMediaDialog(true)}
|
</DropdownMenuItem>
|
||||||
>
|
)}
|
||||||
<ImageIcon className="mr-2 h-4 w-4" />
|
<DropdownMenuItem
|
||||||
Manage media
|
onClick={() =>
|
||||||
</DropdownMenuItem>
|
updateEntry.mutate({
|
||||||
<DropdownMenuItem onClick={() => setShowSettings(true)}>
|
id: e.id,
|
||||||
<Settings className="mr-2 h-4 w-4" />
|
data: { hidden: !e.hidden },
|
||||||
Settings
|
})
|
||||||
</DropdownMenuItem>
|
}
|
||||||
<DropdownMenuSeparator />
|
>
|
||||||
<DropdownMenuItem
|
<EyeOff className="mr-2 h-4 w-4" />
|
||||||
className="text-destructive focus:text-destructive"
|
{e.hidden ? "Unhide" : "Hide"}
|
||||||
onClick={() => setShowDeleteConfirm(true)}
|
</DropdownMenuItem>
|
||||||
>
|
<DropdownMenuSeparator />
|
||||||
<Trash2 className="mr-2 h-4 w-4" />
|
<DropdownMenuItem
|
||||||
Delete entry
|
onClick={() => refreshEntry.mutate(e.id)}
|
||||||
</DropdownMenuItem>
|
disabled={refreshEntry.isPending}
|
||||||
</DropdownMenuContent>
|
>
|
||||||
</DropdownMenu>
|
<RefreshCw
|
||||||
</div>
|
className={`mr-2 h-4 w-4 ${refreshEntry.isPending ? "animate-spin" : ""}`}
|
||||||
|
/>
|
||||||
|
{refreshEntry.isPending
|
||||||
|
? "Refreshing..."
|
||||||
|
: "Refresh details"}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => setShowMediaDialog(true)}
|
||||||
|
>
|
||||||
|
<ImageIcon className="mr-2 h-4 w-4" />
|
||||||
|
Manage media
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem onClick={() => setShowSettings(true)}>
|
||||||
|
<Settings className="mr-2 h-4 w-4" />
|
||||||
|
Settings
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
<DropdownMenuItem
|
||||||
|
className="text-destructive focus:text-destructive"
|
||||||
|
onClick={() => setShowDeleteConfirm(true)}
|
||||||
|
>
|
||||||
|
<Trash2 className="mr-2 h-4 w-4" />
|
||||||
|
Delete entry
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -556,24 +658,45 @@ export function EntryDetailsPage() {
|
|||||||
{credits.length > 0 && (
|
{credits.length > 0 && (
|
||||||
<CastList
|
<CastList
|
||||||
credits={credits}
|
credits={credits}
|
||||||
entryId={e.id}
|
entryId={isLibrary ? e.id : undefined}
|
||||||
isTvSeries={e.is_tvseries}
|
isTvSeries={e.is_tvseries}
|
||||||
maxItems={12}
|
maxItems={12}
|
||||||
|
allCastHref={
|
||||||
|
isLibrary
|
||||||
|
? undefined
|
||||||
|
: `/entry/tmdb/${tmdbType}/${previewTmdbId}/cast`
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{e.is_tvseries && seasons && seasons.length > 0 && (
|
{isLibrary && e.is_tvseries && seasons && seasons.length > 0 && (
|
||||||
<SeasonsContainer seasons={seasons} entryId={e.id} />
|
<SeasonsContainer seasons={seasons} entryId={e.id} />
|
||||||
)}
|
)}
|
||||||
|
{!isLibrary && e.is_tvseries && previewSeasons.length > 0 && (
|
||||||
|
<TmdbSeasonsStrip seasons={previewSeasons} />
|
||||||
|
)}
|
||||||
|
|
||||||
<EntryCollectionsSection entryId={e.id} />
|
{isLibrary && <EntryCollectionsSection entryId={e.id} />}
|
||||||
|
|
||||||
<RecommendationsSection entryId={e.id} isTvSeries={e.is_tvseries} />
|
<RecommendationsSection
|
||||||
|
entryId={isLibrary ? e.id : 0}
|
||||||
|
tmdbId={isLibrary ? 0 : previewTmdbId}
|
||||||
|
isTvSeries={e.is_tvseries}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ArtworkSection
|
||||||
|
entryId={isLibrary ? e.id : 0}
|
||||||
|
tmdbId={isLibrary ? 0 : previewTmdbId}
|
||||||
|
isTvSeries={e.is_tvseries}
|
||||||
|
originalLanguage={e.original_language}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* ── Sidebar ── */}
|
{/* ── Sidebar ── */}
|
||||||
<aside className="space-y-4 lg:sticky lg:top-6 lg:self-start">
|
<aside className="space-y-4 lg:sticky lg:top-6 lg:self-start">
|
||||||
<div className="grid grid-cols-3 gap-2">
|
<div
|
||||||
|
className={`grid gap-2 ${isLibrary ? "grid-cols-3" : "grid-cols-2"}`}
|
||||||
|
>
|
||||||
<RatingTile
|
<RatingTile
|
||||||
label="IMDb"
|
label="IMDb"
|
||||||
value={
|
value={
|
||||||
@@ -597,13 +720,15 @@ export function EntryDetailsPage() {
|
|||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<RatingTile
|
{isLibrary && (
|
||||||
label="You"
|
<RatingTile
|
||||||
value={userRating > 0 ? String(userRating) : null}
|
label="You"
|
||||||
accent="text-primary"
|
value={userRating > 0 ? String(userRating) : null}
|
||||||
emptyLabel="Rate"
|
accent="text-primary"
|
||||||
onClick={() => setShowRatingDialog(true)}
|
emptyLabel="Rate"
|
||||||
/>
|
onClick={() => setShowRatingDialog(true)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="rounded-xl border border-border/60 bg-card/50 p-4">
|
<div className="rounded-xl border border-border/60 bg-card/50 p-4">
|
||||||
@@ -702,7 +827,7 @@ export function EntryDetailsPage() {
|
|||||||
{e.country}
|
{e.country}
|
||||||
</DetailRow>
|
</DetailRow>
|
||||||
)}
|
)}
|
||||||
{!e.is_tvseries && (
|
{isLibrary && !e.is_tvseries && (
|
||||||
<DetailRow icon={<Eye />} label="Watched">
|
<DetailRow icon={<Eye />} label="Watched">
|
||||||
{watchHistory.length > 0 ? (
|
{watchHistory.length > 0 ? (
|
||||||
<button
|
<button
|
||||||
@@ -1048,6 +1173,38 @@ function ExternalChip({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------- TMDB seasons (entries not in the library) ---------- */
|
||||||
|
function TmdbSeasonsStrip({ seasons }: { seasons: TmdbPreviewSeason[] }) {
|
||||||
|
return (
|
||||||
|
<Section title="Seasons">
|
||||||
|
<ScrollArea className="w-full">
|
||||||
|
<div className="flex gap-3 pb-4">
|
||||||
|
{seasons.map((s) => (
|
||||||
|
<div key={s.id} className="w-32 shrink-0 space-y-1.5">
|
||||||
|
<div className="aspect-2/3 overflow-hidden rounded-lg bg-muted ring-1 ring-border/60">
|
||||||
|
{s.poster_path && (
|
||||||
|
<img
|
||||||
|
src={getTmdbImageUrl(s.poster_path, "w342")}
|
||||||
|
alt={s.name}
|
||||||
|
loading="lazy"
|
||||||
|
className="h-full w-full object-cover"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<p className="line-clamp-1 text-sm font-medium">{s.name}</p>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
{s.episode_count} eps
|
||||||
|
{s.air_date && ` · ${getYear(s.air_date)}`}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<ScrollBar orientation="horizontal" />
|
||||||
|
</ScrollArea>
|
||||||
|
</Section>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/* ---------- Collections section ---------- */
|
/* ---------- Collections section ---------- */
|
||||||
function EntryCollectionsSection({ entryId }: { entryId: number }) {
|
function EntryCollectionsSection({ entryId }: { entryId: number }) {
|
||||||
const { data: allCollections = [], isLoading } = useCollections();
|
const { data: allCollections = [], isLoading } = useCollections();
|
||||||
|
|||||||
@@ -1,261 +0,0 @@
|
|||||||
import { useParams, useNavigate } from "react-router-dom";
|
|
||||||
import { useEffect } from "react";
|
|
||||||
import { useTmdbPreview, useCreateEntry } from "@/hooks/useEntries";
|
|
||||||
import { useLibraryStore } from "@/stores/useLibraryStore";
|
|
||||||
import { useCommandPaletteStore } from "@/stores/useCommandPaletteStore";
|
|
||||||
import { Badge } from "@/components/ui/badge";
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import { Separator } from "@/components/ui/separator";
|
|
||||||
import { Plus, Loader2, ExternalLink } from "lucide-react";
|
|
||||||
import { EntryDetailsSkeleton } from "@/components/skeletons/PageSkeletons";
|
|
||||||
import { CastList } from "@/components/entries/CastList";
|
|
||||||
import { getYear, formatRuntime } from "@/lib/media-utils";
|
|
||||||
import type { Credit } from "@/types";
|
|
||||||
|
|
||||||
const TMDB_IMG = "https://image.tmdb.org/t/p";
|
|
||||||
|
|
||||||
export function TmdbPreviewPage() {
|
|
||||||
const { type, tmdbId } = useParams<{ type: string; tmdbId: string }>();
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const tmdbIdNum = parseInt(tmdbId!, 10);
|
|
||||||
const mediaType = type as "movie" | "tv";
|
|
||||||
|
|
||||||
const {
|
|
||||||
data: preview,
|
|
||||||
isLoading,
|
|
||||||
isError,
|
|
||||||
} = useTmdbPreview(tmdbIdNum, mediaType);
|
|
||||||
const createEntry = useCreateEntry();
|
|
||||||
|
|
||||||
// Check if already in library
|
|
||||||
const libraryEntry = useLibraryStore((s) => {
|
|
||||||
for (const e of s.entries.values()) {
|
|
||||||
if (e.entryIds?.tmdb_id === tmdbIdNum) return e;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Redirect immediately if entry is already in library — skip the preview step
|
|
||||||
useEffect(() => {
|
|
||||||
if (libraryEntry) {
|
|
||||||
navigate(`/entry/${libraryEntry.id}`, { replace: true });
|
|
||||||
}
|
|
||||||
}, [libraryEntry, navigate]);
|
|
||||||
|
|
||||||
// Track recently viewed for command palette
|
|
||||||
const addRecentlyViewed = useCommandPaletteStore((s) => s.addRecentlyViewed);
|
|
||||||
useEffect(() => {
|
|
||||||
if (preview) {
|
|
||||||
addRecentlyViewed({
|
|
||||||
id: `tmdb-${tmdbIdNum}`,
|
|
||||||
title: preview.title,
|
|
||||||
type: mediaType,
|
|
||||||
poster_path: preview.poster_path,
|
|
||||||
libraryId: libraryEntry?.id,
|
|
||||||
tmdbId: tmdbIdNum,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [tmdbIdNum, preview?.title]);
|
|
||||||
|
|
||||||
if (isLoading || !preview) {
|
|
||||||
return <EntryDetailsSkeleton />;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isError) {
|
|
||||||
return (
|
|
||||||
<div className="flex flex-col items-center justify-center gap-4 py-20">
|
|
||||||
<p className="text-muted-foreground">Could not load entry from TMDB.</p>
|
|
||||||
<Button variant="outline" onClick={() => navigate(-1)}>
|
|
||||||
Go back
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const backdrop = preview.backdrop_path
|
|
||||||
? `${TMDB_IMG}/w1280${preview.backdrop_path}`
|
|
||||||
: null;
|
|
||||||
const poster = preview.poster_path
|
|
||||||
? `${TMDB_IMG}/w500${preview.poster_path}`
|
|
||||||
: "/images/default-poster.png";
|
|
||||||
|
|
||||||
const handleAddToLibrary = () => {
|
|
||||||
createEntry.mutate(
|
|
||||||
{ tmdb_id: preview.tmdb_id, is_tvserie: preview.is_tvseries },
|
|
||||||
{
|
|
||||||
onSuccess: (newEntry) =>
|
|
||||||
navigate(`/entry/${newEntry.id}`, { replace: true }),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
{/* Backdrop banner */}
|
|
||||||
<div className="relative -mx-6 -mt-6 h-52 overflow-hidden">
|
|
||||||
{backdrop ? (
|
|
||||||
<img
|
|
||||||
src={backdrop}
|
|
||||||
alt=""
|
|
||||||
className="h-full w-full object-cover opacity-25 blur-sm scale-105"
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<div className="h-full w-full bg-linear-to-br from-primary/15 to-primary/5" />
|
|
||||||
)}
|
|
||||||
<div className="absolute inset-0 bg-linear-to-t from-background via-background/60 to-transparent" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Main content */}
|
|
||||||
<div className="mx-auto max-w-4xl">
|
|
||||||
{/* Add to Library button — top right */}
|
|
||||||
<div className="flex justify-end gap-2 -mt-10 relative z-10 mb-2">
|
|
||||||
{libraryEntry ? (
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
onClick={() => navigate(`/entry/${libraryEntry.id}`)}
|
|
||||||
>
|
|
||||||
Already in Library — View
|
|
||||||
</Button>
|
|
||||||
) : (
|
|
||||||
<Button
|
|
||||||
onClick={handleAddToLibrary}
|
|
||||||
disabled={createEntry.isPending}
|
|
||||||
>
|
|
||||||
{createEntry.isPending ? (
|
|
||||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
||||||
) : (
|
|
||||||
<Plus className="mr-2 h-4 w-4" />
|
|
||||||
)}
|
|
||||||
{createEntry.isPending ? "Adding..." : "Add to Library"}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Two-column header: poster | info */}
|
|
||||||
<div className="flex flex-col gap-6 relative items-start sm:flex-row sm:gap-8 sm:-mt-8">
|
|
||||||
{/* LEFT: Poster */}
|
|
||||||
<div className="w-32 sm:w-44 shrink-0 self-start mx-auto sm:mx-0">
|
|
||||||
<img
|
|
||||||
src={poster}
|
|
||||||
alt={preview.title}
|
|
||||||
className="w-full aspect-2/3 rounded-xl object-cover shadow-2xl ring-1 ring-border/50"
|
|
||||||
/>
|
|
||||||
{/* External links */}
|
|
||||||
<div className="flex items-center justify-center gap-3 mt-3">
|
|
||||||
{preview.tmdb_id && (
|
|
||||||
<a
|
|
||||||
href={`https://www.themoviedb.org/${preview.is_tvseries ? "tv" : "movie"}/${preview.tmdb_id}`}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors"
|
|
||||||
>
|
|
||||||
<ExternalLink className="h-3 w-3" />
|
|
||||||
TMDB
|
|
||||||
</a>
|
|
||||||
)}
|
|
||||||
{preview.imdb_id && (
|
|
||||||
<a
|
|
||||||
href={`https://www.imdb.com/title/${preview.imdb_id}`}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors"
|
|
||||||
>
|
|
||||||
<ExternalLink className="h-3 w-3" />
|
|
||||||
IMDb
|
|
||||||
</a>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* RIGHT: Info */}
|
|
||||||
<div className="flex-1 min-w-0 space-y-4">
|
|
||||||
{/* Title */}
|
|
||||||
<div>
|
|
||||||
<h1 className="text-3xl font-bold leading-tight">
|
|
||||||
{preview.title}
|
|
||||||
</h1>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Meta */}
|
|
||||||
<div className="flex flex-wrap items-center gap-2 text-sm text-muted-foreground">
|
|
||||||
{preview.release_date && (
|
|
||||||
<span>{getYear(preview.release_date)}</span>
|
|
||||||
)}
|
|
||||||
{preview.is_tvseries && preview.status && (
|
|
||||||
<>
|
|
||||||
<span>•</span>
|
|
||||||
<span>{preview.status}</span>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{preview.runtime && !preview.is_tvseries && (
|
|
||||||
<>
|
|
||||||
{preview.release_date && <span>•</span>}
|
|
||||||
<span>{formatRuntime(preview.runtime)}</span>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* TV series season count */}
|
|
||||||
{preview.is_tvseries && preview.number_of_seasons != null && (
|
|
||||||
<div className="flex items-center gap-2 text-sm">
|
|
||||||
<Badge variant="secondary">
|
|
||||||
{preview.number_of_seasons}{" "}
|
|
||||||
{preview.number_of_seasons === 1 ? "Season" : "Seasons"}
|
|
||||||
</Badge>
|
|
||||||
{preview.number_of_episodes != null && (
|
|
||||||
<span className="text-muted-foreground">
|
|
||||||
({preview.number_of_episodes} episodes)
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Genres */}
|
|
||||||
{preview.genres.length > 0 && (
|
|
||||||
<div className="flex flex-wrap gap-1.5">
|
|
||||||
{preview.genres.map((g) => (
|
|
||||||
<Badge key={g.id} variant="outline" className="text-xs">
|
|
||||||
{g.name}
|
|
||||||
</Badge>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Rating */}
|
|
||||||
{preview.vote_average != null && preview.vote_average > 0 && (
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<span className="inline-flex items-center gap-1 rounded-full bg-blue-500/10 border border-blue-500/20 px-3 py-1 text-sm text-blue-600 dark:text-blue-400 font-medium">
|
|
||||||
<span className="font-bold">TMDB:</span>
|
|
||||||
{preview.vote_average.toFixed(1)}/10
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Storyline */}
|
|
||||||
{preview.storyline && (
|
|
||||||
<>
|
|
||||||
<p className="text-sm text-muted-foreground leading-relaxed max-w-prose">
|
|
||||||
{preview.storyline}
|
|
||||||
</p>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Sections */}
|
|
||||||
<div className="mt-10 space-y-8">
|
|
||||||
{preview.credits && preview.credits.length > 0 && (
|
|
||||||
<>
|
|
||||||
<Separator />
|
|
||||||
<CastList
|
|
||||||
credits={preview.credits as unknown as Credit[]}
|
|
||||||
maxItems={12}
|
|
||||||
allCastHref={`/entry/tmdb/${mediaType}/${tmdbIdNum}/cast`}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -53,11 +53,6 @@ const EntryDetailsPage = lazy(() =>
|
|||||||
default: m.EntryDetailsPage,
|
default: m.EntryDetailsPage,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
const TmdbPreviewPage = lazy(() =>
|
|
||||||
import("@/pages/TmdbPreviewPage").then((m) => ({
|
|
||||||
default: m.TmdbPreviewPage,
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
const TmdbCastsPage = lazy(() =>
|
const TmdbCastsPage = lazy(() =>
|
||||||
import("@/pages/TmdbCastsPage").then((m) => ({
|
import("@/pages/TmdbCastsPage").then((m) => ({
|
||||||
default: m.TmdbCastsPage,
|
default: m.TmdbCastsPage,
|
||||||
@@ -226,7 +221,7 @@ export const router = createRouter([
|
|||||||
path: "/entry/tmdb/:type/:tmdbId",
|
path: "/entry/tmdb/:type/:tmdbId",
|
||||||
element: (
|
element: (
|
||||||
<SuspensePage fallback={<EntryDetailsSkeleton />}>
|
<SuspensePage fallback={<EntryDetailsSkeleton />}>
|
||||||
<TmdbPreviewPage />
|
<EntryDetailsPage />
|
||||||
</SuspensePage>
|
</SuspensePage>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -426,4 +426,43 @@ export interface TmdbPreview {
|
|||||||
homepage: string | null;
|
homepage: string | null;
|
||||||
imdb_id: string | null;
|
imdb_id: string | null;
|
||||||
credits: TmdbPreviewCredit[];
|
credits: TmdbPreviewCredit[];
|
||||||
|
/** Same shape as a library Entry, built from the TMDB data */
|
||||||
|
entry?: Entry;
|
||||||
|
seasons?: TmdbPreviewSeason[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TmdbPreviewSeason {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
season_number: number;
|
||||||
|
episode_count: number;
|
||||||
|
air_date: string | null;
|
||||||
|
poster_path: string | null;
|
||||||
|
overview: string | null;
|
||||||
|
tmdb_rating: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------- Artwork (TMDB images merged with the media table) ---------- */
|
||||||
|
export type ArtworkType = "poster" | "backdrop" | "logo";
|
||||||
|
|
||||||
|
export interface ArtworkItem {
|
||||||
|
/** TMDB file path; null for local-only media (custom uploads, old downloads) */
|
||||||
|
file_path: string | null;
|
||||||
|
width: number | null;
|
||||||
|
height: number | null;
|
||||||
|
aspect_ratio: number | null;
|
||||||
|
language: string | null;
|
||||||
|
vote_average: number;
|
||||||
|
vote_count: number;
|
||||||
|
in_library: boolean;
|
||||||
|
media_id?: number | null;
|
||||||
|
media_path?: string | null;
|
||||||
|
is_selected?: boolean;
|
||||||
|
is_custom?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ArtworkResponse {
|
||||||
|
posters: ArtworkItem[];
|
||||||
|
backdrops: ArtworkItem[];
|
||||||
|
logos: ArtworkItem[];
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user