Example #1
0
        private static Genre[] GetGenres(JToken item)
        {
            // Extract genres...
            Genre[] genres     = null;
            JArray  jsonGenres = item.Value <JArray>("genres");

            if (jsonGenres != null)
            {
                var list = new List <Genre>();
                foreach (JToken jsonGenre in jsonGenres)
                {
                    list.Add(Genre.FromJToken(jsonGenre));
                }

                genres = list.ToArray();
            }

            return(genres);
        }
Example #2
0
        /// <summary>
        /// Creates a Product from a JSON Object
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns>A Product object</returns>
        internal static Product FromJToken(JToken item)
        {
            if (item == null)
            {
                return(null);
            }

            // Extract category...
            Category category     = Category.Unknown;
            JToken   jsonCategory = item["category"];

            if (jsonCategory != null)
            {
                category = ParseHelper.ParseEnumOrDefault <Category>(jsonCategory.Value <string>("id"));
            }

            // Extract genres...
            Genre[] genres     = null;
            JArray  jsonGenres = item.Value <JArray>("genres");

            if (jsonGenres != null)
            {
                List <Genre> list = new List <Genre>();
                foreach (JToken jsonGenre in jsonGenres)
                {
                    list.Add((Genre)Genre.FromJToken(jsonGenre));
                }

                genres = list.ToArray();
            }

            // Extract takenfrom...
            Product takenFrom     = null;
            JToken  jsonTakenFrom = item["takenfrom"];

            if (jsonTakenFrom != null)
            {
                takenFrom = (Product)FromJToken(jsonTakenFrom);
            }

            // Extract price...
            Price  price      = null;
            JToken jsonPrices = item["prices"];

            if (jsonPrices != null)
            {
                JToken jsonPermDownload = jsonPrices["permanentdownload"];
                if (jsonPermDownload != null)
                {
                    price = Price.FromJToken(jsonPermDownload);
                }
            }

            // Extract Artists...
            Artist[] performers = null;

            if (item["creators"] != null)
            {
                JArray jsonArtists = item["creators"].Value <JArray>("performers");
                if (jsonArtists != null)
                {
                    List <Artist> list = new List <Artist>();
                    foreach (JToken jsonArtist in jsonArtists)
                    {
                        list.Add((Artist)Artist.FromJToken(jsonArtist));
                    }

                    performers = list.ToArray();
                }
            }

            // Extract trackcount...
            int?   trackCount     = null;
            JToken jsonTrackCount = item["trackcount"];

            if (jsonTrackCount != null)
            {
                trackCount = item.Value <int>("trackcount");
            }

            // Extract thumbnails...
            Uri square50  = null;
            Uri square100 = null;
            Uri square200 = null;
            Uri square320 = null;

            MusicItem.ExtractThumbs(item["thumbnails"], out square50, out square100, out square200, out square320);

            // Create the resulting Product object...
            var product = new Product()
            {
                Id                = item.Value <string>("id"),
                Name              = item.Value <string>("name"),
                Thumb50Uri        = square50,
                Thumb100Uri       = square100,
                Thumb200Uri       = square200,
                Thumb320Uri       = square320,
                Category          = category,
                Genres            = genres,
                TakenFrom         = takenFrom,
                Price             = price,
                TrackCount        = trackCount,
                Tracks            = ExtractTracks(item["tracks"]),
                Performers        = performers,
                Duration          = item.Value <int>("duration"),
                VariousArtists    = item.Value <bool>("variousartists"),
                StreetReleaseDate = item.Value <DateTime>("streetreleasedate"),
                SellerStatement   = item.Value <string>("sellerstatement"),
                Label             = item.Value <string>("label")
            };

            var sequence = item.Value <int>("sequence");

            if (sequence >= 1)
            {
                product.Sequence = sequence;
            }

            return(product);
        }