0
votes

I am using JohnnyCrazy/SpotifyAPI-NET for this application in Visual Studio.

The code creates a playlist just fine, but I can't modify it in any way(adding tracks, making the playlist private/public).

I am using the right scope (Scope.PlaylistModifyPrivate | Scope.PlaylistModifyPublic)

private FullPlaylist currentPlaylist;    

public void DoThisStuff()
    {
        _profile = _spotify.GetPrivateProfile();
        currentPlaylist = _spotify.CreatePlaylist(_profile.Id, Convert.ToString(DateTime.Now), false);
        _spotify.AddPlaylistTrack(_profile.Id, currentPlaylist.Uri, "41VtJHghmomTfNrbTSF2Uj");            
    }    
4

4 Answers

0
votes

ok I found the solution:

currentPlaylist.Uri 

That code gives me this: spotify:user:myname:playlist:02DfsHuBWwi1aCp8kxwVrs

but what I need is just the id at the end, so I cut it with

currentPlaylist.Uri.Substring(30)

An imperfect solution, as it will cause errors when the username has a different length than 7, but it works for now.

0
votes

This solution is slightly less imperfect than the one you came up with.

currentPlaylist.Uri.Split(new[] {":playlist:"}, StringSplitOptions.None)[1]);
0
votes
string playListUri = playlist.Uri.Substring(playlist.Uri.LastIndexOf(":") + 1);

Clean way to get URI from the string.

0
votes

spotify:user:myname:playlist:02DfsHuBWwi1aCp8kxwVrs is separated by : so that you can split the string in multiple sub-strings. You then select the string you are interested in like so:

currentPlaylist.Uri.Split(':')[4] // Returns 02DfsHuBWwi1aCp8kxwVrs