add album_links to deezify, fix variable names, support number artists

This commit is contained in:
Soph :3 2025-12-23 13:36:32 +02:00
parent f1c62b6a73
commit 57c58278ab

View file

@ -6,9 +6,9 @@ const CACHE_DIR = "./deezer_cache";
fs.mkdirSync(CACHE_DIR, { recursive: true }); fs.mkdirSync(CACHE_DIR, { recursive: true });
const artists = [ const artists = [
]; ];
const album_links = [
]
const BAD_KEYWORDS = [ const BAD_KEYWORDS = [
" remix", " remix",
"remix ", "remix ",
@ -22,6 +22,7 @@ const BAD_KEYWORDS = [
"anniversary", "anniversary",
"(remixes)", "(remixes)",
"(remix)", "(remix)",
"(acustic)"
]; ];
function normalize(str) { function normalize(str) {
@ -58,6 +59,7 @@ async function getArtistId(name) {
const data = await cachedFetch( const data = await cachedFetch(
`https://api.deezer.com/search/artist?q=${q}` `https://api.deezer.com/search/artist?q=${q}`
); );
return data?.data?.[0]?.id ?? null; return data?.data?.[0]?.id ?? null;
} }
@ -73,7 +75,10 @@ async function getAllAlbums(artistId) {
return out; return out;
} }
async function getAlbum(albumId) {
const url = `https://api.deezer.com/album/${albumId}`;
return await cachedFetch(url);
}
function selectBestAlbumVersions(albums) { function selectBestAlbumVersions(albums) {
const byTitle = new Map(); const byTitle = new Map();
@ -99,32 +104,54 @@ function selectBestAlbumVersions(albums) {
} }
(async () => { (async () => {
const sex = []; const links = [];
const sex_squared = [] const displays = []
const album_links_raw = await Promise.all(album_links.map(async z => await getAlbum(z.replace(/[^\d]*(\d*)$/gm, "$1"))));
for (const artist of artists) { for (const artist of artists) {
console.log(`\n=== ${artist} ===`); console.log(`\n=== ${artist} ===`);
const artistId = await getArtistId(artist); const artistId = typeof artist == "number" ? artist : await getArtistId(artist);
if (!artistId) { if (!artistId) {
console.log("Artist not found"); console.log("Artist not found");
continue; continue;
} }
const albums = await getAllAlbums(artistId); const albums = (await getAllAlbums(artistId));
const cleanAlbums = selectBestAlbumVersions(albums); const cleanAlbums = selectBestAlbumVersions(albums);
let artistLines = [];
let extraCount = 0;
for (const a of cleanAlbums) { for (const a of cleanAlbums) {
console.log( console.log(
`${a.title} | ${a.explicit_lyrics ? "EXPLICIT" : "CLEAN"} | https://www.deezer.com/en/album/${a.id}` `${a.title} | ${a.explicit_lyrics ? "EXPLICIT" : "CLEAN"} | https://www.deezer.com/en/album/${a.id}`
); );
sex_squared.push(`+ ${artist} - ${a.title} ${a.explicit_lyrics ? "[E]" : ""}`)
sex.push(`https://www.deezer.com/en/album/${a.id}`) links.push(`https://www.deezer.com/en/album/${a.id}`);
if (artistLines.length < 100) {
artistLines.push(
`+ ${typeof artist == "number" ? `No name (${artist})` : artist} - ${a.title} ${a.explicit_lyrics ? "[E]" : ""}`
);
} else {
extraCount++;
}
} }
if (extraCount > 0) {
artistLines.push(`(and ${extraCount} more)`);
}
displays.push(...artistLines);
} }
fs.writeFileSync("orpheus_links.txt", sex.join(" ")) album_links_raw.forEach(z => {
fs.writeFileSync("discord_send.txt", sex_squared.join(" \n").match(/.{1,2000}$/gms).map(z => z.trim()).join("\n\n"+'-'.repeat(15)+"\n\n")) links.push(`https://www.deezer.com/en/album/${z.id}`);
displays.push(
`+ ${z.artist.name} - ${z.title} ${z.explicit_lyrics ? "[E]" : ""}`
);
})
fs.writeFileSync("orpheus_links.txt", links.join(" "))
fs.writeFileSync("discord_send.txt", displays.join(" \n").match(/.{1,2000}$/gms).map(z => z.trim()).join("\n\n"+'-'.repeat(15)+"\n\n"))
})().catch(err => { })().catch(err => {
console.error(err); console.error(err);