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' };
|
return { status: 'ok', message: 'Recompute mode enabled' };
|
||||||
});
|
});
|
||||||
app.post<{ Body: ProcessRequest }>('/process', async (request, reply) => {
|
app.post<{ Body: ProcessRequest }>('/process', async (request, reply) => {
|
||||||
const { taskId, cid, filePath, callbackUrl, metaCoreUrl } = request.body;
|
// filePath is optional: TMDB resolves purely from existingMeta
|
||||||
if (!taskId || !cid || !filePath || !callbackUrl || !metaCoreUrl) {
|
// (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);
|
return reply.send({ status: 'rejected', error: 'Missing required fields' } as ProcessResponse);
|
||||||
}
|
}
|
||||||
processFile(request.body, async (payload: CallbackPayload) => {
|
processFile(request.body, async (payload: CallbackPayload) => {
|
||||||
|
|||||||
+23
-8
@@ -433,8 +433,11 @@ export async function process(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip if already has TMDB data (unless forceRecompute)
|
// Skip only if FULLY enriched already (tmdbid AND poster), unless forced.
|
||||||
if (existingMeta?.tmdbid && !forceRecompute) {
|
// 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({
|
await sendCallback({
|
||||||
taskId: request.taskId,
|
taskId: request.taskId,
|
||||||
status: 'skipped',
|
status: 'skipped',
|
||||||
@@ -445,7 +448,7 @@ export async function process(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (forceRecompute) {
|
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
|
// Get midhash for caching
|
||||||
@@ -455,7 +458,7 @@ export async function process(
|
|||||||
if (midhash && !forceRecompute) {
|
if (midhash && !forceRecompute) {
|
||||||
const cachedData = await readJson<any>(`${midhash}_tmdb.json`);
|
const cachedData = await readJson<any>(`${midhash}_tmdb.json`);
|
||||||
if (cachedData) {
|
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 applyTmdbData(metaCore, cid, cachedData);
|
||||||
await sendCallback({
|
await sendCallback({
|
||||||
taskId: request.taskId,
|
taskId: request.taskId,
|
||||||
@@ -468,9 +471,21 @@ export async function process(
|
|||||||
|
|
||||||
let tmdbData = null;
|
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;
|
const imdbId = existingMeta?.imdbid;
|
||||||
if (imdbId) {
|
if (!tmdbData && imdbId) {
|
||||||
tmdbData = await findByImdbId(imdbId);
|
tmdbData = await findByImdbId(imdbId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -499,9 +514,9 @@ export async function process(
|
|||||||
await writeJson(`${midhash}_tmdb.json`, tmdbData);
|
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 {
|
} 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({
|
await sendCallback({
|
||||||
|
|||||||
+2
-1
@@ -41,7 +41,8 @@ export interface HealthResponse {
|
|||||||
export interface ProcessRequest {
|
export interface ProcessRequest {
|
||||||
taskId: string;
|
taskId: string;
|
||||||
cid: string;
|
cid: string;
|
||||||
filePath: string;
|
/** Optional: TMDB never reads the source file — used only for log context. */
|
||||||
|
filePath?: string;
|
||||||
callbackUrl: string;
|
callbackUrl: string;
|
||||||
metaCoreUrl: string;
|
metaCoreUrl: string;
|
||||||
existingMeta?: Record<string, string>;
|
existingMeta?: Record<string, string>;
|
||||||
|
|||||||
Reference in New Issue
Block a user