aauren / SpotifyToaster

Presents toast notifications (system tray popups) when Spotify changes songs
GNU General Public License v2.0
21 stars 3 forks source link

Add Album Title and Track Number To Notification #4

Closed aauren closed 10 years ago

aauren commented 10 years ago

SpotifyToaster doesn't currently display the album name because the Spotify window title doesn't contain that information. However, it might be possible to derive that information from a music web service.

ranveer5289 commented 10 years ago

Hi,

You can use Last.fm API for this purpose. Last.fm api provides a method track.getInfo which provides Album details and Album art based on the track and artist name.

To get album art you can refer to getAlbumArt method. Last.fm API

You can use the API in following ways:

  1. Last.fm C# API
  2. Directly creating and accessing the API url and than parsing the XML/Json response.

There is another service called musicbrainz . I have not explored it much but it is quite popular.

Thanks, Ranveer Raghuwanshi

aauren commented 10 years ago

Thanks @ranveer5289! I was actually in the process of implementing a class for getting artwork that is very similar to what you guys did with LastFM when you wrote that.

I was originally hoping that I could use the same cached artwork that the Spotify app uses, but that proved too difficult to parse. So instead, I ended up falling back on the same method you guys used.

I am considering adding an alternate method of getting the current song though. If the user has the LastFM integration configured in Spotify, then an app could either poll their LastFM recent tracks list, or sniff the packets coming from Spotify and going to LastFM to determine a song change.

It seems like a lot of work, but it would be possible to get: Artist, Track Title, Track Number, Album, and Length from the LastFM integration which seems intriguing.

ranveer5289 commented 10 years ago

Hi @aauren ,

Your way to poll the users LastFM recent track list to get current playing song seems a bit inefficient to me. What my current code does is it listens for the "Name Change" event fired by spotify and than get the song name, it never polls spotify it just waits for the event.

In general event driven mechanism is better than polling mechanism.

If you went with the LastFm approach you need to consider the following issues:

  1. What if the user doesn't use LastFM service than in that case you need to fallback to your current way as an alternative.
  2. If you go with the LastFm approach you are creating a dependency on it to get the current song and than you need to consider the network latency issue as well. I have observed sometimes the update to last.fm is not that quick and it take a little time which will lead to bad user experience.

In general you should always try to minimize the dependency on third party services until n unless your current application doesn't supports a way to achieve what you are trying to get.

So, what you can do is use Lastfm service in addition to your current already implemented approach.

Now, what sounds intriguing to me me is sniffing packets from spotify. This is something which we can use to identify spotify's advertisements for non-premium user and than mute the system volume so that they are not disturbed by it. I am interested in learning this, do share a tutorial/blog post on how you sniffed the spotify packets and extracted metadata from it.

One more thing, does your application shows notification when advertisement are played in spotify because my original application used to display an empty notification each time ads use to play. So, I was thinking sniffing packets could help me in this thing.

Thanks, Ranveer Raghuwanshi

aauren commented 10 years ago

@ranveer5289 I understand what you're saying about polling notifications being less optimal. Chances are that I would use a hybrid approach and only poll once I saw that the window title was changed. This would reduce the polling overhead and hopefully the lag that polling usually incurs as well. This seems a lot easier than monitoring packets. But like you said it would only work if LastFM updated quickly enough, otherwise, there would be a frustrating lag that users probably wouldn't like. Also, as you pointed out, it would only work for users that enabled the LastFM integration, so it would have to be a configurable option.

Packet monitoring is a more complete solution, but it seems difficult. If I ever end up introducing that feature I'll be sure to write up something in the wiki explaining how it is done. But tentatively, I had planned on pursuing SharpPcap which is a C# wrapper for WinPcap which is what Wireshark uses: http://www.codeproject.com/Articles/12458/SharpPcap-A-Packet-Capture-Framework-for-NET

I've already used Wireshark and could see the LastFM HTTP packet being sent by Spotify, so I know that the data exists and is capturable, but actually writing what is necessary to get it inside my app is another matter. I think that with this solution as well I would also take a hybrid approach and both watch the window name as well as do the packet monitoring so that way it didn't have to monitor traffic the whole time. This approach also has a downside of snooping on the user's network data. I'm not sure that end users will like the idea of installing an application that monitors their network traffic, even if it is benign and gives them functionality.

I believe that you're correct and that monitoring the LastFM integration might be a method to auto-mute Spotify's ads. For example, if you see the window title change, but don't receive a LastFM packing withing x number of seconds, then mute until the window title changes again. I pay for an unlimitted account so it's not my intention to do anything with the ads in this application and I would fear that if it caught on, and Spotify didn't like it, that they might remove the LastFM integration just to stop people from circumventing their ads.

Since I have an unlimitted account I'm not sure what my app does when an ad comes on. My guess is that it would probably still display a toast notification since that piece is based on your code and that's what you said your application does. I would love to hear from someone who uses the app and has a free account so that I know for sure. If the formatting of the window title is different enough, and in an identifiable way, then I might be able to mitigate this problem.