Skip to content

Commit e286f6a

Browse files
author
cedya77
committed
fix: ONA type detection in Kitsu search
Add subtype to Kitsu sparse fieldset so ONA detection actually fires. Also fall back to episodeCount when no Fribb mapping exists, and avoid permanently caching ONA type on transient TMDB failures.
1 parent bd494c3 commit e286f6a

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

addon/lib/getSearch.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,13 @@ async function performKitsuSearch(type, query, language, config, page = 1) {
255255
const mapping = await idMapper.getMappingByKitsuId(kitsuId);
256256
const malId = mapping?.mal_id;
257257

258-
// Resolve actual type — ONAs can be movies or series
259258
let itemType = type;
260-
if (item.subtype?.toLowerCase() === 'ona' && malId) {
261-
const resolvedType = await idMapper.resolveOnaType(malId, config);
262-
itemType = resolvedType;
259+
if (item.subtype?.toLowerCase() === 'ona') {
260+
if (malId) {
261+
itemType = await idMapper.resolveOnaType(malId, config);
262+
} else if (item.episodeCount === 1) {
263+
itemType = 'movie';
264+
}
263265
}
264266
const isMovie = itemType === 'movie';
265267

addon/lib/id-mapper.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,12 +1142,17 @@ async function resolveOnaType(malId, config = {}) {
11421142
onaTypeCache.set(numericMalId, 'movie');
11431143
return 'movie';
11441144
}
1145-
} catch {
1146-
// TMDB movie endpoint failed (404 or error) — not a movie
1145+
} catch (err) {
1146+
const status = err?.response?.status || err?.status;
1147+
if (status === 404) {
1148+
logger.debug(`[ID Mapper] ONA mal:${numericMalId} TMDB movie/${mapping.themoviedb_id} not found (404)`);
1149+
} else {
1150+
logger.warn(`[ID Mapper] ONA mal:${numericMalId} TMDB lookup failed (${status || err?.message}), skipping cache`);
1151+
return 'series';
1152+
}
11471153
}
11481154
}
11491155

1150-
// Default: treat as series
11511156
onaTypeCache.set(numericMalId, 'series');
11521157
return 'series';
11531158
}

addon/lib/kitsu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ async function searchByName(query: string, subtypes: string[] = [], ageRating: s
254254
'filter[subtype]': subtype,
255255
'page[limit]': limit,
256256
'page[offset]': offset,
257-
'fields[anime]': 'canonicalTitle,titles,abbreviatedTitles,coverImage,posterImage,synopsis,description,startDate,status,episodeCount,episodeLength,ageRating'
257+
'fields[anime]': 'canonicalTitle,titles,abbreviatedTitles,coverImage,posterImage,synopsis,description,startDate,status,subtype,episodeCount,episodeLength,ageRating'
258258
};
259259
if(ageRating.toLowerCase() !== 'none') {
260260
params['filter[ageRating]'] = ageRating;

0 commit comments

Comments
 (0)