MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Spotify Play?

    Scheduled Pinned Locked Moved Bug Hunt
    19 Posts 6 Posters 16.4k Views 12 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      mantha @Rasmus rytter
      last edited by

      Hi @rasmus-rytter,

      if two or more people came to the same conclusion, its an indication that its not an to bad idea :-)
      independent from this post i just had setup my mirror exactly the way @yawns and @richland007 described to you.

      I enhanced MMM-NowPlayingOnSpotify and MMM-AssistantMk2 to make them capable to control Spotify. It´s still in development but if you like you can have a look on my git forks.

      MMM-NowPlayingOnSpotify
      MMM-AssistantMk2

      you need to redo your authorization (Step 2) because we require now also the authorization user-modify-playback-state and you should add “deviceName” into your config-file.

      Im looking forward to your feedback dear alpha-tester ;-)

      F 1 Reply Last reply Reply Quote 1
      • F Offline
        F17MC @mantha
        last edited by

        @mantha Hi! How can I install this feature?
        I want launch Spotify with my MagicMirror. I have installed NowPlayingOnSpotify, AssistantMK2 and Raspotify. All works fine.
        Now, I can do the next: If I said to AssistantMK2 “SmartMirror, play Spotify on Chromecast Audio”, it launch raspotify and select my ChromeCast Audio as output. Do you think that it is possible?

        Sorry for my English.

        1 Reply Last reply Reply Quote 0
        • ejay-ibmE Offline
          ejay-ibm Project Sponsor Module Developer
          last edited by ejay-ibm

          @mantha Thank you for working on this !

          I have installed you modules.

          Unfortunately I can’t make the player respond to my play / stop command .
          the player well respond when I select a song from my phone and send it to raspotify , the module is well updated with cover and paying status .

          But voice command just doesn’t work .

          Anything particular I should say ?
          Maybe your developement is just done 100% done yet.

          Thank you

          Ejay

          M 1 Reply Last reply Reply Quote 0
          • M Offline
            mantha @ejay-ibm
            last edited by

            @ejay-ibm
            the module is listening to an open.spotify.com answer from Google assistant.
            It seems like the assistant is not aware of the preconfigured music provider and you need to point him in the right direction.

            “search for xxx on Spotify” works in my case. I’m almost sure that in the past also “play xxx from spotify” had worked, but now I got no more an open.spotify.com link backs. Would be interesting how it works for you.

            FYI - I identified that the Device parameter does not work proper in the current github version. need to work on this…

            1 Reply Last reply Reply Quote 0
            • ejay-ibmE Offline
              ejay-ibm Project Sponsor Module Developer
              last edited by

              Ok I see the answer coming to the screen but it look like it’s not passed to the module.

              "Micheal Jackson on spotify" ((open.spotify.com -- https://open.spotify.com/artist/3fMbdgg4jU18AjLCKBhRSm))\nMichael Jackson wasn't merely the biggest pop .... 
              

              Let me know if you need me to run some test or report logs to help you in debug.

              Ejay

              M 1 Reply Last reply Reply Quote 0
              • M Offline
                mantha @ejay-ibm
                last edited by

                @ejay-ibm
                in a first step you could check the console log for “[AMK2] openSpotify found:” and if the event PLAY_SPOTIFY was fired…

                ejay-ibmE 1 Reply Last reply Reply Quote 0
                • ejay-ibmE Offline
                  ejay-ibm Project Sponsor Module Developer @mantha
                  last edited by ejay-ibm

                  @mantha none of both found .
                  could you point me to the line in your code sending this to the console log please ?
                  I see in MK2 js code

                  if (payload.foundOpenSpotify) {
                  		this.sendNotification("PLAY_SPOTIFY", {
                  			url: payload.foundOpenSpotify
                  		})
                      };
                  

                  I can say that the notification is not sent, so no payload.foundOpenSpotify occur

                  I can see as well in node_helper.js

                  if (openSpotify) {
                            console.error("[AMK2] openSpotify found:", openSpotify[1])
                            foundOpenSpotify = openSpotify[1]
                          }
                        })
                  

                  Why in console error instead of console log ?
                  ( Sorry i’m not a dev might be a silly question and I guess the result would be the same if log or error it should be sent to the console… )

                  M 1 Reply Last reply Reply Quote 0
                  • ejay-ibmE Offline
                    ejay-ibm Project Sponsor Module Developer
                    last edited by ejay-ibm

                    As well I think the regex is not correct here : node_helper.js line 290

                    var re = new RegExp("\\(.open\\.spotify\\.com – (https:\\/\\/open\\.spotify\\.com[^ ]*).\\)", "gm")
                    

                    should be :

                    var re = new RegExp("\(open\.spotify\.com – (https:\/\/open\.spotify\.com[^ ]*\/\)", "gm")
                    
                    open\.spotify\.com
                    

                    is the correct regex to match with :
                    open.spotify.com
                    and

                    https:\/\/open\.spotify\.com[^ ]*\/
                    

                    is the correct regex to match with :
                    https://open.spotify.com/fallback1234

                    I may be wrong in my interpretation.

                    1 Reply Last reply Reply Quote 0
                    • M Offline
                      mantha @ejay-ibm
                      last edited by mantha

                      @ejay-ibm said in Spotify Play?:

                      Why in console error instead of console log ?
                      ( Sorry i’m not a dev might be a silly question and I guess the result would be the same if log or error it should be sent to the console… )

                      haha… there is a simple answer. I want them to be red to find them more easy. In a final version it should be console log…

                      Regarding the RegEx: I just tested them in german. I’m for sure not an RegEx pro (that’s a kind of black magic for me) ;-)
                      So if you have a better Regex expression feel free to change it.

                      The additional escape characters was necessary to wrap the RegEx into the java code.
                      Are you getting it to work without these escapes?

                      Proposal:
                      based on your post it seems to me, like the English version respond with

                      open.spotify.com -- https...
                      

                      instead of

                      open.spotify.com - https...
                      
                      

                      So you might need to reflect this in the RegEx

                      var re = new RegExp("\\(.open\\.spotify\\.com –+ (https:\\/\\/open\\.spotify\\.com[^ ]*).\\)", "gm")
                      
                      1 Reply Last reply Reply Quote 0
                      • ejay-ibmE Offline
                        ejay-ibm Project Sponsor Module Developer
                        last edited by ejay-ibm

                        @mantha
                        Sorry typo it well respond with

                        open.spotify.com - https...
                        

                        I have try :

                         var re = new RegExp("https:\/\/open\.spotify\.com\/([^ ]*)", "gm")
                                var openSpotify = re.exec(str)
                                if (openSpotify) {
                                  console.error("[AMK2] openSpotify found:", openSpotify[1])
                                  foundOpenSpotify = openSpotify[1]
                        

                        And I’m getting in console log :

                        received a module notification: PLAY_SPOTIFY from sender: MMM-AssistantMk2

                        but

                        var re = new RegExp("\\(.open\\.spotify\\.com – (https:\\/\\/open\\.spotify\\.com[^ ]*).\\)", "gm")
                        

                        I’m not getting anything.

                        What is strange is that in both case :
                        console.error(“[AMK2] openSpotify found:”, openSpotify[1])

                        Doesn’t throw anything…
                        but as well
                        console.log(“[AMK2] video found:”, youtubeVideo[1])
                        Doesn’t throw anything either even when it find and play a video. so i’ll not worry for not about the notif logs

                        So, for Now, I consider it’s working as PLAY_SPOTIFY notification is fired.

                        What would be the next step now?

                        Ejay

                        M 1 Reply Last reply Reply Quote 0
                        • M Offline
                          mantha @ejay-ibm
                          last edited by

                          @ejay-ibm

                          please check the console in the dev mode, as well as the filesystem logs…
                          module and helper write unfortunately to different log destinations.

                          Regarding the next steps I’m going to open a chat…

                          1 Reply Last reply Reply Quote 0
                          • ejay-ibmE Offline
                            ejay-ibm Project Sponsor Module Developer
                            last edited by ejay-ibm

                            Ok I made a few changes in the MK2assistant node-helper.js

                            var re = new RegExp("https:\/\/open\.spotify\.com\/([a-zA-Z0-9?\/]+)", "gm")
                                    //var re = new RegExp("\\(.open\\.spotify\\.com – (https:\\/\\/open\\.spotify\\.com[^ ]*).\\)", "gm")
                                    var openSpotify = re.exec(str)
                                    if (openSpotify) {
                                    console.error("[AMK2] openSpotify found:", openSpotify[0])
                                      foundOpenSpotify = openSpotify[0]
                                    
                            

                            And as well in Nowplayingoncpotify/core/Spotifyconnector.js

                            let uri = replaceall("/", ":", url.replace("https:\/\/open.spotify.com", "spotify"));
                            

                            The slash were not escaped in the url making half of the line be a comment.

                            After updating raspotify to the latest I can say : “Michael Jackson on spotify” and the song start playing .
                            Good stuff .

                            I’m wondering if slash should be escaped as well here I haven’t do it since it’s working :

                            const tokenRefreshEndpoint = 'https://accounts.spotify.com/api/token';
                            const apiEndpoint = 'https://api.spotify.com/v1/me/player';
                            

                            As you can see the editor consider the part after the slash as comment

                            0_1552119557018_Capture d’écran 2019-03-09 à 09.18.38.png
                            Not sure how it works on interpretor side.

                            anyway I’ll post my update in the repo .

                            Ejay

                            M 1 Reply Last reply Reply Quote 0
                            • M Offline
                              mantha @ejay-ibm
                              last edited by mantha

                              @ejay-ibm
                              Hey Ejay,

                              many thanks for testing and bug fixing.

                              Regarding your findings: The original RegEx still works on my installation, but based on your experience it seams like the RegEx is more stable by just looking for the URL itself. I can´t see any downside of this approach.
                              In my test it turn out that “-” and “_” need to be added to the character set, due to they are used e.g. in usernames (spotify_germany) which are part of playlist path.

                              Also the escaping is now much more proper (interesting that the raw version had worked…)

                              Important finding from ejay
                              if raspotify just jump back to track start instead of changing the song, an update of raspotify is needed. I had exactly the same behavior on my installation.

                              1 Reply Last reply Reply Quote 0

                              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                              With your input, this post could be even better 💗

                              Register Login
                              • 1 / 1
                              • First post
                                Last post
                              Enjoying MagicMirror? Please consider a donation!
                              MagicMirror created by Michael Teeuw.
                              Forum managed by Sam, technical setup by Karsten.
                              This forum is using NodeBB as its core | Contributors
                              Contact | Privacy Policy