using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; namespace Sony.Filtr.AppleMusic.Models { public class GenreAttributes { public string name { get; set; } } public class GenreData { public GenreAttributes attributes { get; set; } public string href { get; set; } public long id { get; set; } public string type { get; set; } } public class ChartGenresResponse { public List data { get; set; } } public class ChartAlbumAttributes { public string artistName { get; set; } public Artwork artwork { get; set; } public string copyright { get; set; } public EditorialNotes editorialNotes { get; set; } public List genreNames { get; set; } public bool isComplete { get; set; } public bool isSingle { get; set; } public string name { get; set; } public PlayParams playParams { get; set; } public string releaseDate { get; set; } public int trackCount { get; set; } public string url { get; set; } } public class ChartPlaylistAttributes { public Artwork artwork { get; set; } public bool isChart { get; set; } public string url { get; set; } public string lastModifiedDate { get; set; } public string name { get; set; } public string playlistType { get; set; } public string curatorName { get; set; } public PlayParams playParams { get; set; } public EditorialNotes description { get; set; } } public class ChartAlbumData { public ChartAlbumAttributes attributes { get; set; } public string href { get; set; } public long id { get; set; } public string type { get; set; } } public class ChartAlbum { public string chart { get; set; } public List data { get; set; } public string href { get; set; } public string name { get; set; } public string next { get; set; } } public class ChartPlaylist { public string name { get; set; } public string chart { get; set; } public string href { get; set; } public string next { get; set; } public List data { get; set; } } public class ChartPlaylistData { public string id { get; set; } public string type { get; set; } public ChartPlaylistAttributes attributes { get; set; } public string href { get; set; } } public class SongPlayParams { public string id { get; set; } public string kind { get; set; } } public class ChartSongAttributes { public string artistName { get; set; } public Artwork artwork { get; set; } public int discNumber { get; set; } public int durationInMillis { get; set; } public List genreNames { get; set; } public string name { get; set; } public SongPlayParams playParams { get; set; } public string releaseDate { get; set; } public int trackNumber { get; set; } public string url { get; set; } public string isrc { get; set; } } public class ChartSong { public string chart { get; set; } public List data { get; set; } public string href { get; set; } public string name { get; set; } public string next { get; set; } } public class ChartMusicVideo { public string name { get; set; } public string chart { get; set; } public string href { get; set; } public string next { get; set; } public List data { get; set; } } public class ChartMusicVideoData { public long id { get; set; } public string type { get; set; } public string href { get; set; } public ChartMusicVideoAttributes attributes { get; set; } } public class ChartMusicVideoAttributes { public string url { get; set; } public string name { get; set; } public List genreNames { get; set; } public string artistName { get; set; } public string releaseDate { get; set; } public Artwork artwork { get; set; } public PlayParams playParams { get; set; } public string contentRating { get; set; } public int durationInMillis { get; set; } } public class PlaylistListChartSongsData { public readonly IReadOnlyList ChartSongs; public readonly DateTime PlaylistLastModifiedDate; public readonly string Storefront; public PlaylistListChartSongsData(PlaylistData playlist, string storefront) { this.ChartSongs = playlist?.relationships?.tracks?.data? .Where(p => p.attributes != null) .Select(t => new ChartSongData { attributes = GetAttributes(t.attributes), href = t.href, id = t.id, type = t.type }) .ToList() .AsReadOnly(); this.PlaylistLastModifiedDate = DateTime.Parse(playlist.attributes.lastModifiedDate); this.Storefront = storefront; } public bool HasData { get { return this.ChartSongs != null; } } private static ChartSongAttributes GetAttributes(TrackAttributes trackAttributes) { return new ChartSongAttributes { artistName = trackAttributes.artistName, artwork = trackAttributes.artwork != null ? new Artwork { bgColor = trackAttributes.artwork.bgColor, url = trackAttributes.artwork.url, height = trackAttributes.artwork.height, textColor1 = trackAttributes.artwork.textColor1, textColor2 = trackAttributes.artwork.textColor2, textColor3 = trackAttributes.artwork.textColor3, textColor4 = trackAttributes.artwork.textColor4, width = trackAttributes.artwork.width } : null, discNumber = trackAttributes.discNumber, durationInMillis = trackAttributes.durationInMillis, genreNames = trackAttributes.genreNames, name = trackAttributes.name, releaseDate = trackAttributes.releaseDate, trackNumber = trackAttributes.trackNumber, url = trackAttributes.url, isrc = trackAttributes.isrc }; } } public class ChartSongData { public ChartSongAttributes attributes { get; set; } public string href { get; set; } public long id { get; set; } public string type { get; set; } } public class ChartResults { public List albums { get; set; } public List songs { get; set; } public List playlists { get; set; } [JsonProperty(PropertyName = "music-videos")] public List musicVideos { get; set; } } public class ChartResponse { public ChartResults results { get; set; } } }