Added support for artists links
This commit is contained in:
parent
36f23ee87b
commit
6b8e3be014
@ -37,23 +37,35 @@ 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)
|
||||||
|
|
||||||
// Check if element is already in queue
|
if (isSingleObject) downloadObjs = [downloadObjs]
|
||||||
if (queueOrder.includes(downloadObj.uuid))
|
|
||||||
throw new AlreadyInQueue(downloadObj.getEssentialDict())
|
|
||||||
|
|
||||||
// Save queue status when adding something to the queue
|
let slimmedObjects: any[] = []
|
||||||
if (!fs.existsSync(configFolder+'queue')) fs.mkdirSync(configFolder+'queue')
|
|
||||||
|
|
||||||
queueOrder.push(downloadObj.uuid)
|
downloadObjs.forEach(async (downloadObj: any) => {
|
||||||
fs.writeFileSync(configFolder+`queue${sep}order.json`, JSON.stringify(queueOrder))
|
// Check if element is already in queue
|
||||||
queue[downloadObj.uuid] = downloadObj.getEssentialDict()
|
if (queueOrder.includes(downloadObj.uuid))
|
||||||
fs.writeFileSync(configFolder+`queue${sep}${downloadObj.uuid}.json`, JSON.stringify(downloadObj.toDict()))
|
throw new AlreadyInQueue(downloadObj.getEssentialDict(), !isSingleObject)
|
||||||
listener.send('addedToQueue', downloadObj.getSlimmedDict())
|
|
||||||
|
// Save queue status when adding something to the queue
|
||||||
|
if (!fs.existsSync(configFolder+'queue')) fs.mkdirSync(configFolder+'queue')
|
||||||
|
|
||||||
|
queueOrder.push(downloadObj.uuid)
|
||||||
|
fs.writeFileSync(configFolder+`queue${sep}order.json`, JSON.stringify(queueOrder))
|
||||||
|
queue[downloadObj.uuid] = downloadObj.getEssentialDict()
|
||||||
|
fs.writeFileSync(configFolder+`queue${sep}${downloadObj.uuid}.json`, JSON.stringify(downloadObj.toDict()))
|
||||||
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user