コード例 #1
0
        public void FindBySong(Song song, SongBucket bucket)
        {
            var result = echo.Query <Search>().Execute(new SearchArgument
            {
                Title  = song.Name,
                Artist = song.Artist.Name,
                Bucket = bucket
            });

            if (result.Status.Code != ResponseCode.Success)
            {
                return;
            }

            TheEchoNest echosong = database.TheEchoNest.FindBySongName(song.Name);

            if (echosong == null)
            {
                return;
            }

            var track = result.Songs.FirstOrDefault();

            this.UpdateAudioProperties(echosong, track);
            echosong.Song = song;

            SaveIntoDatabase();
        }
コード例 #2
0
ファイル: SongTests.cs プロジェクト: VirUZI/echonest-sharp
        public void GetSongs_Profile_ExpectedArtist()
        {
            const string     songId             = "spotify-WW:track:0hAN0b6tSBuHMIvBGGdXNP";
            const string     songId2            = "spotify-WW:track:6zrGHFJzIaGv2O02dDay1k";
            const string     expectedEchoNestId = "SOAEDJD13F6397EE1A";
            const SongBucket buckets            = SongBucket.AudioSummary | SongBucket.SongType;

            //act
            using (EchoNestSession session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey")))
            {
                var profileResponse = session.Query <Song.Profile>().Execute(new[] { new IdSpace(songId), new IdSpace(songId2) }, buckets);

                //assert
                Assert.IsNotNull(profileResponse);
                Assert.IsNotNull(profileResponse.Songs);
                Assert.IsTrue(profileResponse.Songs.Count == 2);

                var songExists = profileResponse.Songs.Any(song => song.ID == expectedEchoNestId);
                Assert.IsTrue(songExists, "Song does not exist in profile response");

                // output
                Console.WriteLine("Tracks for profile '{0}'", songId);
                foreach (SongBucketItem song in profileResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
                Console.WriteLine();
                Console.WriteLine();
            }
        }
コード例 #3
0
        public static IEnumerable <string> GetBucketDescriptions(this SongBucket bucket)
        {
            var buckets = bucket.GetBuckets();

            foreach (var b in buckets)
            {
                yield return(GetDescription(b));
            }
        }
コード例 #4
0
        public static IEnumerable <SongBucket> GetBuckets(this SongBucket bucket)
        {
            var buckets = bucket.ToString().Split(',');

            foreach (var s in buckets)
            {
                SongBucket parsed;
                if (Enum.TryParse(s.Trim(), out parsed))
                {
                    yield return(parsed);
                }
            }
        }