Cleaned up code for SpotifyTrack implementation
authorRemixDev <deezloaderremix@gmail.com>
Sun, 14 Apr 2019 16:35:36 +0000 (18:35 +0200)
committerRemixDev <deezloaderremix@gmail.com>
Sun, 14 Apr 2019 16:35:36 +0000 (18:35 +0200)
app/app.js
app/public/js/frontend.js

index 7ccf2930709fb07fc737800ebf1656582f1093ad..7a0b20c77d8312fbcd22b00aec417802e0731ef3 100644 (file)
@@ -652,10 +652,16 @@ io.sockets.on('connection', function (s) {
                        try{
                                let creds = await Spotify.clientCredentialsGrant()
                                Spotify.setAccessToken(creds.body['access_token'])
-                               var resp = await Spotify.getTrack(data.id, {fields: "external_ids"})
+                               var resp = await Spotify.getTrack(data.id, {fields: "external_ids,artists,album,name"})
                                deezerId = await convertSpotify2Deezer(resp.body)
-                               data.id = deezerId
-                               downloadTrack(data)
+                               if (deezerId != 0){
+                                       data.id = deezerId
+                                       downloadTrack(data)
+                               }else{
+                                       s.emit("toast", "Can't find the track on Deezer!")
+                                       s.emit("silentlyCancelDownload", `${data.id}:${data.bitrate}`)
+                                       logger.error(`Can't find the track on Deezer!`)
+                               }
                        }catch(err){
                                logger.error(`downloadSpotifyPlaylist failed: ${err.stack ? err.stack : err}`)
                                return
index 997d752dfddbd6f129c1c9ab31a82f71919bdb21..bb2908e330bb7a0db341d3e384763f426d8d9422 100644 (file)
@@ -20,6 +20,10 @@ socket.on("message", function(desc){
        message(desc.title, desc.msg)
 })
 
+socket.on("toast", function(message){
+       M.toast({html: '<i class="material-icons left">error</i>'+message, displayLength: 5000, classes: 'rounded'})
+})
+
 socket.on("messageUpdate", function(desc){
        if (localStorage.getItem('updateModal') != desc.lastVersion){
                message(desc.title, desc.msg)
@@ -1184,6 +1188,11 @@ socket.on("cancelDownload", function (data) {
        })
 })
 
+socket.on("silentlyCancelDownload", function(id){
+       if (downloadQueue.indexOf(id)>-1)
+               downloadQueue.splice( downloadQueue.indexOf(id), 1)
+})
+
 $('#clearTracksTable').click(function (ev) {
        $('#tab_downloads_table_downloads').find('tbody').find('.finished, .error').addClass('animated fadeOutRight').on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
                downloadQueue.splice( downloadQueue.indexOf($(this).data('deezerid')), 1)