Spotify (api is partially broken)

Questions and comments specific to a particular plugin should go here.
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Spotify

Post by krambriw » Wed Dec 18, 2013 5:02 pm

It was a while ago since I wrote this plugin, I need to check if the plugin itself keeps track of song changes,
Otherwise it sounds as a good idea to create such an event. This event could be used as you say.

Would it be a good idea to keep the information about the actual song in the payload?

BestR

leothlon
Experienced User
Posts: 59
Joined: Tue Dec 17, 2013 6:29 pm

Re: Spotify

Post by leothlon » Thu Dec 19, 2013 8:51 am

A good payload could be something like
"song - artist - duration"

if possible maby even as " u'songname' u'artistname' u'duration' " this would i believe alow for using payload[0] [1] [2] to get specific? so if i want to send it out to webserver / commandfusion or so it could easly be formated.
though you can do that with the get song function in anyway so maby not nessesary.

But atleast getting an event to tell eventghost the track changed. then you can use that to trigger get song name anyway...

Another wounderfull feature would be to start playing a specific playlist.
Like say i come home and want some nice relaxing music i click the button on my controllunit, it sends to eventghost that triggers playing that music.
The day after i come home, its friday and i want to get in the mood for the nights party so i want club music for example and i then just press that button on my controllunit.

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Spotify

Post by krambriw » Thu Dec 19, 2013 9:22 am

Yes, understood,

Regarding further features, I just have to obey the limits in the api (pytify.py) I'm using for this...

BR

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Spotify

Post by krambriw » Thu Dec 19, 2013 3:05 pm

Okay, here is a version that fires events
- when the artist/track changes
- when nothing is played

I think the second event is also needed to allow easy updates of GUI's when nothing is played, otherwise the last played track will remain in the GUI (if you use websockets or CommandFusion, you can use both events to update the page elements correctly)

Typical events look like this in my tests:

Code: Select all

15:54:44   MySpotify.CurrentArtistTrack ['Not playing anything...', '']
15:54:46   MySpotify.CurrentArtistTrack ['Lana Del Rey', 'Without You']
For the other requested features,
- duration is not available
- it is unfortunately not possible with the api I use to select and play a specific playlist.

EDIT: Deleted version, see below

BR Walter
Last edited by krambriw on Mon Dec 30, 2013 7:16 am, edited 1 time in total.

opitmalt
Posts: 3
Joined: Wed Oct 02, 2013 5:11 pm

Re: Spotify

Post by opitmalt » Fri Dec 20, 2013 12:52 pm

I have a working but not that good solution for starting specific playlists in Spotify with EG (see below). It works for me if Spotify is already running. You can get the string inside the "Copy string to clipboard:"-action if you right click the playlist you would like to play and choose "Copy Spotify URI".

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1640">
    <Folder Name="SpotifyPlayPlaylist" Expanded="True">
        <Macro Name="SpotifyPlayPlaylist1000Matti" Expanded="True">
            <Action>
                System.Execute(u'C:\\Users\\optimalt\\AppData\\Roaming\\Spotify\\spotify.exe', u'', 0, False, 2, u'', False)
            </Action>
            <Action>
                EventGhost.Wait(3.0)
            </Action>
            <Action>
                Window.SendKeys(u'{Tabulator}', False)
            </Action>
            <Action>
                System.SetClipboard(u'spotify:user:chops:playlist:4y9iMsycGTbGcdgun8M8Cj')
            </Action>
            <Action>
                Window.SendKeys(u'{Ctrl+L}', False)
            </Action>
            <Action>
                Window.SendKeys(u'{Ctrl+V}', False)
            </Action>
            <Action>
                Window.SendKeys(u'{Return}', False)
            </Action>
            <Action>
                Window.SendKeys(u'{Tabulator}', False)
            </Action>
            <Action>
                Window.SendKeys(u'{Return}', False)
            </Action>
            <Action>
                Window.SendKeys(u'{Ctrl+L}', False)
            </Action>
            <Action>
                Window.SendKeys(u'{Backspace}', False)
            </Action>
            <Action>
                Window.SendKeys(u'{Tabulator}', False)
            </Action>
            <Action>
                Window.FindWindow(u'spotify.exe', None, None, None, None, None, False, 0.0, 2)
            </Action>
            <Action>
                Window.Minimize()
            </Action>
        </Macro>
    </Folder>
</EventGhost>

leothlon
Experienced User
Posts: 59
Joined: Tue Dec 17, 2013 6:29 pm

Re: Spotify

Post by leothlon » Thu Dec 26, 2013 8:29 pm

