style: auto-fix linting issues
This commit is contained in:
parent
d907178f7a
commit
3a63898e73
1 changed files with 34 additions and 18 deletions
30
js/app.js
30
js/app.js
|
|
@ -1103,14 +1103,18 @@ async function parseCSV(csvText, api, onProgress) {
|
||||||
let foundTrack = null;
|
let foundTrack = null;
|
||||||
|
|
||||||
// Helper: Normalize strings for fuzzy matching
|
// Helper: Normalize strings for fuzzy matching
|
||||||
const normalize = (str) => str.toLowerCase().replace(/[^\w\s]/g, '').trim();
|
const normalize = (str) =>
|
||||||
|
str
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[^\w\s]/g, '')
|
||||||
|
.trim();
|
||||||
|
|
||||||
// Helper: Check if result matches our criteria
|
// Helper: Check if result matches our criteria
|
||||||
const isValidMatch = (track, title, artists, album) => {
|
const isValidMatch = (track, title, artists, album) => {
|
||||||
if (!track) return false;
|
if (!track) return false;
|
||||||
|
|
||||||
const trackTitle = normalize(track.title || '');
|
const trackTitle = normalize(track.title || '');
|
||||||
const trackArtists = (track.artists || []).map(a => normalize(a.name || '')).join(' ');
|
const trackArtists = (track.artists || []).map((a) => normalize(a.name || '')).join(' ');
|
||||||
const trackAlbum = normalize(track.album?.name || '');
|
const trackAlbum = normalize(track.album?.name || '');
|
||||||
|
|
||||||
const queryTitle = normalize(title);
|
const queryTitle = normalize(title);
|
||||||
|
|
@ -1118,16 +1122,24 @@ async function parseCSV(csvText, api, onProgress) {
|
||||||
const queryAlbum = normalize(album || '');
|
const queryAlbum = normalize(album || '');
|
||||||
|
|
||||||
// Must match title (exact or substring match)
|
// Must match title (exact or substring match)
|
||||||
const titleMatch = trackTitle === queryTitle || trackTitle.includes(queryTitle) || queryTitle.includes(trackTitle);
|
const titleMatch =
|
||||||
|
trackTitle === queryTitle ||
|
||||||
|
trackTitle.includes(queryTitle) ||
|
||||||
|
queryTitle.includes(trackTitle);
|
||||||
if (!titleMatch) return false;
|
if (!titleMatch) return false;
|
||||||
|
|
||||||
// Must match at least one artist
|
// Must match at least one artist
|
||||||
const artistMatch = trackArtists.includes(queryArtists.split(' ')[0]) || queryArtists.includes(trackArtists.split(' ')[0]);
|
const artistMatch =
|
||||||
|
trackArtists.includes(queryArtists.split(' ')[0]) ||
|
||||||
|
queryArtists.includes(trackArtists.split(' ')[0]);
|
||||||
if (!artistMatch) return false;
|
if (!artistMatch) return false;
|
||||||
|
|
||||||
// If album provided, prefer matching album but not strict
|
// If album provided, prefer matching album but not strict
|
||||||
if (queryAlbum) {
|
if (queryAlbum) {
|
||||||
const albumMatch = trackAlbum === queryAlbum || trackAlbum.includes(queryAlbum) || queryAlbum.includes(trackAlbum);
|
const albumMatch =
|
||||||
|
trackAlbum === queryAlbum ||
|
||||||
|
trackAlbum.includes(queryAlbum) ||
|
||||||
|
queryAlbum.includes(trackAlbum);
|
||||||
return albumMatch; // Prefer album matches
|
return albumMatch; // Prefer album matches
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1239,8 +1251,12 @@ async function parseCSV(csvText, api, onProgress) {
|
||||||
tracks.push(foundTrack);
|
tracks.push(foundTrack);
|
||||||
console.log(`✓ "${trackTitle}" by ${artistNames}${albumName ? ' [' + albumName + ']' : ''}`);
|
console.log(`✓ "${trackTitle}" by ${artistNames}${albumName ? ' [' + albumName + ']' : ''}`);
|
||||||
} else {
|
} else {
|
||||||
console.warn(`✗ Track not found: "${trackTitle}" by ${artistNames}${albumName ? ' [' + albumName + ']' : ''}`);
|
console.warn(
|
||||||
missingTracks.push(`${trackTitle} - ${artistNames}${albumName ? ' (album: ' + albumName + ')' : ''}`);
|
`✗ Track not found: "${trackTitle}" by ${artistNames}${albumName ? ' [' + albumName + ']' : ''}`
|
||||||
|
);
|
||||||
|
missingTracks.push(
|
||||||
|
`${trackTitle} - ${artistNames}${albumName ? ' (album: ' + albumName + ')' : ''}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error searching for track "${trackTitle}":`, error);
|
console.error(`Error searching for track "${trackTitle}":`, error);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue