feat: clean artist and title terms before iTunes search to improve result accuracy.
This commit is contained in:
@@ -23,6 +23,19 @@ const USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
|
||||
// Helper for delays
|
||||
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
||||
// Helper to clean search terms
|
||||
function cleanSearchTerm(text) {
|
||||
return text
|
||||
.replace(/_Unplugged/gi, '')
|
||||
.replace(/_Remastered/gi, '')
|
||||
.replace(/_Live/gi, '')
|
||||
.replace(/_Acoustic/gi, '')
|
||||
.replace(/_Radio Edit/gi, '')
|
||||
.replace(/_Extended/gi, '')
|
||||
.replace(/_/g, ' ')
|
||||
.trim();
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log(`🎵 Starting iTunes Refresh Script`);
|
||||
console.log(` Target: ${API_URL}`);
|
||||
@@ -92,7 +105,9 @@ async function main() {
|
||||
|
||||
while (retries < MAX_RETRIES) {
|
||||
try {
|
||||
const term = encodeURIComponent(`${song.artist} ${song.title}`);
|
||||
const cleanArtist = cleanSearchTerm(song.artist);
|
||||
const cleanTitle = cleanSearchTerm(song.title);
|
||||
const term = encodeURIComponent(`${cleanArtist} ${cleanTitle}`);
|
||||
const itunesUrl = `https://itunes.apple.com/search?term=${term}&entity=song&limit=5`;
|
||||
|
||||
const res = await fetch(itunesUrl, {
|
||||
|
||||
Reference in New Issue
Block a user