Update: the plugin only give me triggers in EG if spotify was running when EG started.
any idea why this would be?

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Spotify

Post by krambriw » Fri Dec 27, 2013 10:09 am

Hi,

Thanks for reporting back.

I saw some issues with my code so I have improved and hopefully made it work better. In my tests, I can now start EG and the Spotify plugin without problems independent if Spotify is already running or not. I can Start and Terminate Spotify using the plugin actions or via direct commands to the application and I do receive events when I change tracks (and pause/stop playing).

EDIT: Deleted version, see below



BR
Last edited by krambriw on Mon Dec 30, 2013 7:15 am, edited 1 time in total.

leothlon
Experienced User
Posts: 59
Joined: Tue Dec 17, 2013 6:29 pm

Re: Spotify

Post by leothlon » Fri Dec 27, 2013 2:22 pm

It still only gives me trigger eventss if spotify was already running when EG starts.
If i then terminate spotify to start it again i wont get events in EG.

same goes if i start EG without spotify running and then start it, no events.

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Spotify

Post by krambriw » Fri Dec 27, 2013 8:06 pm

w7 64 bit?

I have only tested with Vista 32 bit

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Spotify

Post by krambriw » Sat Dec 28, 2013 7:09 am

Now also tested with w7 64 bit,
See your problems, working only if Spotify is already started AND you run EG as admin (you have to run EG as admin, otherwise access right limitation prevents EG from controlling Spotify and also preventing EG from saving it's configurations).

In w7 64 bit, a lot of problems with access rights is preventing previous working solutions from functioning...I do not know, maybe setting up user accounts somehow could solve the problems. You have to investigate if you can find a solution to the access rights problems, use a 32 bit environment or live with this limitation

BR

Image2.jpg

leothlon
Experienced User
Posts: 59
Joined: Tue Dec 17, 2013 6:29 pm

Re: Spotify

Post by leothlon » Sat Dec 28, 2013 10:37 am

Is there anything in the code that runs on start that makes it work when spotify is already started?
or that runs in older windows when it notice spotify starts?
would it be possible to make that a eventghost function?

couse in that case maby a workaround is to add eventghost plugin proccess watcher, then when it notice spotify.exe start event it launches that function and the spotifyplugin "re-attatches" itself

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Spotify

Post by krambriw » Sun Dec 29, 2013 9:48 am

I found the reason why it did not work unless Spotify was already started ;)
In w7, I think you have to run EG as admin anyway to have full control of the Spotify application

See first post for published version
Last edited by krambriw on Mon Dec 30, 2013 1:20 pm, edited 1 time in total.

leothlon
Experienced User
Posts: 59
Joined: Tue Dec 17, 2013 6:29 pm

Re: Spotify

Post by leothlon » Sun Dec 29, 2013 1:00 pm

It seems to be working great now! Thank you so much.

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Spotify

Post by krambriw » Mon Dec 30, 2013 1:21 pm

See first post for published version

Silverhawk
Posts: 16
Joined: Sun Nov 10, 2013 6:19 pm

Re: Spotify

Post by Silverhawk » Sun Jan 05, 2014 12:15 pm

Using it a lot,t hanks for this krambriw! I use it to remotely control my spotify from my tablet/phone, with the events I can keep an updated notification on my phone/tablet as well with the current song that is playing.

One thing doesn't work properly though, next playlist/previous playlist/Last Playlist. When you are in the wrong selection it doesn't work. To get the selection into playlist three use ctrl+L (go to search bar), sleep, tab. Changed the code a bit in my plugin and it seems to work every time.

BTW: Is there any way you could add a command to get the playlist name?

My edited go to last playlist class:

Code: Select all

class GoToPlayList(eg.ActionClass):
    name = "Go to playlists tree view and start playing the last one"
    description = "Go to Playlist tree view and start playing"


    def __call__(self):
        sh = win32com.client.Dispatch("WScript.Shell")
        win32api.Sleep(100)
        if self.plugin.bSpotifyObjectCreated:
            hWnd = win32gui.FindWindow("SpotifyMainWindow", None)
            BringHwndToFront(hWnd)
            win32api.Sleep(200)
            sh.AppActivate("spotify")
            win32api.Sleep(500)
            sh.SendKeys("^l")
            win32api.Sleep(100)
            sh.SendKeys("{TAB}")
            win32api.Sleep(100)
            sh.SendKeys("{END}")
            win32api.Sleep(100)
            sh.SendKeys("{ENTER}")
            del hWnd
        del sh
        return

Post Reply