Added support for Spotify Albums captcha-login
authorRemixDev <deezloaderremix@gmail.com>
Thu, 25 Apr 2019 12:17:17 +0000 (14:17 +0200)
committerRemixDev <deezloaderremix@gmail.com>
Thu, 25 Apr 2019 12:17:17 +0000 (14:17 +0200)
app/app.js
app/package-lock.json
app/public/js/frontend.js

index 7a0b20c77d8312fbcd22b00aec417802e0731ef3..3dd8086e643a8d92257c28ab2c64267999e519c6 100644 (file)
@@ -663,7 +663,7 @@ io.sockets.on('connection', function (s) {
                                        logger.error(`Can't find the track on Deezer!`)
                                }
                        }catch(err){
-                               logger.error(`downloadSpotifyPlaylist failed: ${err.stack ? err.stack : err}`)
+                               logger.error(`downloadSpotifyTrack failed: ${err.stack ? err.stack : err}`)
                                return
                        }
                }else{
@@ -672,6 +672,33 @@ io.sockets.on('connection', function (s) {
        }
        s.on("downloadspotifytrack", data=>{downloadSpotifyTrack(data)})
 
+       // Gets data from the frontend and creates data for the deezer track object
+       async function downloadSpotifyAlbum(data){
+               logger.info(`Added to Queue ${data.id}`)
+               if (spotifySupport){
+                       try{
+                               let creds = await Spotify.clientCredentialsGrant()
+                               Spotify.setAccessToken(creds.body['access_token'])
+                               var resp = await Spotify.getAlbum(data.id, {fields: "external_ids,artists,name"})
+                               deezerId = await convertSpotifyAlbum2Deezer(resp.body)
+                               if (deezerId != 0){
+                                       data.id = deezerId
+                                       downloadAlbum(data)
+                               }else{
+                                       s.emit("toast", "Can't find the album on Deezer!")
+                                       s.emit("silentlyCancelDownload", `${data.id}:${data.bitrate}`)
+                                       logger.error(`Can't find the album on Deezer!`)
+                               }
+                       }catch(err){
+                               logger.error(`downloadSpotifyAlbum failed: ${err.stack ? err.stack : err}`)
+                               return
+                       }
+               }else{
+                       s.emit("message", {title: "Spotify Support is not enabled", msg: "You should add authCredentials.js in your config files to use this feature<br>You can see how to do that in <a href=\"https://notabug.org/RemixDevs/DeezloaderRemix/wiki/Spotify+Features\">this guide</a>"})
+               }
+       }
+       s.on("downloadspotifyalbum", data=>{downloadSpotifyAlbum(data)})
+
        // Converts the spotify track to a deezer one
        // It tries first with the isrc (best way of conversion)
        // Fallbacks to the old way, using search
@@ -721,6 +748,38 @@ io.sockets.on('connection', function (s) {
                return 0
        }
 
+       // Converts the spotify album to a deezer one
+       // It tries first with the upc (best way of conversion)
+       // Fallbacks to the old way, using search
+       async function convertSpotifyAlbum2Deezer(album){
+               if (!album) return 0
+               try{
+                       if (album.external_ids.upc){
+                               if (! isNaN(album.external_ids.upc)) album.external_ids.upc = parseInt(album.external_ids.upc)
+                               let resp = await s.Deezer.legacyGetAlbumByUPC(album.external_ids.upc)
+                               if (resp.title)
+                                       return resp.id
+                               else
+                                       logger.warn("UPC album is not on Deezer, falling back to old method")
+                       }
+               }catch(err){
+                       logger.warn("UPC not found, falling back to old method")
+               }
+               return convertAlbumMetadata2Deezer(album.artists[0].name, album.name)
+       }
+
+       // Tries to get album id from pure luck
+       async function convertAlbumMetadata2Deezer(artist, album){
+               let resp
+               artist = artist.replace(/–/g,"-").replace(/’/g, "'")
+               album = album.replace(/–/g,"-").replace(/’/g, "'")
+               try{
+                       resp = await s.Deezer.legacySearch(`artist:"${artist}" album:"${album}"`, "album", 1)
+               }catch(err){logger.err(`ConvertAlbumFromMetadata: ${err.stack ? err.stack : err}`)}
+               if (resp.data[0]) return resp.data[0].id
+               return 0
+       }
+
        // All the above functions call this function
        // It adds the object to an array and adds the promise for the download to the object itself
        function addToQueue(object) {
index bc888246d138dfe91ab09e764a3b1983adf51c56..45116123050dddb741725f0888d6f1587630f581 100644 (file)
                        }\r
                },\r
                "deezer-api": {\r
-                       "version": "git+https://notabug.org/RemixDevs/deezer-api.git#e4d246a7c4328d8fffe66b4d51ec5485a45622c0",\r
+                       "version": "git+https://notabug.org/RemixDevs/deezer-api.git#425d9d68f5cba9b6c95139e1c026479dbbc3d8ba",\r
                        "from": "git+https://notabug.org/RemixDevs/deezer-api.git#master",\r
                        "requires": {\r
                                "request-promise": "^4.2.2"\r
index 55818e6930261d5ce710eb4e601b00ef3205d601..08bb058936e6799c5c2925d1c8e93ba87e31d464 100644 (file)
@@ -1059,7 +1059,7 @@ function addToQueue(url, forceBitrate=null) {
        bitrate = forceBitrate ? forceBitrate : userSettings.maxBitrate
        var type = getTypeFromLink(url), id = getIDFromLink(url, type)
        console.log(type, id)
-       if (['track', 'spotifytrack', 'playlist', 'spotifyplaylist', 'album', 'artist', 'artisttop'].indexOf(type) == -1) {
+       if (['track', 'spotifytrack', 'playlist', 'spotifyplaylist', 'album', 'spotifyalbum', 'artist', 'artisttop'].indexOf(type) == -1) {
                M.toast({html: '<i class="material-icons left">error</i> Wrong Type!', displayLength: 5000, classes: 'rounded'})
                return false
        }