Added support for artists links

This commit is contained in:
RemixDev 2021-05-13 19:20:22 +02:00
parent 36f23ee87b
commit 6b8e3be014

View File

@ -37,11 +37,18 @@ export let currentJob: any = null
export async function addToQueue(dz: any, url: string, bitrate: number){ export async function addToQueue(dz: any, url: string, bitrate: number){
if (!dz.logged_in) throw new NotLoggedIn if (!dz.logged_in) throw new NotLoggedIn
console.log(`Adding ${url} to queue`) console.log(`Adding ${url} to queue`)
let downloadObj = await deemix.generateDownloadObject(dz, url, bitrate, deemixPlugins, listener) let downloadObjs = await deemix.generateDownloadObject(dz, url, bitrate, deemixPlugins, listener)
let isSingleObject = !Array.isArray(downloadObjs)
console.log(downloadObjs)
if (isSingleObject) downloadObjs = [downloadObjs]
let slimmedObjects: any[] = []
downloadObjs.forEach(async (downloadObj: any) => {
// Check if element is already in queue // Check if element is already in queue
if (queueOrder.includes(downloadObj.uuid)) if (queueOrder.includes(downloadObj.uuid))
throw new AlreadyInQueue(downloadObj.getEssentialDict()) throw new AlreadyInQueue(downloadObj.getEssentialDict(), !isSingleObject)
// Save queue status when adding something to the queue // Save queue status when adding something to the queue
if (!fs.existsSync(configFolder+'queue')) fs.mkdirSync(configFolder+'queue') if (!fs.existsSync(configFolder+'queue')) fs.mkdirSync(configFolder+'queue')
@ -50,10 +57,15 @@ export async function addToQueue(dz: any, url: string, bitrate: number){
fs.writeFileSync(configFolder+`queue${sep}order.json`, JSON.stringify(queueOrder)) fs.writeFileSync(configFolder+`queue${sep}order.json`, JSON.stringify(queueOrder))
queue[downloadObj.uuid] = downloadObj.getEssentialDict() queue[downloadObj.uuid] = downloadObj.getEssentialDict()
fs.writeFileSync(configFolder+`queue${sep}${downloadObj.uuid}.json`, JSON.stringify(downloadObj.toDict())) fs.writeFileSync(configFolder+`queue${sep}${downloadObj.uuid}.json`, JSON.stringify(downloadObj.toDict()))
listener.send('addedToQueue', downloadObj.getSlimmedDict()) slimmedObjects.push(downloadObj.getSlimmedDict())
})
if (isSingleObject)
listener.send('addedToQueue', downloadObjs[0].getSlimmedDict())
else
listener.send('addedToQueue', slimmedObjects)
startQueue(dz) startQueue(dz)
return queue[downloadObj.uuid] return slimmedObjects
} }
async function startQueue(dz: any): Promise<any>{ async function startQueue(dz: any): Promise<any>{
@ -95,10 +107,12 @@ class QueueError extends Error {
class AlreadyInQueue extends QueueError { class AlreadyInQueue extends QueueError {
item: any item: any
constructor(dwObj: any) { silent: boolean
constructor(dwObj: any, silent: boolean) {
super(`${dwObj.artist} - ${dwObj.title} is already in queue.`) super(`${dwObj.artist} - ${dwObj.title} is already in queue.`)
this.name = "AlreadyInQueue" this.name = "AlreadyInQueue"
this.item = dwObj this.item = dwObj
this.silent = silent
} }
} }