public void BuildArtistNameUrl()
        {
            var artistName = "Muse";
            var result     = new ArtistImageUriWriter(ArtistImageUriWriterTests.Settings).BuildForName(artistName, 200, 200);

            Assert.AreEqual("http://www.testme.com/1.x/gb/creators/images/200x200/random/?domain=music&client_id=ClientId&lang=en&name=Muse", result.AbsoluteUri);
        }
Exemple #2
0
        /// <summary>
        /// Creates a Mix from a JSON Object
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="settings">The settings.</param>
        /// <returns>
        /// A Mix object
        /// </returns>
        internal static Mix FromJToken(JToken item, IMusicClientSettings settings)
        {
            const string PlayMeThumbUri = "http://dev.mixrad.io/assets/playme/{0}x{0}.png";

            if (item == null)
            {
                return(null);
            }

            bool   parentalAdvisory      = false;
            JToken parentaladvisoryToken = item["parentaladvisory"];

            if (parentaladvisoryToken != null)
            {
                parentalAdvisory = item.Value <bool>("parentaladvisory");
            }

            JToken featuredArtists     = item["featuredartists"];
            var    featuredArtistsList = new List <Artist>();

            if (featuredArtists != null)
            {
                foreach (JToken token in featuredArtists)
                {
                    Artist artist = Artist.FromJToken(token, settings);
                    featuredArtistsList.Add(artist);
                }
            }

            Uri square50  = null;
            Uri square100 = null;
            Uri square200 = null;
            Uri square320 = null;
            Uri square640 = null;

            var thumbnailsToken = item["thumbnails"];

            MusicItem.ExtractThumbs(thumbnailsToken, out square50, out square100, out square200, out square320);

            if (thumbnailsToken != null)
            {
                square640 = Mix.ExtractThumb(thumbnailsToken, "640x640");
            }

            var            seeds          = item["seeds"];
            SeedCollection seedCollection = null;

            if (seeds != null)
            {
                seedCollection = SeedCollection.FromJson(item.ToString());
            }
            else
            {
                var mixId = item.Value <string>("id");

                if (!string.IsNullOrEmpty(mixId))
                {
                    seedCollection = new SeedCollection(Seed.FromMixId(mixId));
                }
            }

            var name = item.Value <string>("name");

            var description = item.Value <string>("description");

            if (seedCollection != null && seedCollection.Count > 0)
            {
                if (seedCollection.Count(s => s.Type == SeedType.UserId) > 0)
                {
                    if (square50 == null)
                    {
                        square50 = new Uri(string.Format(PlayMeThumbUri, 50));
                    }

                    if (square100 == null)
                    {
                        square100 = new Uri(string.Format(PlayMeThumbUri, 100));
                    }

                    if (square200 == null)
                    {
                        square200 = new Uri(string.Format(PlayMeThumbUri, 200));
                    }

                    if (square320 == null)
                    {
                        square320 = new Uri(string.Format(PlayMeThumbUri, 320));
                    }

                    if (square640 == null)
                    {
                        square640 = new Uri(string.Format(PlayMeThumbUri, 640));
                    }

                    if (string.IsNullOrEmpty(name))
                    {
                        name = "Play Me";
                    }
                }
                else if (seedCollection.Count(s => s.Type == SeedType.ArtistId) > 0)
                {
                    var artistSeeds = seedCollection.Where(s => (s.Type == SeedType.ArtistId)).ToArray();

                    if (string.IsNullOrEmpty(name))
                    {
                        // Derive a name
                        var names = artistSeeds.Select(s => s.Name).Where(s => !string.IsNullOrEmpty(s)).ToArray();

                        name = names.Length > 0
                                ? string.Join(", ", names)
                                : "Artist Mix";
                    }

                    // Derive a thumbnail image
                    var idSeed = artistSeeds.FirstOrDefault(s => !string.IsNullOrEmpty(s.Id));
                    if (idSeed != null && settings != null)
                    {
                        var builder = new ArtistImageUriWriter(settings);

                        if (square50 == null)
                        {
                            square50 = builder.BuildForId(idSeed.Id, 50);
                        }

                        if (square100 == null)
                        {
                            square100 = builder.BuildForId(idSeed.Id, 100);
                        }

                        if (square200 == null)
                        {
                            square200 = builder.BuildForId(idSeed.Id, 200);
                        }

                        if (square320 == null)
                        {
                            square320 = builder.BuildForId(idSeed.Id, 320);
                        }

                        if (square640 == null)
                        {
                            square640 = builder.BuildForId(idSeed.Id, 640);
                        }
                    }
                }
            }

            return(new Mix()
            {
                Name = name,
                TrackCount = item.Value <int>("numbertracks"),
                ParentalAdvisory = parentalAdvisory,
                Seeds = seedCollection,
                Thumb50Uri = square50,
                Thumb100Uri = square100,
                Thumb200Uri = square200,
                Thumb320Uri = square320,
                Thumb640Uri = square640,
                Description = description,
                FeaturedArtists = featuredArtistsList
            });
        }