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( export async function download_image_from_itunes(
artist: string, rawArtist: string,
album: 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 { try {
const itunes_url = await itunes_cover_url(artist, album); const itunes_url = await itunes_cover_url(rawArtist, rawAlbum);
if (!itunes_url) { 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)) { if (!fs.existsSync(artist_dir)) {
fs.mkdirSync(artist_dir, { recursive: true }); fs.mkdirSync(artist_dir, { recursive: true });
} }
@@ -69,7 +71,7 @@ export async function download_image_from_itunes(
responseType: "arraybuffer", responseType: "arraybuffer",
}); });
fs.writeFileSync(`${artist_dir}/${album}.png`, img_response.data); fs.writeFileSync(`${artist_dir}/${safeAlbum}.png`, img_response.data);
} catch (error) { } catch (error) {
console.error("Error fetching data:", error); console.error("Error fetching data:", error);
throw error; throw error;

View File

@@ -46,11 +46,12 @@ async function get_image_from_server(
resultFilePath = iTunesFilePath; resultFilePath = iTunesFilePath;
} else { } else {
try { try {
await download_image_from_itunes(artist, album); await download_image_from_itunes(artist, album, safeArtist, safeAlbum);
resultFilePath = iTunesFilePath; resultFilePath = iTunesFilePath;
} catch (first_error) { } catch (first_error) {
try { 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; else throw first_error;
resultFilePath = MBFilePath; resultFilePath = MBFilePath;
} catch (secong_error) { } catch (secong_error) {