mirror of
https://gitlab.com/RemixDev/deemix-js.git
synced 2024-12-28 18:36:26 +00:00
Better handling of albums upcs
This commit is contained in:
parent
b57cecb09a
commit
eab97f9893
|
@ -58,14 +58,31 @@ async function generateTrackItem(dz, id, bitrate, trackAPI, albumAPI){
|
||||||
async function generateAlbumItem(dz, id, bitrate, rootArtist){
|
async function generateAlbumItem(dz, id, bitrate, rootArtist){
|
||||||
// Get essential album info
|
// Get essential album info
|
||||||
let albumAPI
|
let albumAPI
|
||||||
try{
|
if (String(id).startsWith('upc')){
|
||||||
albumAPI = await dz.api.get_album(id)
|
let upcs = [id.slice(4)]
|
||||||
} catch (e){
|
upcs.push(parseInt(upcs[0])) // Try UPC without leading zeros as well
|
||||||
console.trace(e)
|
let lastError
|
||||||
throw new GenerationError(`https://deezer.com/album/${id}`, e.message)
|
await each(upcs, async (upc)=>{
|
||||||
|
try {
|
||||||
|
albumAPI = await dz.api.get_album(`upc:${upc}`)
|
||||||
|
} catch (e) {
|
||||||
|
lastError = e
|
||||||
|
albumAPI = null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (!albumAPI){
|
||||||
|
console.trace(lastError)
|
||||||
|
throw new GenerationError(`https://deezer.com/album/${id}`, lastError.message)
|
||||||
|
}
|
||||||
|
id = albumAPI.id
|
||||||
|
} else {
|
||||||
|
try{
|
||||||
|
albumAPI = await dz.api.get_album(id)
|
||||||
|
} catch (e){
|
||||||
|
console.trace(e)
|
||||||
|
throw new GenerationError(`https://deezer.com/album/${id}`, e.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (String(id).startsWith('upc')) { id = albumAPI['id'] }
|
|
||||||
if (!(/^\d+$/.test(id))) throw new InvalidID(`https://deezer.com/album/${id}`)
|
if (!(/^\d+$/.test(id))) throw new InvalidID(`https://deezer.com/album/${id}`)
|
||||||
|
|
||||||
// Get extra info about album
|
// Get extra info about album
|
||||||
|
|
Loading…
Reference in a new issue