Example #1
0
 public PlaylistModel(PlaylistModel playlist)
 {
     Name        = playlist.Name;
     Description = playlist.Description;
     Tracks      = new List <TrackModel>(playlist.Tracks);
     Subscribers = new List <string>(playlist.Subscribers);
     Creator     = playlist.Creator;
     Image       = playlist.Image;
 }
Example #2
0
        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);
        }
Example #3
0
 public TrackModel()
 {
     Artists  = new List <ArtistModel>();
     Album    = new AlbumModel();
     Playlist = new PlaylistModel();
 }