var queueList = {}
var queue = []
socket.on("addedToQueue", function(queueItem){
queueList[queueItem.uuid] = queueItem
queue.push(queueItem.uuid)
$("#download_list").append(
`
${queueItem.title} -
${queueItem.artist}
0/${queueItem.size}
`)
})
socket.on("startDownload", function(uuid){
$('#bar_' + uuid).removeClass('indeterminate').addClass('determinate')
})
socket.on("updateQueue", function(update){
if (update.uuid && queue.indexOf(update.uuid) > -1){
console.log(update)
if (update.downloaded){
queueList[update.uuid].downloaded++
$("#download_"+update.uuid+" .queue_downloaded").text(queueList[update.uuid].downloaded)
$('#bar_' + update.uuid).css('width', ((queueList[update.uuid].downloaded + queueList[update.uuid].failed) / queueList[update.uuid].size)*100 + '%')
}
if (update.failed){
queueList[update.uuid].failed++
if (queueList[update.uuid].failed == 1){
$("#download_"+update.uuid+" .download_info_status").append(`(1 Failed)`)
}else{
$("#download_"+update.uuid+" .queue_failed").text(queueList[update.uuid].failed)
}
}
if (update.progress){
queueList[update.uuid].progress = update.progress
}
}
})