Compare commits

...

1 Commits

2 changed files with 12 additions and 9 deletions

View File

@@ -49,18 +49,20 @@ export async function itunes_cover_url(artist: string, album: string) {
}
export async function download_image_from_itunes(
artist: string,
album: string,
rawArtist: string,
rawAlbum: string,
safeArtist: string,
safeAlbum: string,
) {
console.log("[DEBUG]: download_image_from_itunes:", artist, album);
console.log("[DEBUG]: download_image_from_itunes:", rawArtist, rawAlbum);
try {
const itunes_url = await itunes_cover_url(artist, album);
const itunes_url = await itunes_cover_url(rawArtist, rawAlbum);
if (!itunes_url) {
throw new Error(`iTunes URL not found for ${artist} - ${album}`);
throw new Error(`iTunes URL not found for ${rawArtist} - ${rawAlbum}`);
}
const artist_dir = `public/covers/itunes/${artist}`;
const artist_dir = `public/covers/itunes/${safeArtist}`;
if (!fs.existsSync(artist_dir)) {
fs.mkdirSync(artist_dir, { recursive: true });
}
@@ -69,7 +71,7 @@ export async function download_image_from_itunes(
responseType: "arraybuffer",
});
fs.writeFileSync(`${artist_dir}/${album}.png`, img_response.data);
fs.writeFileSync(`${artist_dir}/${safeAlbum}.png`, img_response.data);
} catch (error) {
console.error("Error fetching data:", error);
throw error;

View File

@@ -46,11 +46,12 @@ async function get_image_from_server(
resultFilePath = iTunesFilePath;
} else {
try {
await download_image_from_itunes(artist, album);
await download_image_from_itunes(artist, album, safeArtist, safeAlbum);
resultFilePath = iTunesFilePath;
} catch (first_error) {
try {
if (safeMbid && safeMbid != "0") await download_image_from_caa(mbid);
if (safeMbid && safeMbid != "0")
await download_image_from_caa(safeMbid);
else throw first_error;
resultFilePath = MBFilePath;
} catch (secong_error) {