Fixed problems with Deezer getTracks
authorRemixDev <deezloaderremix@gmail.com>
Mon, 4 Feb 2019 20:59:51 +0000 (21:59 +0100)
committerRemixDev <deezloaderremix@gmail.com>
Mon, 4 Feb 2019 20:59:51 +0000 (21:59 +0100)
app/app.js
app/lib/deezer-api/index.js

index a45447c815efa277590ab7466a50a85effc8561d..a090e139ebd9259e3e94d22c6c9f880d874eb1c4 100644 (file)
@@ -950,7 +950,7 @@ io.sockets.on('connection', function (s) {
                        case "spotifyplaylist":
                                downloading.settings.plName = downloading.name
                                downloading.playlistArr = Array(downloading.size)
-                               downloading.playlistContent = new Array(downloading.size);
+                               downloading.playlistContent = new Array(downloading.size)
                                logger.info("Waiting for all tracks to be converted");
                                const convert = async () =>{
                                        await asyncForEach(downloading.obj.tracks, async (t,i)=>{
@@ -981,6 +981,11 @@ io.sockets.on('connection', function (s) {
                                                                return false
                                                        }
                                                        t.position = index
+                                                       if (t.id==0){
+                                                               t.title = downloading.obj.tracks[t.position].name
+                                             t.album = {id: 0, title: downloading.obj.tracks[t.position].album.name}
+                                             t.artist = {id: 0, name: downloading.obj.tracks[t.position].artists[0].name}
+                                                       }
                                                        try{
                                                                await downloadTrackObject(t, downloading.queueId, downloading.settings)
                                                                downloading.downloaded++
@@ -1072,13 +1077,13 @@ io.sockets.on('connection', function (s) {
        async function downloadTrackObject(track, queueId, settings) {
                if (!s.downloadQueue[queueId]) {
                        logger.error(`[${track.artist.name} - ${track.title}] Failed to download: Not in queue`)
-                       throw new Error(`Failed to download: Not in queue`)
-                       return
+                       throw new Error("Not in queue")
+                       return false
                }
-               if (track.id == 0){
+               if (parseInt(track.id) == 0){
                        logger.error(`[${track.artist.name} - ${track.title}] Failed to download: Wrong ID`)
-                       throw new Error(`Failed to download: Wrong ID`)
-                       return
+                       throw new Error("Wrong ID")
+                       return false
                }
 
                /* Album information is necessary for the following tags:
index a13fd1e27fcc2fa1326d42487ed00ccb7b9882d6..a45d252f4272cdc8116488604934bfb602f6fb0c 100644 (file)
@@ -161,9 +161,27 @@ module.exports = class Deezer {
   async getTracks(ids){
     var tracksArray = []
     var body = await this.apiCall(`song.getListData`, {sng_ids: ids})
-    body.results.data.forEach(track=>{
-      tracksArray.push(new Track(track))
-    })
+               var errors = 0
+               for(var i=0; i<ids.length; i++){
+                       if (ids[i] != 0) {
+                               tracksArray.push(new Track(body.results.data[i-errors]))
+                       }else{
+                               errors++
+                               tracksArray.push({
+                                       id: 0,
+                           title: '',
+                           duration: 0,
+                           MD5: 0,
+                           mediaVersion: 0,
+                           filesize: 0,
+                           album: {id: 0, title: "", picture: ""},
+                           artist: {id: 0, name: ""},
+                           artists: [{id: 0, name: ""}],
+                           recordType: -1,
+                               })
+                       }
+
+               }
     return tracksArray
   }