public static IAlbum FromJson(JToken json, IDeezerClient client) { if (json == null) { return(null); } string apiDateString = json.Value <string>(RELEASE_DATE_PROPERTY_NAME); DateTime?releaseDate = DateTimeExtensions.ParseApiDateTime(apiDateString); return(new Album() { Id = json.Value <ulong>(ID_PROPERTY_NAME), Title = json.Value <string>(TITLE_PROPERTY_NAME), UPC = json.Value <string>(UPC_PROPERTY_NAME), Link = json.Value <string>(LINK_PROPERTY_NAME), ShareLink = json.Value <string>(SHARE_LINK_PROPERTY_NAME), CoverArtwork = Images.FromJson(json), GenreId = json.ValueOrDefault <ulong>(GENRE_ID_PROPERTY_NAME, 0), Genre = FragmentOf <IGenre> .FromJson(json[GENRE_LIST_PROPERTY_NAME], x => Api.Genre.FromJson(x, client)), Fans = json.Value <uint>(FANS_PROPERTY_NAME), Rating = json.Value <int>(RATING_PROPERTY_NAME), Label = json.Value <string>(LABEL_PROPERTY_NAME), TrackCount = json.Value <uint>(TRACK_COUNT_PROEPRTY_NAME), Duration = json.Value <uint>(DURATION_PROPERTY_NAME), ReleaseDate = releaseDate, Available = json.Value <bool>(AVAILABLE_PROPERTY_NAME), RecordType = json.Value <string>(RECORD_TYPE_PROPERTY_NAME), Contributors = CollectionOf <IArtist> .FromJson(json[CONTRIBUTORS_PROPERTY_NAME], x => Api.Artist.FromJson(x, client)), Artist = Api.Artist.FromJson(json[ARTIST_PROPERTY_NAME], client), TracklistInternal = FragmentOf <ITrack> .FromJson(json[TRACKS_PROPERTY_NAME], x => Api.Track.FromJson(x, client)), // ISessionObject Client = client, }); }
//TODO Readable //TODO Title_version //TODO Explicit public static ITrack FromJson(JToken json, IDeezerClient client) { var releaseDateString = json.Value <string>(RELEASE_PROPERTY_NAME); DateTime?releaseDate = DateTimeExtensions.ParseApiDateTime(releaseDateString); //TODO -> AvailableFrom property?? //var availabilityDateString = json.Value<String>(TimeAdd) /* Tracks don't always come with their own artwork. * Instead, we'll pinch the artwork from the 'Album' property * if this is available in the returned JSON. */ var containedInAlbum = Api.Album.FromJson(json[ALBUM_PROPERTY_NAME], client); var internalArtwork = Api.Images.FromJson(json); var actualArtwork = new TrackImages(containedInAlbum, internalArtwork?.Small, internalArtwork?.Medium, internalArtwork?.Large, internalArtwork?.ExtraLarge); bool hasAvailabiltyList = (json as JObject)?.ContainsKey(AVAILABLE_COUNTRY_PROPERTY_NAME) ?? false; // Json.Values<string>() is lazy, need to wrap and eval into a list at this point // as the underlying json is disposed as soon as the parsing has been completed. IEnumerable <string> availableInList = hasAvailabiltyList ? new List <string>(json[AVAILABLE_COUNTRY_PROPERTY_NAME].Values <string>()) : new List <string>(0); return(new Track() { Id = json.Value <ulong>(ID_PROPERTY_NAME), Title = json.Value <string>(TITLE_PROPERTY_NAME), ShortTitle = json.Value <string>(SHORT_TITLE_PROPERTY_NAME), ISRC = json.Value <string>(ISRC_PROPERTY_NAME), Link = json.Value <string>(LINK_PROPERTY_NAME), ShareLink = json.Value <string>(SHARE_LINK_PROPERTY_NAME), PreviewLink = json.Value <string>(PREVIEW_PROPERTY_NAME), Duration = json.Value <uint>(DURATION_PROPERTY_NAME), BPM = json.Value <float>(BPM_PROPERTY_NAME), Gain = json.Value <float>(GAIN_PROPERTY_NAME), TrackNumber = json.Value <uint>(TRACK_NUMBER_PROPERTY_NAME), DiscNumber = json.Value <uint>(DISC_NUMBER_PROPERTY_NAME), Rank = json.Value <uint>(RANK_PROPERTY_NAME), ReleaseDate = releaseDate, Artwork = actualArtwork, AvailableIn = availableInList, Artist = Api.Artist.FromJson(json[ARTIST_PROPERTY_NAME], client), Album = containedInAlbum, Contributors = CollectionOf <IArtist> .FromJson(json[CONTRIBUTORS_PROPERTY_NAME], x => Api.Artist.FromJson(x, client)), // ISssionObject Client = client, }); }