Closed marcguillemdev closed 5 years ago
Hey @DanixPC, not abandoned- I have just been busy with other projects. Still supporting the library and happy to implement any endpoints you need π
I'm glad to read that, so I need to get the complete song list from a playlist. Once I have the playlist I want to get the title and artist of each song.
This is my code now:
public async void get_spotify_playlist(string playlist) { var http = new HttpClient(); var accounts = new AccountsService(http); var plapi = new PlaylistsApi(http, accounts); var pl = await plapi.GetPlaylist("1tpXaFf2F55E7kVJON4j4G"); var pl_tr = pl.Tracks. }
So i need something like var tracks = pl.GetTracks();
After, i use something like tracks.ElementAt(0).Title;
Thank you so much in advance. ππ
No problem! I'll take a look at this tonight - shouldn't take long.
Hey @DanixPC, this is already implemented as IPlaylistsApi.GetTracks(string playlistId)
e.g.
var http = new HttpClient();
var accounts = new AccountsService(http);
var plapi = new PlaylistsApi(http, accounts);
var pl = await plapi.GetTracks("37i9dQZF1DX3WvGXE8FqYX");
var pl_tr = pl.Items.ElementAt(0).Track.Name;
Give it a try π
@DanielLarsenNZ Works like a charm! Thank you so much boss!
But i have a only problem, in this case, the playlist contains at least more than 100 songs, and the api only returns the firts 100. Maybe im forgetting a parameter or something, i dont know.
Try this:
var pl = await plapi.GetTracks("4h4urfIy5cyCdFOc1Ff4iN", offset: 100);
I've added a more complete Playlists example to README.md
// Page through a list of tracks in a Playlist
var playlists = new PlaylistsApi(http, accounts);
int limit = 100;
var playlist = await playlists.GetTracks("4h4urfIy5cyCdFOc1Ff4iN", limit: limit);
int offset = 0;
int j = 0;
// using System.Linq
while (playlist.Items.Any())
{
for (int i = 0; i < playlist.Items.Length; i++)
{
Trace.WriteLine($"Track #{j += 1}: {playlist.Items[i].Track.Artists[0].Name} / {playlist.Items[i].Track.Name}");
}
offset += limit;
playlist = await playlists.GetTracks("4h4urfIy5cyCdFOc1Ff4iN", limit: limit, offset: offset);
}
Thank you so much, it worked! Again thanks for your patience and work! ;)
Youβre welcome! π
Im making a playlist coverter from Spotify to Deezer but all wrappers requiere auth excepting this. :(