diff --git a/prproj-remapper.js b/prproj-remapper.js index 038c267..c7a15e0 100644 --- a/prproj-remapper.js +++ b/prproj-remapper.js @@ -250,20 +250,27 @@ function findHighResFileForGves(gvesPath, hiresTitle, hiresMediaFolder, fs) { // Normalize the folder path const searchFolder = hiresMediaFolder.replace(/\\/g, '/').replace(/\/$/, ''); - // If Title is provided, search for it + // If Title is provided, search for files containing that title if (hiresTitle) { - const videoExts = ['.mp4', '.mov', '.mxf', '.mov', '.wav', '.aif', '.aiff']; + try { + const files = fs.readdirSync(searchFolder); + const videoExts = new Set(['.mp4', '.mov', '.mxf', '.wav', '.aif', '.aiff']); + const titleLower = hiresTitle.toLowerCase(); - for (const ext of videoExts) { - const candidate = `${searchFolder}/${hiresTitle}${ext}`; - try { - if (fs.existsSync(candidate)) { - // Convert back to UNC format if it was a local path - return candidate.replace(/\//g, '\\'); + // Look for files that contain the title as a substring + for (const file of files) { + const ext = '.' + file.split('.').pop().toLowerCase(); + if (!videoExts.has(ext)) continue; + + const fileLower = file.toLowerCase(); + // Match if filename contains the title + if (fileLower.includes(titleLower)) { + const fullPath = `${searchFolder}/${file}`; + return fullPath.replace(/\//g, '\\'); } - } catch (e) { - // Ignore individual file check failures } + } catch (e) { + // Ignore folder read failures, fall through to secondary search } }