public static async Task <TrackModel> FromLibrary(Track unmanagedTrack, LoadifySession session) { var trackModel = new TrackModel(unmanagedTrack); if (unmanagedTrack == null) { return(trackModel); } await SpotifyObject.WaitForInitialization(unmanagedTrack.IsLoaded); trackModel.Name = unmanagedTrack.Name(); trackModel.Duration = TimeSpan.FromMilliseconds(unmanagedTrack.Duration()); trackModel.Rating = unmanagedTrack.Popularity(); trackModel.Album = await AlbumModel.FromLibrary(unmanagedTrack.Album(), session); for (var j = 0; j < unmanagedTrack.NumArtists(); j++) { var unmanagedArtist = unmanagedTrack.Artist(j); if (unmanagedArtist == null) { continue; } trackModel.Artists.Add(await ArtistModel.FromLibrary(unmanagedArtist, session)); } return(trackModel); }
public static async Task <PlaylistModel> FromLibrary(Playlist unmanagedPlaylist, LoadifySession session) { var playlistModel = new PlaylistModel(unmanagedPlaylist); if (unmanagedPlaylist == null) { return(playlistModel); } await SpotifyObject.WaitForInitialization(unmanagedPlaylist.IsLoaded); playlistModel.Name = unmanagedPlaylist.Name() ?? ""; playlistModel.Subscribers = unmanagedPlaylist.Subscribers().ToList(); playlistModel.Creator = unmanagedPlaylist.Owner().DisplayName() ?? ""; playlistModel.Description = unmanagedPlaylist.GetDescription() ?? ""; var playlistImageId = unmanagedPlaylist.GetImage(); if (playlistImageId != null) { var playlistImage = session.GetImage(playlistImageId); await SpotifyObject.WaitForInitialization(playlistImage.IsLoaded); playlistModel.Image = playlistImage.Data(); } for (var i = 0; i < unmanagedPlaylist.NumTracks(); i++) { var unmanagedTrack = unmanagedPlaylist.Track(i); if (unmanagedTrack == null) { continue; } var managedTrack = await TrackModel.FromLibrary(unmanagedTrack, session); managedTrack.Playlist = playlistModel; playlistModel.Tracks.Add(managedTrack); } return(playlistModel); }