From 334133ae467bfaa3c7627577b43f8ad0ce246391 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 6 Jun 2026 15:24:33 +0200 Subject: [PATCH] plugin detection improvment --- src/index.ts | 8 ++++++-- src/plugin.ts | 31 +++++++++++++++++++++++-------- src/types.ts | 3 ++- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index 2218cce..dd98d5c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -48,8 +48,12 @@ app.post('/recompute', async () => { return { status: 'ok', message: 'Recompute mode enabled' }; }); app.post<{ Body: ProcessRequest }>('/process', async (request, reply) => { - const { taskId, cid, filePath, callbackUrl, metaCoreUrl } = request.body; - if (!taskId || !cid || !filePath || !callbackUrl || !metaCoreUrl) { + // filePath is optional: TMDB resolves purely from existingMeta + // (originalTitle/movieYear/videoType/imdbid produced by filename-parser) and + // writes back to `cid`. It never reads the source file. This lets the gateway + // feeders drive TMDB from parsed metadata alone, with no file on disk. + const { taskId, cid, callbackUrl, metaCoreUrl } = request.body; + if (!taskId || !cid || !callbackUrl || !metaCoreUrl) { return reply.send({ status: 'rejected', error: 'Missing required fields' } as ProcessResponse); } processFile(request.body, async (payload: CallbackPayload) => { diff --git a/src/plugin.ts b/src/plugin.ts index 7ecefd0..01d7156 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -433,8 +433,11 @@ export async function process( return; } - // Skip if already has TMDB data (unless forceRecompute) - if (existingMeta?.tmdbid && !forceRecompute) { + // Skip only if FULLY enriched already (tmdbid AND poster), unless forced. + // A record carrying a tmdbid but no poster — e.g. a gateway anchor or + // jellyfin-nfo that set only the id — still runs, so the full cycle + // (poster download + plot/genres) completes via getByTmdbId below. + if (existingMeta?.tmdbid && existingMeta?.poster && !forceRecompute) { await sendCallback({ taskId: request.taskId, status: 'skipped', @@ -445,7 +448,7 @@ export async function process( } if (forceRecompute) { - console.log(`[tmdb] Force recompute enabled for ${request.filePath}`); + console.log(`[tmdb] Force recompute enabled for ${request.filePath ?? existingMeta?.fileName ?? cid}`); } // Get midhash for caching @@ -455,7 +458,7 @@ export async function process( if (midhash && !forceRecompute) { const cachedData = await readJson(`${midhash}_tmdb.json`); if (cachedData) { - console.log(`[tmdb] Using cached TMDB data for ${request.filePath}`); + console.log(`[tmdb] Using cached TMDB data for ${request.filePath ?? existingMeta?.fileName ?? cid}`); await applyTmdbData(metaCore, cid, cachedData); await sendCallback({ taskId: request.taskId, @@ -468,9 +471,21 @@ export async function process( let tmdbData = null; - // Try by IMDB ID first + // Resolve by a known TMDB id first (authoritative — e.g. a gateway + // anchor or jellyfin-nfo). Completes the full cycle (poster + plot + + // genres) from an id alone, with no fuzzy re-search. + const knownTmdbId = existingMeta?.tmdbid; + if (knownTmdbId) { + const mediaType = + existingMeta?.videoType === 'tvshow' || existingMeta?.videoType === 'tv' + ? 'tv' + : 'movie'; + tmdbData = await getByTmdbId(knownTmdbId, mediaType); + } + + // Try by IMDB ID const imdbId = existingMeta?.imdbid; - if (imdbId) { + if (!tmdbData && imdbId) { tmdbData = await findByImdbId(imdbId); } @@ -499,9 +514,9 @@ export async function process( await writeJson(`${midhash}_tmdb.json`, tmdbData); } - console.log(`[tmdb] Fetched TMDB data for ${request.filePath}`); + console.log(`[tmdb] Fetched TMDB data for ${request.filePath ?? existingMeta?.fileName ?? cid}`); } else { - console.log(`[tmdb] No TMDB match found for ${request.filePath}`); + console.log(`[tmdb] No TMDB match found for ${request.filePath ?? existingMeta?.fileName ?? cid}`); } await sendCallback({ diff --git a/src/types.ts b/src/types.ts index 4dbbfe2..1146b3f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -41,7 +41,8 @@ export interface HealthResponse { export interface ProcessRequest { taskId: string; cid: string; - filePath: string; + /** Optional: TMDB never reads the source file — used only for log context. */ + filePath?: string; callbackUrl: string; metaCoreUrl: string; existingMeta?: Record;