From 5c2b5a59beb370daec5c1ab1df4a80751dcc0194 Mon Sep 17 00:00:00 2001 From: TheBeastLT Date: Wed, 1 Nov 2023 17:12:32 +0200 Subject: [PATCH] fix debrid filename matching for title with non unicode chars --- addon/moch/mochHelper.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/addon/moch/mochHelper.js b/addon/moch/mochHelper.js index 8f75050..f1049aa 100644 --- a/addon/moch/mochHelper.js +++ b/addon/moch/mochHelper.js @@ -32,7 +32,7 @@ export async function enrichMeta(itemMeta) { poster: commonImdbId && `${METAHUB_URL}/poster/medium/${commonImdbId}/img`, background: commonImdbId && `${METAHUB_URL}/background/medium/${commonImdbId}/img`, videos: itemMeta.videos.map(video => { - const file = files.find(file => video.title.includes(file.title)); + const file = files.find(file => sameFilename(video.title, file.title)); if (file?.imdbId) { if (file.imdbSeason && file.imdbEpisode) { video.id = `${file.imdbId}:${file.imdbSeason}:${file.imdbEpisode}`; @@ -51,6 +51,16 @@ export async function enrichMeta(itemMeta) { return itemMeta } +function sameFilename(filename, expectedFilename) { + const offset = filename.length - expectedFilename.length; + for (let i = 0; i < expectedFilename.length; i++) { + if (filename[offset + i] !== expectedFilename[i] && expectedFilename[i] !== '�') { + return false; + } + } + return true; +} + function mostCommonValue(array) { return array.sort((a, b) => array.filter(v => v === a).length - array.filter(v => v === b).length).pop(); }