Update packages/addon/src/utils.ts
Browse files- packages/addon/src/utils.ts +6 -36
packages/addon/src/utils.ts
CHANGED
|
@@ -40,31 +40,7 @@ function sanitizeTitle(title: string): string {
|
|
| 40 |
return sanitized;
|
| 41 |
}
|
| 42 |
|
| 43 |
-
|
| 44 |
-
function matchesWithYearAndGenre(fileTitle: string, query: string, year: string | undefined, genre: string | undefined): boolean {
|
| 45 |
-
const sanitizedQuery = query.toLowerCase().trim();
|
| 46 |
-
const sanitizedTitle = sanitizeTitle(fileTitle).toLowerCase().trim();
|
| 47 |
-
|
| 48 |
-
// Handle cases where "Alive" is a common word but needs to be matched with the year/genre
|
| 49 |
-
const yearPattern = year ? new RegExp(`(${year})`, 'i') : null;
|
| 50 |
-
const genrePattern = genre ? new RegExp(`(${genre})`, 'i') : null;
|
| 51 |
-
|
| 52 |
-
// Match based on title, and if year or genre is available, match those as well
|
| 53 |
-
let match = sanitizedTitle.includes(sanitizedQuery);
|
| 54 |
-
|
| 55 |
-
if (match && yearPattern) {
|
| 56 |
-
match = yearPattern.test(sanitizedTitle);
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
if (match && genrePattern) {
|
| 60 |
-
match = genrePattern.test(sanitizedTitle);
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
log('matchesWithYearAndGenre - Title matching with year/genre:', { fileTitle, query, match });
|
| 64 |
-
return match;
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
export function matchesTitle(fileTitle: string, query: string, strict: boolean, year?: string, genre?: string): boolean {
|
| 68 |
const sanitizedQuery = query.toLowerCase().trim();
|
| 69 |
const sanitizedTitle = sanitizeTitle(fileTitle).toLowerCase().trim();
|
| 70 |
|
|
@@ -76,10 +52,11 @@ export function matchesTitle(fileTitle: string, query: string, strict: boolean,
|
|
| 76 |
return result;
|
| 77 |
}
|
| 78 |
|
| 79 |
-
|
| 80 |
-
const
|
| 81 |
-
log('matchesTitle - Loose match result:',
|
| 82 |
-
|
|
|
|
| 83 |
}
|
| 84 |
|
| 85 |
export function createStreamUrl({
|
|
@@ -211,11 +188,4 @@ export function testTitleFunctions() {
|
|
| 211 |
log(matchesTitle("Am_er-ic.a the Beautiful", "America the Beautiful", false)); // Expected: true
|
| 212 |
log(matchesTitle("La fête de l'été", "fete", false)); // Expected: true
|
| 213 |
log(matchesTitle("Fête du cinéma", "cinema", false)); // Expected: true
|
| 214 |
-
log(matchesTitle("Alive", "Alive", true)); // Expected: true
|
| 215 |
-
log(matchesTitle("Alive (1993)", "Alive", false, "1993", "Drama")); // Expected: true
|
| 216 |
-
|
| 217 |
-
log("End of Title Functions Test");
|
| 218 |
}
|
| 219 |
-
|
| 220 |
-
// Run the test
|
| 221 |
-
testTitleFunctions();
|
|
|
|
| 40 |
return sanitized;
|
| 41 |
}
|
| 42 |
|
| 43 |
+
export function matchesTitle(fileTitle: string, query: string, strict: boolean): boolean {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
const sanitizedQuery = query.toLowerCase().trim();
|
| 45 |
const sanitizedTitle = sanitizeTitle(fileTitle).toLowerCase().trim();
|
| 46 |
|
|
|
|
| 52 |
return result;
|
| 53 |
}
|
| 54 |
|
| 55 |
+
const re = new RegExp(`\\b${sanitizedQuery.split(' ')[0]}\\b`, 'i');
|
| 56 |
+
const matchResult = re.test(sanitizedTitle);
|
| 57 |
+
log('matchesTitle - Loose match result:', matchResult);
|
| 58 |
+
|
| 59 |
+
return matchResult;
|
| 60 |
}
|
| 61 |
|
| 62 |
export function createStreamUrl({
|
|
|
|
| 188 |
log(matchesTitle("Am_er-ic.a the Beautiful", "America the Beautiful", false)); // Expected: true
|
| 189 |
log(matchesTitle("La fête de l'été", "fete", false)); // Expected: true
|
| 190 |
log(matchesTitle("Fête du cinéma", "cinema", false)); // Expected: true
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
}
|
|
|
|
|
|
|
|
|