RMMSecurity / spotify-local-api

Automatically exported from code.google.com/p/spotify-local-api
0 stars 0 forks source link

Playlists information #4

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It's not an issue, but adding a function to get playlists information 'd be 
awesome. From the home page I see it'll be added soon.

The only way I've found is to request 
https://embed.spotify.com/?uri=playlist_URI
With the new Spotify update, playlists are now stored in 
/AppData/Local/Spotify/mercury.db, but I've still not found a way to read the 
database.
Is there another method?

Thanks.

Original issue reported on code.google.com by Jito...@gmail.com on 17 Mar 2013 at 1:37

GoogleCodeExporter commented 9 years ago
Thx for the info! I added a little something for this.
This snippet returns all URIs of a playlist as JSON.
First you need to add the HTML Agility Pack 
(http://htmlagilitypack.codeplex.com/)

And of course: using HtmlAgilityPack;

/// <summary>
/// Get URIs for the songs of the playlist
/// </summary>
/// <param name="uri">The playlist URI</param>
/// <returns>JSON object with song URIs</returns>
public string getPlaylist(string uri)
{
    try
    {
        string raw = new WebClient().DownloadString(string.Format("https://embed.spotify.com/?uri={0}", uri));
        HtmlDocument document = new HtmlDocument();
        document.LoadHtml(raw);

        HtmlNodeCollection collection = document.DocumentNode.SelectNodes("//li[@data-track]");
        List<string> songlinks = new List<string>();    
        foreach (HtmlNode link in collection)
        {
            songlinks.Add("spotify:track:" + link.Attributes["data-track"].Value);
        }
        return JsonConvert.SerializeObject(songlinks);
    }
    catch
    {
        return "";
    }
}

@author: if you want you can add this code!

Original comment by Killm...@gmail.com on 15 Jul 2013 at 10:48

GoogleCodeExporter commented 9 years ago
Hi, I've been using this and it's pretty cool. Is there anyway to get the URI 
of the current playlist? I've downloaded the HTML agility pack, and started 
using it, but there's no way to get the current playlist URI.

Original comment by davegkra...@gmail.com on 24 Jul 2013 at 4:43

GoogleCodeExporter commented 9 years ago
Unfortunately it's not working properly anymore because the embedded playlists 
are now limited to the first 200 songs only :(

Original comment by Jito...@gmail.com on 20 Aug 2013 at 9:37