Update packages/addon/src/utils.ts
Browse files39 unmodified lines404142434445464748495051525354555657585960616263646566676869705 unmodified lines76777879808182838485125 unmodified lines21121221321421521621721821922022139 unmodified linesreturn sanitized;}// New: Enhanced matching for "common word" casesfunction matchesWithYearAndGenre(fileTitle: string, query: string, year: string | undefined, genre: string | undefined): boolean {const sanitizedQuery = query.toLowerCase().trim();const sanitizedTitle = sanitizeTitle(fileTitle).toLowerCase().trim();// Handle cases where "Alive" is a common word but needs to be matched with the year/genreconst yearPattern = year ? new RegExp(`(${year})`, 'i') : null;const genrePattern = genre ? new RegExp(`(${genre})`, 'i') : null;// Match based on title, and if year or genre is available, match those as welllet match = sanitizedTitle.includes(sanitizedQuery);if (match && yearPattern) {match = yearPattern.test(sanitizedTitle);}if (match && genrePattern) {match = genrePattern.test(sanitizedTitle);}log('matchesWithYearAndGenre - Title matching with year/genre:', { fileTitle, query, match });return match;}export function matchesTitle(fileTitle: string, query: string, strict: boolean, year?: string, genre?: string): boolean {const sanitizedQuery = query.toLowerCase().trim();const sanitizedTitle = sanitizeTitle(fileTitle).toLowerCase().trim();5 unmodified linesreturn result;}// Use year and genre matching logic for problematic casesconst result = matchesWithYearAndGenre(fileTitle, query, year, genre);log('matchesTitle - Loose match result:', result);return result;}export function createStreamUrl({125 unmodified lineslog(matchesTitle("Am_er-ic.a the Beautiful", "America the Beautiful", false)); // Expected: truelog(matchesTitle("La fête de l'été", "fete", false)); // Expected: truelog(matchesTitle("Fête du cinéma", "cinema", false)); // Expected: truelog(matchesTitle("Alive", "Alive", true)); // Expected: truelog(matchesTitle("Alive (1993)", "Alive", false, "1993", "Drama")); // Expected: truelog("End of Title Functions Test");}// Run the testtestTitleFunctions();39 unmodified lines404142434445465 unmodified lines5253545556575859606162125 unmodified lines18818919019139 unmodified linesreturn sanitized;}export function matchesTitle(fileTitle: string, query: string, strict: boolean): boolean {const sanitizedQuery = query.toLowerCase().trim();const sanitizedTitle = sanitizeTitle(fileTitle).toLowerCase().trim();5 unmodified linesreturn result;}const re = new RegExp(`\\b${sanitizedQuery.split(' ')[0]}\\b`, 'i');const matchResult = re.test(sanitizedTitle);log('matchesTitle - Loose match result:', matchResult);return matchResult;}export function createStreamUrl({125 unmodified lineslog(matchesTitle("Am_er-ic.a the Beautiful", "America the Beautiful", false)); // Expected: truelog(matchesTitle("La fête de l'été", "fete", false)); // Expected: truelog(matchesTitle("Fête du cinéma", "cinema", false)); // Expected: true}
packages/addon/src/utils.ts+6-36