add error handling, add dupe checker to json files, add unavailable track checker to json
This commit is contained in:
parent
cac779ffaa
commit
a133624584
3 changed files with 33 additions and 25 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -38,3 +38,7 @@ tmp
|
||||||
localstorage.json
|
localstorage.json
|
||||||
localStorage.sqlite
|
localStorage.sqlite
|
||||||
downloaded
|
downloaded
|
||||||
|
duplicates.name.json
|
||||||
|
duplicates.isrc.json
|
||||||
|
.gitignore
|
||||||
|
unavailable.json
|
||||||
|
|
44
index.ts
44
index.ts
|
@ -146,19 +146,18 @@ for (const track of tracks.items) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
/* Remove all tracks that are unavailable
|
/* Remove all tracks that are unavailable*/
|
||||||
for (const track of tracks.items) {
|
let unavailableTracks = tracks.items.filter(track => !track.item.streamReady);
|
||||||
if (track.item.streamReady) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/*for (const track of unavailableTracks) {
|
||||||
await utils.fetch("/users/199235629/favorites/tracks/" + track.item.id, {
|
await utils.fetch("/users/199235629/favorites/tracks/" + track.item.id, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
})
|
})
|
||||||
console.log("Removed from favorites", track.item.id)
|
console.log("Removed from favorites", track.item.id)
|
||||||
}
|
}*/
|
||||||
*/
|
|
||||||
/*
|
Bun.write("unavailable.json", JSON.stringify(unavailableTracks, null, 2))
|
||||||
|
|
||||||
function findDuplicateTracksByName(tracks: typeof tracks.items) {
|
function findDuplicateTracksByName(tracks: typeof tracks.items) {
|
||||||
const seen = new Map<string, { count: number, originals: typeof tracks }>();
|
const seen = new Map<string, { count: number, originals: typeof tracks }>();
|
||||||
|
|
||||||
|
@ -214,29 +213,28 @@ function findDuplicateTracksByISRC(tracks: typeof tracks.items) {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
// Usage:
|
// Usage:
|
||||||
const duplicatesByISRC = findDuplicateTracksByISRC(tracks.items);
|
const duplicatesByISRC = findDuplicateTracksByISRC(tracks.items);
|
||||||
|
|
||||||
|
let duplicatesISRCText = {};
|
||||||
|
|
||||||
duplicatesByISRC.forEach(({ name, isrc, count, duplicates }) => {
|
duplicatesByISRC.forEach(({ name, isrc, count, duplicates }) => {
|
||||||
console.log(`Name: ${name} ISRC: "${isrc}" - Count: ${count}`);
|
duplicatesISRCText[isrc] = { name, count, duplicates };
|
||||||
duplicates.forEach((trackObj) => {
|
|
||||||
//console.log(` - Track ID: ${trackObj.item.id}, Created: ${trackObj.created}`);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
*/
|
await Bun.write("duplicates.isrc.json", JSON.stringify(duplicatesISRCText, null, 2));
|
||||||
/*
|
|
||||||
// Usage:
|
|
||||||
const duplicates = findDuplicateTracksByName(tracks.items);
|
const duplicates = findDuplicateTracksByName(tracks.items);
|
||||||
|
|
||||||
console.log("Duplicate tracks:");
|
let duplicatesNamesText = {};
|
||||||
|
|
||||||
duplicates.forEach(({ normalizedTitle, count, duplicates }) => {
|
duplicates.forEach(({ normalizedTitle, count, duplicates }) => {
|
||||||
console.log(`Title: "${normalizedTitle}" - Count: ${count}`);
|
duplicatesNamesText[normalizedTitle] = { count, duplicates };
|
||||||
duplicates.forEach((trackObj) => {
|
|
||||||
//console.log(` - Track ID: ${trackObj.item.id}, Created: ${trackObj.created}`);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
*/
|
await Bun.write("duplicates.name.json", JSON.stringify(duplicatesNamesText, null, 2));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,13 @@ export default class {
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Failed to fetch ${url}: ${response.status} ${response.statusText}`)
|
//throw new Error(`Failed to fetch ${url}: ${response.status} ${response.statusText}\n${await response.text()}`);
|
||||||
|
return {
|
||||||
|
status: response.status,
|
||||||
|
statusText: response.statusText,
|
||||||
|
url: parsedUrl.toString(),
|
||||||
|
error: await response.text(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return await response.json() as Object;
|
return await response.json() as Object;
|
||||||
|
|
Loading…
Add table
Reference in a new issue