public static YTrackResponse FromJson(JToken jTrack)
        {
            try
            {
                var track = new YTrackResponse
                {
                    Id        = jTrack.GetString("id"),
                    RealId    = jTrack.GetString("realId"),
                    Title     = jTrack.GetString("title"),
                    Major     = YMajor.FromJson(jTrack.Contains("major")),
                    Available = jTrack.GetBool("available"),
                    AvailableForPremiumUsers = jTrack.GetBool("availableForPremiumUsers"),
                    Albums = jTrack.ContainField("albums")
            ? YAlbumResponse.FromJsonArray(jTrack["albums"].ToObject <JArray>())
            : null,
                    DurationMS = jTrack["durationMs"].ToObject <int>(),
                    StorageDir = jTrack.GetString("storageDir"),
                    FileSize   = jTrack.GetInt("fileSize"),
                    Artists    = YArtistResponse.FromJsonArray(jTrack["artists"].ToObject <JArray>()),
                    OgImage    = jTrack.GetString("ogImage")
                };
                return(track);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(null);
        }
Beispiel #2
0
        public static YAlbumResponse FromJson(JToken jAlbum)
        {
            var album = new YAlbumResponse
            {
                Artists   = YArtistResponse.FromJsonArray(jAlbum["artists"].ToObject <JArray>()),
                Available = jAlbum.GetBool("available"),
                AvailableForPremiumUsers = jAlbum.GetBool("availableForPremiumUsers"),
                CoverUri            = jAlbum.GetString("coverUri"),
                Genre               = jAlbum.GetString("genre"),
                Id                  = jAlbum.GetString("id"),
                OriginalReleaseYear = jAlbum.GetString("originalReleaseYear"),
                Regions             = jAlbum.Contains("regions")
          ? jAlbum["regions"].ToObject <JArray>().Select(x => (string)x).ToList()
          : null,
                StorageDir = jAlbum.GetString("storageDir"),
                Title      = jAlbum.GetString("title"),
                TrackCount = jAlbum.GetInt("trackCount"),
                Year       = jAlbum.GetString("year"),
                Bests      = jAlbum.ContainField("bests")
          ? jAlbum["bests"].ToObject <JArray>().Select(x => x.ToString()).ToList()
          : null,
                Type = jAlbum.GetString("type"),
            };

            if (jAlbum.ContainField("volumes"))
            {
                if (jAlbum["volumes"].ToString() != String.Empty)
                {
                    var fieldVolumes = jAlbum["volumes"].ToObject <JArray>().FirstOrDefault();
                    if (fieldVolumes != null)
                    {
                        var jVolumes = fieldVolumes.ToObject <JArray>();
                        var tracks   = YTrackResponse.FromJsonArray(jVolumes);
                        album.Volumes = new List <List <YTrackResponse> > {
                            tracks
                        };
                    }
                    else
                    {
                        album.Volumes = null;
                    }
                }
            }
//      album.Volumes = jAlbum.ContainField("volumes")
//        ? new List<List<Track>>
//        {
//          Track.FromJsonArray(jAlbum["volumes"].ToObject<JArray>().First().ToObject<JArray>())
//        }
//        : null;

            return(album);
        }