plugin detection improvment
This commit is contained in:
+6
-2
@@ -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) => {
|
||||
|
||||
+23
-8
@@ -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<any>(`${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({
|
||||
|
||||
+2
-1
@@ -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<string, string>;
|
||||
|
||||
Reference in New Issue
Block a user