Beispiel #1
0
        public static void Display(EchoNestSession session)
        {
            ConsoleKeyInfo keyInfo;

            using (ConsoleEx.BeginColorBlock(ConsoleColor.Cyan))
            {
                Console.WriteLine("=== Playlist API ===");
                Console.WriteLine("1: Basic");
                Console.WriteLine("2: Static");
                Console.WriteLine("3: Dynamic");
                Console.WriteLine("=================");
            }

            ConsoleEx.Write("Enter api >> ", ConsoleColor.Green);
            keyInfo = Console.ReadKey();
            Console.Write(Environment.NewLine);

            switch (keyInfo.Key)
            {
            case ConsoleKey.D1:
                Basic(session);
                break;

            case ConsoleKey.D2:
                Basic(session);
                break;

            case ConsoleKey.D3:
                Basic(session);
                break;
            }
        }
Beispiel #2
0
        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();
            }
        }
        private static void Biographies(EchoNestSession session)
        {
            ConsoleEx.WriteLine("=== Biographies ===", ConsoleColor.Cyan);
            ConsoleEx.Write("Query >> ", ConsoleColor.Green);
            string query = Console.ReadLine();

            ConsoleEx.WriteLine("Searching..", ConsoleColor.Yellow);

            var result = session.Query<Biography>().Execute(query, numberOfResults: 1);

            if (result.Status.Code == ResponseCode.Success)
            {
                foreach (var biography in result.Biographies)
                {
                    ConsoleEx.WriteLine("Site:", ConsoleColor.White);
                    ConsoleEx.WriteLine(biography.Site, ConsoleColor.DarkYellow);
                    ConsoleEx.WriteLine("Biography text:", ConsoleColor.White);
                    ConsoleEx.WriteLine(biography.Text, ConsoleColor.DarkYellow);
                }
            }
            else
            {
                ConsoleEx.WriteLine(result.Status.Message, ConsoleColor.Red);
            }
        }
        private static void Profile(EchoNestSession session)
        {
            ConsoleEx.WriteLine("=== Song Search ===", ConsoleColor.Cyan);
            ConsoleEx.Write("Query >> ", ConsoleColor.Green);
            string query = Console.ReadLine();

            ConsoleEx.WriteLine("Searching..", ConsoleColor.Yellow);

            string id = "spotify:track:58HONnHW8ZvMDb4In757x4";

            // id = "TRNATAV144D0B601A7";
            var result = session.Query<Profile>().Execute(new ProfileArgument
                                                             {
                                                                 Id = id,
                                                                 Bucket = TrackBucket.AudioSummary
                                                             });

            if (result.Status.Code == ResponseCode.Success)
            {
                var item = result.Track;
                ConsoleEx.Write("Artist: ", ConsoleColor.White);
                ConsoleEx.WriteLine(item.Artist, ConsoleColor.DarkYellow);
                ConsoleEx.Write("Title: ", ConsoleColor.White);
                ConsoleEx.WriteLine(item.Title, ConsoleColor.DarkYellow);                
            }
            else
            {
                ConsoleEx.WriteLine(result.Status.Message, ConsoleColor.Red);
            }
        }
Beispiel #5
0
        private static void Search(EchoNestSession session)
        {
            ConsoleEx.WriteLine("=== Song Search ===", ConsoleColor.Cyan);
            ConsoleEx.Write("Query >> ", ConsoleColor.Green);
            string query = Console.ReadLine();

            ConsoleEx.WriteLine("Searching..", ConsoleColor.Yellow);

            var result = session.Query<Search>().Execute(new SearchArgument
                                                             {
                                                                 Title = query,
                                                                 Bucket = SongBucket.ArtistHotttness,
                                                                 Sort = "artist_hotttnesss-desc"
                                                             });

            if (result.Status.Code == ResponseCode.Success)
            {
                foreach (var item in result.Songs)
                {
                    ConsoleEx.Write("Artist: ", ConsoleColor.White);
                    ConsoleEx.WriteLine(item.ArtistName, ConsoleColor.DarkYellow);
                    ConsoleEx.Write("Hotttness: ", ConsoleColor.White);
                    ConsoleEx.WriteLine(item.ArtistHotttnesss.ToString(), ConsoleColor.DarkYellow);
                }
            }
            else
            {
                ConsoleEx.WriteLine(result.Status.Message, ConsoleColor.Red);
            }
        }
Beispiel #6
0
        private static void Blogs(EchoNestSession session)
        {
            ConsoleEx.WriteLine("=== Blogs ===", ConsoleColor.Cyan);
            ConsoleEx.Write("Query >> ", ConsoleColor.Green);
            string query = Console.ReadLine();

            ConsoleEx.WriteLine("Searching..", ConsoleColor.Yellow);

            var result = session.Query <Blog>().Execute(query, numberOfResults: 1);

            if (result.Status.Code == ResponseCode.Success)
            {
                foreach (var biography in result.Blogs)
                {
                    ConsoleEx.WriteLine("Name:", ConsoleColor.White);
                    ConsoleEx.WriteLine(biography.Name, ConsoleColor.DarkYellow);
                    ConsoleEx.WriteLine("Summary:", ConsoleColor.White);
                    ConsoleEx.WriteLine(biography.Summary, ConsoleColor.DarkYellow);
                    ConsoleEx.WriteLine("Url:", ConsoleColor.White);
                    ConsoleEx.WriteLine(biography.Url, ConsoleColor.DarkYellow);
                }
            }
            else
            {
                ConsoleEx.WriteLine(result.Status.Message, ConsoleColor.Red);
            }
        }
Beispiel #7
0
        private static void Profile(EchoNestSession session)
        {
            ConsoleEx.WriteLine("=== Song Search ===", ConsoleColor.Cyan);
            ConsoleEx.Write("Query >> ", ConsoleColor.Green);
            string query = Console.ReadLine();

            ConsoleEx.WriteLine("Searching..", ConsoleColor.Yellow);

            string id = "spotify:track:58HONnHW8ZvMDb4In757x4";

            // id = "TRNATAV144D0B601A7";
            var result = session.Query <Profile>().Execute(new ProfileArgument
            {
                Id     = id,
                Bucket = TrackBucket.AudioSummary
            });

            if (result.Status.Code == ResponseCode.Success)
            {
                var item = result.Track;
                ConsoleEx.Write("Artist: ", ConsoleColor.White);
                ConsoleEx.WriteLine(item.Artist, ConsoleColor.DarkYellow);
                ConsoleEx.Write("Title: ", ConsoleColor.White);
                ConsoleEx.WriteLine(item.Title, ConsoleColor.DarkYellow);
            }
            else
            {
                ConsoleEx.WriteLine(result.Status.Message, ConsoleColor.Red);
            }
        }
Beispiel #8
0
        public void GetBasicPlaylist_WhereArtistName_HasSongsByArtist(string artistName)
        {
            BasicArgument basicArgument = new BasicArgument
            {
                Results = 10,
                Dmca = true
            };

            TermList artistTerms = new TermList { artistName };
            basicArgument.Artist.AddRange(artistTerms);

            using (var session = new EchoNestSession(ApiKey))
            {
                PlaylistResponse searchResponse = session.Query<Basic>().Execute(basicArgument);

                Assert.IsNotNull(searchResponse);

                System.Diagnostics.Debug.WriteLine("Songs for : {0}", artistName);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    System.Diagnostics.Debug.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }

            }
        }
Beispiel #9
0
        private static void Profile(EchoNestSession session)
        {
            ConsoleEx.WriteLine("=== Profile ===", ConsoleColor.Cyan);
            ConsoleEx.Write("Query >> ", ConsoleColor.Green);
            string query = Console.ReadLine();

            ConsoleEx.WriteLine("Fetching..", ConsoleColor.Yellow);

            var result = session.Query <Profile>().Execute(new IdSpace(query), bucket: GetAllArtistBucket());

            if (result.Status.Code == ResponseCode.Success)
            {
                ConsoleEx.WriteLine("Name:", ConsoleColor.White);
                ConsoleEx.WriteLine(result.Artist.Name, ConsoleColor.DarkYellow);
                ConsoleEx.WriteLine("Hotttness:", ConsoleColor.White);
                ConsoleEx.WriteLine(result.Artist.Hotttnesss.ToString(), ConsoleColor.DarkYellow);

                foreach (var g in result.Artist.Genres)
                {
                    ConsoleEx.WriteLine("Genre:", ConsoleColor.White);
                    ConsoleEx.WriteLine(g.Name.ToString(), ConsoleColor.DarkYellow);
                }
            }
            else
            {
                ConsoleEx.WriteLine(result.Status.Message, ConsoleColor.Red);
            }
        }
Beispiel #10
0
        public async void GetArtistInfo(string artist, Action <string, Exception> callback)
        {
            Exception ex         = null;
            string    artistInfo = null;

            try
            {
                if (this.echoNestSession == null)
                {
                    var echoNestApiKey = await this.LoadApiKey();

                    this.echoNestSession = new EchoNestSession(echoNestApiKey);
                }

                var artistQuery = FormatArtistQuery(artist);
                var result      = this.echoNestSession.Query <Biography>().Execute(artistQuery);

                StringBuilder sb = new StringBuilder();
                foreach (var bio in result.Biographies)
                {
                    sb.Append(bio.Text);
                }

                artistInfo = sb.ToString();
            }
            catch (Exception e)
            {
                ex = e;
            }

            callback(artistInfo, ex);
        }
Beispiel #11
0
        public void GetBasicPlaylist_WhereArtistName_HasSongsByArtist(string artistName)
        {
            //arrange
            BasicArgument basicArgument = new BasicArgument
            {
                Results = 10,
                Dmca = true
            };

            TermList artistTerms = new TermList { artistName };
            basicArgument.Artist.AddRange(artistTerms);

            //act
            using (EchoNestSession session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey")))
            {
               //act
                PlaylistResponse searchResponse = session.Query<Basic>().Execute(basicArgument);

                //assert
                Assert.IsNotNull(searchResponse);

                // output
                Console.WriteLine("Songs for : {0}", artistName);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
                Console.WriteLine();
            }
        }
Beispiel #12
0
        public void GetSongs_WhereDescription_Christmas_IsNotNull()
        {
            const string description = "christmas";

            using (EchoNestSession session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey")))
            {
                SearchArgument searchArgument = new SearchArgument {
                    Results = 10, Bucket = SongBucket.ArtistHotttness, Sort = "artist_familiarity-desc"
                };

                searchArgument.Description.AddRange(new TermList {
                    description
                });

                SearchResponse searchResponse = session.Query <Search>().Execute(searchArgument);

                Assert.IsNotNull(searchResponse);

                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }

                Console.WriteLine();
            }
        }
Beispiel #13
0
        public static void Display(EchoNestSession session)
        {
            ConsoleKeyInfo keyInfo;

            using (ConsoleEx.BeginColorBlock(ConsoleColor.Cyan))
            {
                Console.WriteLine("=== Song API ===");
                Console.WriteLine("1: Search");
                Console.WriteLine("2: Profile");
                Console.WriteLine("=================");
            }

            ConsoleEx.Write("Enter api >> ", ConsoleColor.Green);
            keyInfo = Console.ReadKey();
            Console.Write(Environment.NewLine);

            switch (keyInfo.Key)
            {
            case ConsoleKey.D1:
                Search(session);
                break;

            case ConsoleKey.D2:
                Profile(session);
                break;
            }
        }
        public void GetFourtyRunningSongs(string query)
        {
            var id      = GetSongId(query);
            var songIds = new TermList();

            songIds.Add(id);

            StaticArgument staticArgument = new StaticArgument
            {
                Type     = "song-radio",
                SongID   = songIds,
                Results  = 40,
                MinTempo = 88,
                MaxTempo = 92,
                Variety  = 1
            };


            using (var session = new EchoNestSession(ApiKey))
            {
                PlaylistResponse searchResponse = session.Query <Static>().Execute(staticArgument);

                Assert.IsNotNull(searchResponse);
                Assert.IsNotNull(searchResponse.Songs);
                Assert.IsTrue(searchResponse.Songs.Any());

                Assert.AreEqual(40, searchResponse.Songs.Count);
            }
        }
Beispiel #15
0
        public static void Display(EchoNestSession session)
        {
            ConsoleKeyInfo keyInfo;

            using (ConsoleEx.BeginColorBlock(ConsoleColor.Cyan))
            {
                Console.WriteLine("=== Playlist API ===");
                Console.WriteLine("1: Basic");
                Console.WriteLine("2: Static");
                Console.WriteLine("3: Dynamic");
                Console.WriteLine("=================");
            }

            ConsoleEx.Write("Enter api >> ", ConsoleColor.Green);
            keyInfo = Console.ReadKey();
            Console.Write(Environment.NewLine);

            switch (keyInfo.Key)
            {
                case ConsoleKey.D1:
                    Basic(session);
                    break;
                case ConsoleKey.D2:
                    Basic(session);
                    break;
                case ConsoleKey.D3:
                    Basic(session);
                    break;
            }
        }
Beispiel #16
0
        public static void Display(EchoNestSession session)
        {
            ConsoleKeyInfo keyInfo;

            using (ConsoleEx.BeginColorBlock(ConsoleColor.Cyan))
            {
                Console.WriteLine("=== Song API ===");
                Console.WriteLine("1: Search");
                Console.WriteLine("2: Profile");
                Console.WriteLine("=================");
            }

            ConsoleEx.Write("Enter api >> ", ConsoleColor.Green);
            keyInfo = Console.ReadKey();
            Console.Write(Environment.NewLine);

            switch (keyInfo.Key)
            {
                case ConsoleKey.D1:
                    Search(session);
                    break;
                case ConsoleKey.D2:
                    Profile(session);
                    break;
            }
        }
Beispiel #17
0
        private static void Reviews(EchoNestSession session)
        {
            ConsoleEx.WriteLine("=== Reviews ===", ConsoleColor.Cyan);
            ConsoleEx.Write("Query >> ", ConsoleColor.Green);
            string query = Console.ReadLine();

            ConsoleEx.WriteLine("Searching..", ConsoleColor.Yellow);

            var result = session.Query <Reviews>().Execute(query, numberOfResults: 5);

            if (result.Status.Code == ResponseCode.Success)
            {
                foreach (var item in result.Reviews)
                {
                    ConsoleEx.WriteLine("Name:", ConsoleColor.White);
                    ConsoleEx.WriteLine(item.Name, ConsoleColor.DarkYellow);
                    ConsoleEx.WriteLine("Url:", ConsoleColor.White);
                    ConsoleEx.WriteLine(item.Url, ConsoleColor.DarkYellow);
                }
            }
            else
            {
                ConsoleEx.WriteLine(result.Status.Message, ConsoleColor.Red);
            }
        }
        private void LookUpAlbumInformation(string artistName, string albumName)
        {
            try
            {
                using (var session = new EchoNestSession(EchoNestModule.ApiKey))
                {
                    var response = session.Query <Reviews>().Execute(artistName, numberOfResults: 20);

                    if (response.Status.Code == ResponseCode.Success)
                    {
                        var reviews = response.Reviews.Where(r => r.Release.ToLower().Contains(albumName.ToLower()));
                        var review  = reviews.FirstOrDefault();

                        if (review != null)
                        {
                            CurrentTrackContainer.ExtraData.Review = review;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex.ToString(), Category.Exception, Priority.Medium);
            }
        }
Beispiel #19
0
        private static void Search(EchoNestSession session)
        {
            ConsoleEx.WriteLine("=== Song Search ===", ConsoleColor.Cyan);
            ConsoleEx.Write("Query >> ", ConsoleColor.Green);
            string query = Console.ReadLine();

            ConsoleEx.WriteLine("Searching..", ConsoleColor.Yellow);

            var result = session.Query <Search>().Execute(new SearchArgument
            {
                Title  = query,
                Bucket = SongBucket.ArtistHotttness,
                Sort   = "artist_hotttnesss-desc"
            });

            if (result.Status.Code == ResponseCode.Success)
            {
                foreach (var item in result.Songs)
                {
                    ConsoleEx.Write("Artist: ", ConsoleColor.White);
                    ConsoleEx.WriteLine(item.ArtistName, ConsoleColor.DarkYellow);
                    ConsoleEx.Write("Hotttness: ", ConsoleColor.White);
                    ConsoleEx.WriteLine(item.ArtistHotttnesss.ToString(), ConsoleColor.DarkYellow);
                }
            }
            else
            {
                ConsoleEx.WriteLine(result.Status.Message, ConsoleColor.Red);
            }
        }
        public void GetBasicPlaylist_WhereArtistName_HasSongsByArtist(string artistName)
        {
            BasicArgument basicArgument = new BasicArgument
            {
                Results = 10,
                Dmca    = true
            };

            TermList artistTerms = new TermList {
                artistName
            };

            basicArgument.Artist.AddRange(artistTerms);

            using (var session = new EchoNestSession(ApiKey))
            {
                PlaylistResponse searchResponse = session.Query <Basic>().Execute(basicArgument);

                Assert.IsNotNull(searchResponse);

                System.Diagnostics.Debug.WriteLine("Songs for : {0}", artistName);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    System.Diagnostics.Debug.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
            }
        }
Beispiel #21
0
        public void GetSongs_WhereDescription_Christmas_IsNotNull()
        {
            //arrange
            const string description = "christmas";

            //act
            using (EchoNestSession session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey")))
            {
                // arrange
                SearchArgument searchArgument = new SearchArgument {Results = 10, Bucket = SongBucket.ArtistHotttness, Sort = "artist_familiarity-desc"};

                searchArgument.Description.AddRange(new TermList {description});

                //act
                SearchResponse searchResponse = session.Query<Search>().Execute(searchArgument);

                //assert
                Assert.IsNotNull(searchResponse);

                // output
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
                Console.WriteLine();
            }
        }
Beispiel #22
0
        public void GetBasicPlaylist_WhereArtistName_HasSongsByArtist(string artistName)
        {
            //arrange
            BasicArgument basicArgument = new BasicArgument
            {
                Results = 10,
                Dmca    = true
            };

            TermList artistTerms = new TermList {
                artistName
            };

            basicArgument.Artist.AddRange(artistTerms);


            //act
            using (EchoNestSession session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey")))
            {
                //act
                PlaylistResponse searchResponse = session.Query <Basic>().Execute(basicArgument);

                //assert
                Assert.IsNotNull(searchResponse);

                // output
                Console.WriteLine("Songs for : {0}", artistName);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
                Console.WriteLine();
            }
        }
Beispiel #23
0
        public static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Please provide the Echo Nest API key");
                Console.ReadLine();
                return;
            }

            string apiKey = args[0];

            using (var session = new EchoNestSession(apiKey))
            {
                ConsoleKeyInfo keyInfo;

                do
                {
                    using (ConsoleEx.BeginColorBlock(ConsoleColor.Cyan))
                    {
                        Console.WriteLine("=== Main menu ===");
                        Console.WriteLine("1: Artist API");
                        Console.WriteLine("2: Song API");
                        Console.WriteLine("3: Playlist API");
                        Console.WriteLine("4: Track API");
                        Console.WriteLine("=================");
                    }

                    ConsoleEx.Write("Enter menu >> ", ConsoleColor.Green);
                    keyInfo = Console.ReadKey();
                    Console.Write(Environment.NewLine);

                    switch (keyInfo.Key)
                    {
                        case ConsoleKey.D1:
                            ArtistShell.Display(session);
                            break;
                        case ConsoleKey.D2:
                            SongShell.Display(session);
                            break;
                        case ConsoleKey.D3:
                            PlaylistShell.Display(session);
                            break;
                        case ConsoleKey.D4:
                            TrackShell.Display(session);
                            break;
                    }

                    if (keyInfo.Key != ConsoleKey.Escape)
                    {
                        ConsoleEx.Write("Press any key to continue (except Esc which will exit)", ConsoleColor.Yellow);
                        keyInfo = Console.ReadKey();
                        Console.WriteLine();
                    }
                }
                while (keyInfo.Key != ConsoleKey.Escape);
            }

            Console.ReadLine();
        }
        public static void Display(EchoNestSession session)
        {
            ConsoleKeyInfo keyInfo;

            using (ConsoleEx.BeginColorBlock(ConsoleColor.Cyan))
            {
                Console.WriteLine("=== Artist API ===");
                Console.WriteLine("1: Biographies");
                Console.WriteLine("2: Blogs");
                Console.WriteLine("3: Familiarity");
                Console.WriteLine("4: Hotttnesss");
                Console.WriteLine("5: Images");
                Console.WriteLine("6: List terms");
                Console.WriteLine("7: News");
                Console.WriteLine("8: Reviews");
                Console.WriteLine("9: Similar");
                Console.WriteLine("0: Suggest");
                Console.WriteLine("=================");
            }

            ConsoleEx.Write("Enter api >> ", ConsoleColor.Green);
            keyInfo = Console.ReadKey();
            Console.Write(Environment.NewLine);

            switch (keyInfo.Key)
            {
                case ConsoleKey.D1:
                    Biographies(session);
                    break;
                case ConsoleKey.D2:
                    Blogs(session);
                    break;
                case ConsoleKey.D3:
                    Familiarity(session);
                    break;
                case ConsoleKey.D4:
                    Hotttnesss(session);
                    break;
                case ConsoleKey.D5:
                    Images(session);
                    break;
                case ConsoleKey.D6:
                    ListTerms(session);
                    break;
                case ConsoleKey.D7:
                    News(session);
                    break;
                case ConsoleKey.D8:
                    Reviews(session);
                    break;
                case ConsoleKey.D9:
                    Similar(session);
                    break;
                case ConsoleKey.D0:
                    Suggest(session);
                    break;
            }
        }
        public bool MoveNext(CancellationToken token)
        {
            if (_songQueue == null)
            {
                using (var session = new EchoNestSession(EchoNestModule.ApiKey))
                {
                    var response = session.Query <Static>().Execute(_argument);

                    if (response == null)
                    {
                        // Try desperatly once more to see if its really not possible to get a proper response
                        response = session.Query <Static>().Execute(_argument);
                    }

                    if (response == null)
                    {
                        _toastService.Show("Trouble getting customized playlist from EchoNest");
                        return(false);
                    }

                    if (response.Status.Code == ResponseCode.Success)
                    {
                        _songQueue = new Queue <SongBucketItem>(response.Songs);
                    }
                    else
                    {
                        _songQueue = new Queue <SongBucketItem>();
                    }
                }
            }

            while (_songQueue.Count > 0)
            {
                if (token.IsCancellationRequested)
                {
                    token.ThrowIfCancellationRequested();
                }

                var song = _songQueue.Dequeue();

                var queryResult = _radio.GetTracksByName(song.ArtistName + " " + song.Title).ToArray();

                if (!queryResult.Any())
                {
                    queryResult = _radio.GetTracksByName(song.ArtistName).ToArray();
                }

                _currentTracks = queryResult.Take(1).ToArray();

                if (_currentTracks.Any())
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #26
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Please provide the Echo Nest API key");
                Console.ReadLine();
                return;
            }

            string apiKey = args[0];

            using (var session = new EchoNestSession(apiKey))
            {
                ConsoleKeyInfo keyInfo;

                do
                {
                    using (ConsoleEx.BeginColorBlock(ConsoleColor.Cyan))
                    {
                        Console.WriteLine("=== Main menu ===");
                        Console.WriteLine("1: Artist API");
                        Console.WriteLine("2: Song API");
                        Console.WriteLine("3: Playlist API");
                        Console.WriteLine("=================");
                    }

                    ConsoleEx.Write("Enter menu >> ", ConsoleColor.Green);
                    keyInfo = Console.ReadKey();
                    Console.Write(Environment.NewLine);

                    switch (keyInfo.Key)
                    {
                    case ConsoleKey.D1:
                        ArtistShell.Display(session);
                        break;

                    case ConsoleKey.D2:
                        SongShell.Display(session);
                        break;

                    case ConsoleKey.D3:
                        PlaylistShell.Display(session);
                        break;
                    }

                    if (keyInfo.Key != ConsoleKey.Escape)
                    {
                        ConsoleEx.Write("Press any key to continue (except Esc which will exit)", ConsoleColor.Yellow);
                        keyInfo = Console.ReadKey();
                        Console.WriteLine();
                    }
                } while (keyInfo.Key != ConsoleKey.Escape);
            }

            Console.ReadLine();
        }
 public void TestArtistBio()
 {
     using (var session = new EchoNestSession(ApiKey))
     {
         string query    = "Adele";
         var    result   = session.Query <EchoNest.Artist.Biography>().Execute(query, numberOfResults: 1);
         var    expected = 1;
         var    actual   = result.Biographies.Count;
         Assert.AreEqual(expected, actual);
     }
 }
Beispiel #28
0
        public void GetSongs_ForApocalypseNow_ExpectedArtist(string title, string styles, string moods, string expect)
        {
            // arrange
            TermList styleTerms = new TermList();

            foreach (string s in styles.Split(','))
            {
                styleTerms.Add(s);
            }

            TermList moodTerms = new TermList();

            foreach (string s in moods.Split(','))
            {
                moodTerms.Add(s);
            }

            SearchArgument searchArgument = new SearchArgument
            {
                Mode    = "0", /* minor */
                Sort    = "artist_familiarity-desc",
                Results = 10
            };

            searchArgument.Styles.AddRange(styleTerms);

            searchArgument.Moods.AddRange(moodTerms);

            //act
            using (EchoNestSession session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey")))
            {
                SearchResponse searchResponse = session.Query <Search>().Execute(searchArgument);

                //assert
                Assert.IsNotNull(searchResponse);
                Assert.IsNotNull(searchResponse.Songs);

                var matches = (from s in searchResponse.Songs
                               where s.ArtistName.ToLower().Contains(expect)
                               select s).ToList();


                Assert.IsNotNull(matches, "Failed to find songs where artist name contains: {0}", expect);

                // output
                Console.WriteLine("Tracks for '{0}'", title);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
                Console.WriteLine();
                Console.WriteLine();
            }
        }
Beispiel #29
0
 public void TestArtistBio()
 {
     using (var session = new EchoNestSession(ApiKey))
     {
         string query = "Adele";
         var result = session.Query<EchoNest.Artist.Biography>().Execute(query, numberOfResults: 1);
         var expected = 1;
         var actual = result.Biographies.Count;
         Assert.AreEqual(expected, actual);
     }
 }
        public void GetArtistByArtistName_JamesTaylor_IsProfileJamesTaylor()
        {
            const string artistName = "James Taylor";

            using (var session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey")))
            {
                ProfileResponse profileResponse = session.Query<Profile>().Execute(artistName);

                Assert.IsNotNull(profileResponse);
                Assert.AreEqual(artistName, profileResponse.Artist.Name, artistName);
            }
        }
Beispiel #31
0
        public void GetArtistByArtistName_JamesTaylor_IsProfileJamesTaylor()
        {
            const string artistName = "James Taylor";

            using (var session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey")))
            {
                ProfileResponse profileResponse = session.Query <Profile>().Execute(artistName);

                Assert.IsNotNull(profileResponse);
                Assert.AreEqual(artistName, profileResponse.Artist.Name, artistName);
            }
        }
Beispiel #32
0
        public void GetSongs_ForApocalypseNow_ExpectedArtist(string title, string styles, string moods, string expect)
        {
            // arrange
            TermList styleTerms = new TermList();
            foreach (string s in styles.Split(','))
            {
                styleTerms.Add(s);
            }

            TermList moodTerms = new TermList();
            foreach (string s in moods.Split(','))
            {
                moodTerms.Add(s);
            }

            SearchArgument searchArgument = new SearchArgument
            {
                Mode = "0", /* minor */
                Sort = "artist_familiarity-desc",
                Results = 10
            };

            searchArgument.Styles.AddRange(styleTerms);

            searchArgument.Moods.AddRange(moodTerms);

            //act
            using (EchoNestSession session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey")))
            {
                SearchResponse searchResponse = session.Query<Search>().Execute(searchArgument);

                //assert
                Assert.IsNotNull(searchResponse);
                Assert.IsNotNull(searchResponse.Songs);

                var matches = (from s in searchResponse.Songs
                               where s.ArtistName.ToLower().Contains(expect)
                               select s).ToList();

                Assert.IsNotNull(matches, "Failed to find songs where artist name contains: {0}", expect);

                // output
                Console.WriteLine("Tracks for '{0}'", title);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
                Console.WriteLine();
                Console.WriteLine();
            }
        }
Beispiel #33
0
        private static void Profile(EchoNestSession session)
        {
            ConsoleEx.WriteLine("=== Song Profile ===", ConsoleColor.Cyan);

            // ConsoleEx.Write("Query >> ", ConsoleColor.Green);
            // string query = Console.ReadLine();
            ConsoleEx.WriteLine("Loading..", ConsoleColor.Yellow);

            var result = session.Query<Profile>().Execute(new ProfileArgument
            {
                Id = "SOWMQIK144BDD38DD3",
                Bucket =
                SongBucket.ArtistHotttness
                | SongBucket.ArtistHotttnesssRank
                | SongBucket.SongHotttness
                | SongBucket.SongHotttnesssRank
                | SongBucket.ArtistDiscovery
                | SongBucket.ArtistDiscoveryRank
                | SongBucket.SongCurrency
                | SongBucket.SongCurrencyRank
                | SongBucket.SongDiscovery
                | SongBucket.SongDiscoveryRank
                | SongBucket.SongType
                | SongBucket.ArtistFamiliarity
                | SongBucket.ArtistFamiliarityRank
                | SongBucket.AudioSummary
                | SongBucket.ArtistLocation
                | SongBucket.Tracks
                | SongBucket.IdSpotifyWw
                | SongBucket.IdDeezer
                | SongBucket.IdMusicBrainz
            });

            if (result.Status.Code == ResponseCode.Success)
            {
                foreach (var item in result.Songs)
                {
                    ConsoleEx.Write("Artist: ", ConsoleColor.White);
                    ConsoleEx.WriteLine(item.ArtistName, ConsoleColor.DarkYellow);
                    ConsoleEx.Write("Title: ", ConsoleColor.White);
                    ConsoleEx.WriteLine(item.Title, ConsoleColor.DarkYellow);
                    ConsoleEx.Write("Hotttness: ", ConsoleColor.White);
                    ConsoleEx.WriteLine(item.ArtistHotttnesss.ToString(), ConsoleColor.DarkYellow);
                }
            }
            else
            {
                ConsoleEx.WriteLine(result.Status.Message, ConsoleColor.Red);
            }
        }
Beispiel #34
0
        public string[] GetSimilarArtists(string query)
        {
            using (EchoNestSession session = new EchoNestSession(EchoNestModule.ApiKey))
            {
                var response = session.Query <SuggestArtist>().Execute(query);

                if (response.Status.Code == ResponseCode.Success)
                {
                    return(response.Artists.Select(t => t.Name).ToArray());
                }
            }

            return(new string[0]);
        }
        public string[] GetSimilarArtists(string query)
        {
            using (EchoNestSession session = new EchoNestSession(EchoNestModule.ApiKey))
            {
                var response = session.Query<SuggestArtist>().Execute(query);

                if (response.Status.Code == ResponseCode.Success)
                {
                    return response.Artists.Select(t => t.Name).ToArray();
                }
            }

            return new string[0];
        }
Beispiel #36
0
        private static void Profile(EchoNestSession session)
        {
            ConsoleEx.WriteLine("=== Song Profile ===", ConsoleColor.Cyan);

            // ConsoleEx.Write("Query >> ", ConsoleColor.Green);
            // string query = Console.ReadLine();
            ConsoleEx.WriteLine("Loading..", ConsoleColor.Yellow);

            var result = session.Query <Profile>().Execute(new ProfileArgument
            {
                Id     = "SOWMQIK144BDD38DD3",
                Bucket =
                    SongBucket.ArtistHotttness
                    | SongBucket.ArtistHotttnesssRank
                    | SongBucket.SongHotttness
                    | SongBucket.SongHotttnesssRank
                    | SongBucket.ArtistDiscovery
                    | SongBucket.ArtistDiscoveryRank
                    | SongBucket.SongCurrency
                    | SongBucket.SongCurrencyRank
                    | SongBucket.SongDiscovery
                    | SongBucket.SongDiscoveryRank
                    | SongBucket.SongType
                    | SongBucket.ArtistFamiliarity
                    | SongBucket.ArtistFamiliarityRank
                    | SongBucket.AudioSummary
                    | SongBucket.ArtistLocation
                    | SongBucket.Tracks
                    | SongBucket.IdSpotifyWw
                    | SongBucket.IdDeezer
                    | SongBucket.IdMusicBrainz
            });

            if (result.Status.Code == ResponseCode.Success)
            {
                foreach (var item in result.Songs)
                {
                    ConsoleEx.Write("Artist: ", ConsoleColor.White);
                    ConsoleEx.WriteLine(item.ArtistName, ConsoleColor.DarkYellow);
                    ConsoleEx.Write("Title: ", ConsoleColor.White);
                    ConsoleEx.WriteLine(item.Title, ConsoleColor.DarkYellow);
                    ConsoleEx.Write("Hotttness: ", ConsoleColor.White);
                    ConsoleEx.WriteLine(item.ArtistHotttnesss.ToString(), ConsoleColor.DarkYellow);
                }
            }
            else
            {
                ConsoleEx.WriteLine(result.Status.Message, ConsoleColor.Red);
            }
        }
Beispiel #37
0
        private void HotTileJobExecution(Job <TileData> job, TileData tile)
        {
            try
            {
                var imageBackground = _random.NextDouble();

                if (imageBackground > 0.2)
                {
                    using (var session = new EchoNestSession(EchoNestModule.ApiKey))
                    {
                        var response = session.Query <TopHottt>().Execute(bucket: ArtistBucket.Images);

                        if (response != null && response.Status.Code == ResponseCode.Success)
                        {
                            var index  = _random.Next(0, response.Artists.Count - 1);
                            var artist = response.Artists[index];

                            if (artist.Images.Count > 0)
                            {
                                tile.Effect          = _tileEffect;
                                index                = _random.Next(0, artist.Images.Count - 1);
                                tile.BackgroundImage = new Uri(artist.Images[index].Url, UriKind.RelativeOrAbsolute);

                                _dispatcher.BeginInvoke(new Action(() =>
                                {
                                    tile.Content = new TextBlock
                                    {
                                        Text                = artist.Name,
                                        TextTrimming        = TextTrimming.CharacterEllipsis,
                                        Margin              = new Thickness(4),
                                        HorizontalAlignment = HorizontalAlignment.Left,
                                        VerticalAlignment   = VerticalAlignment.Top
                                    };
                                }));
                            }
                        }
                    }
                }
                else
                {
                    tile.Effect          = null;
                    tile.BackgroundImage = _tileIcon;
                    tile.Content         = null;
                }
            }
            catch (Exception e)
            {
                _logger.Log(e.ToString(), Category.Exception, Priority.Low);
            }
        }
Beispiel #38
0
        public void GetStaticPlaylist_WhereMoodAndStyle_HasVarietyOfArtists(string title, string styles, string moods)
        {
            //arrange
            TermList styleTerms = new TermList();

            foreach (string s in styles.Split(','))
            {
                styleTerms.Add(s);
            }

            TermList moodTerms = new TermList();

            foreach (string s in moods.Split(','))
            {
                moodTerms.Add(s);
            }

            StaticArgument staticArgument = new StaticArgument
            {
                Results         = 25,
                Adventurousness = 0.4,
                Type            = "artist-description",
                Variety         = 0.4 /* variety of artists */
            };

            staticArgument.Styles.AddRange(styleTerms);

            staticArgument.Moods.AddRange(moodTerms);

            //act
            using (EchoNestSession session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey")))
            {
                //act
                PlaylistResponse searchResponse = session.Query <Static>().Execute(staticArgument);

                //assert
                Assert.IsNotNull(searchResponse);
                Assert.IsNotNull(searchResponse.Songs);
                Assert.IsTrue(searchResponse.Songs.Any());

                // output
                Console.WriteLine("Songs for : {0}", title);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
                Console.WriteLine();
            }
        }
Beispiel #39
0
        private static void Basic(EchoNestSession session)
        {
            String query = String.Empty;

            ConsoleEx.WriteLine("=== Basic Playlist Generation ===", ConsoleColor.Cyan);
            ConsoleEx.WriteLine("(Enter a comma separated list of artist names for generating a baisc 'artist-radio' type playlist)", ConsoleColor.Cyan);

            ConsoleEx.Write("Query >> ", ConsoleColor.Green);
            query = Console.ReadLine();

            if (String.IsNullOrEmpty(query))
            {
                ConsoleEx.WriteLine("Query was empty. Press any key to start over.", ConsoleColor.Cyan);
                Console.ReadLine();
                Basic(session);
            }

            ConsoleEx.WriteLine("Generating..", ConsoleColor.Yellow);

            BasicArgument basicArgument = new BasicArgument();

            string[] terms = query.Split(',');

            TermList artistTerms = new TermList();

            foreach (string term in terms)
            {
                artistTerms.Add(term.Trim());
            }

            basicArgument.Artist.AddRange(artistTerms);

            var result = session.Query <Basic>().Execute(basicArgument);

            if (result.Status.Code == ResponseCode.Success)
            {
                foreach (var item in result.Songs)
                {
                    ConsoleEx.Write("Artist: ", ConsoleColor.White);
                    ConsoleEx.WriteLine(item.ArtistName, ConsoleColor.DarkYellow);
                    ConsoleEx.Write("Hotttness: ", ConsoleColor.White);
                    ConsoleEx.WriteLine(item.ArtistHotttnesss.ToString(), ConsoleColor.DarkYellow);
                }
            }
            else
            {
                ConsoleEx.WriteLine(result.Status.Message, ConsoleColor.Red);
            }
        }
Beispiel #40
0
        private static void Basic(EchoNestSession session)
        {
            String query = String.Empty;

            ConsoleEx.WriteLine("=== Basic Playlist Generation ===", ConsoleColor.Cyan);
            ConsoleEx.WriteLine("(Enter a comma separated list of artist names for generating a baisc 'artist-radio' type playlist)", ConsoleColor.Cyan);

            ConsoleEx.Write("Query >> ", ConsoleColor.Green);
            query = Console.ReadLine();

            if (String.IsNullOrEmpty(query))
            {
                ConsoleEx.WriteLine("Query was empty. Press any key to start over.", ConsoleColor.Cyan);
                Console.ReadLine();
                Basic(session);
            }

            ConsoleEx.WriteLine("Generating..", ConsoleColor.Yellow);

            BasicArgument basicArgument = new BasicArgument();

            string[] terms = query.Split(',');

            TermList artistTerms = new TermList();
            foreach (string term in terms)
            {
                artistTerms.Add(term.Trim());
            }

            basicArgument.Artist.AddRange(artistTerms);

            var result = session.Query<Basic>().Execute(basicArgument);

            if (result.Status.Code == ResponseCode.Success)
            {
                foreach (var item in result.Songs)
                {
                    ConsoleEx.Write("Artist: ", ConsoleColor.White);
                    ConsoleEx.WriteLine(item.ArtistName, ConsoleColor.DarkYellow);
                    ConsoleEx.Write("Hotttness: ", ConsoleColor.White);
                    ConsoleEx.WriteLine(item.ArtistHotttnesss.ToString(), ConsoleColor.DarkYellow);
                }
            }
            else
            {
                ConsoleEx.WriteLine(result.Status.Message, ConsoleColor.Red);
            }
        }
        private PlaylistResponse GetSongPlaylist(EchoNestSession session, string query)
        {
            var id = GetSongId(session, query);
            var songIds = new TermList();
            songIds.Add(id);

            StaticArgument staticArgument = new StaticArgument
            {
                Type = "song-radio",
                SongID = songIds,
                Results = 40,
                Variety = 1
            };

            return session.Query<Static>().Execute(staticArgument);
        }
        private static ArtistBucketItem GetArtistInformation(string query)
        {
            using (var session = new EchoNestSession(EchoNestModule.ApiKey))
            {
                var response = session
                               .Query <Profile>()
                               .Execute(query, ArtistBucket.Terms | ArtistBucket.Images);

                if (response.Status.Code == ResponseCode.Success)
                {
                    return(response.Artist);
                }
            }

            return(null);
        }
Beispiel #43
0
        private IEnumerable <ListTermsItem> GetItems(ListTermsType type)
        {
            using (_loadingIndicatorService.EnterLoadingBlock())
            {
                using (var session = new EchoNestSession(EchoNestModule.ApiKey))
                {
                    var response = session.Query <ListTerms>().Execute(type);

                    if (response.Status.Code == ResponseCode.Success)
                    {
                        return(response.Terms);
                    }
                }

                return(new ListTermsItem[0]);
            }
        }
Beispiel #44
0
        public void GetSongs_WhereDescription_Christmas_IsNotNull()
        {
            const string description = "christmas";

            using (var session = new EchoNestSession(ApiKey))
            {
                SearchArgument searchArgument = new SearchArgument { Results = 10, Bucket = SongBucket.ArtistHotttness, Sort = "artist_familiarity-desc" };
                searchArgument.Description.AddRange(new TermList { description });
                SearchResponse searchResponse = session.Query<Search>().Execute(searchArgument);

                Assert.IsNotNull(searchResponse);

                foreach (EchoNest.Song.SongBucketItem song in searchResponse.Songs)
                {
                   System.Diagnostics.Debug.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
            }
        }
        public string GetSongId(string title)
        {
            SearchArgument searchArgument = new SearchArgument
            {
                Title = title
            };

            using (var session = new EchoNestSession(ApiKey))
            {
                SearchResponse searchResponse = session.Query <Search>().Execute(searchArgument);

                Assert.IsNotNull(searchResponse);
                Assert.IsNotNull(searchResponse.Songs);
                Assert.IsTrue(searchResponse.Songs.Count > 0);

                return(searchResponse.Songs.First().ID);
            }
        }
        public void GetStaticPlaylist_WhereMoodAndStyle_HasVarietyOfArtists(string title, string styles, string moods)
        {
            TermList styleTerms = new TermList();
            foreach (string s in styles.Split(','))
            {
                styleTerms.Add(s);
            }

            TermList moodTerms = new TermList();
            foreach (string s in moods.Split(','))
            {
                moodTerms.Add(s);
            }

            StaticArgument staticArgument = new StaticArgument
            {
                Results = 25,
                Adventurousness = 0.4,
                Type = "artist-description",
                Variety = 0.4 /* variety of artists */
            };

            staticArgument.Styles.AddRange(styleTerms);

            staticArgument.Moods.AddRange(moodTerms);

            using (EchoNestSession session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey")))
            {
                PlaylistResponse searchResponse = session.Query<Static>().Execute(staticArgument);

                Assert.IsNotNull(searchResponse);
                Assert.IsNotNull(searchResponse.Songs);
                Assert.IsTrue(searchResponse.Songs.Any());

                Console.WriteLine("Songs for : {0}", title);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }

                Console.WriteLine();
            }
        }
        private PlaylistData CreateEchonestPlaylist(string apiKey)
        {
            var query = Query.Replace('&', '+');
            using (var session = new EchoNestSession(apiKey))
            {
                var searchReponse = GetArtistPlaylist(session, query);

                // Do we have a match for the artist? If not look for a matching song
                if (searchReponse.Songs != null && searchReponse.Songs.Count > 0)
                {
                    return CreatePlaylistDataFromEchoNestResponse(searchReponse);
                }
                else
                {
                    searchReponse = GetSongPlaylist(session, query);
                    return CreatePlaylistDataFromEchoNestResponse(searchReponse);
                }
            }
        }
        public void GetStaticPlaylist_WhereMoodAndStyle_HasVarietyOfArtists(string title, string styles, string moods)
        {
            TermList styleTerms = new TermList();

            foreach (string s in styles.Split(','))
            {
                styleTerms.Add(s);
            }

            TermList moodTerms = new TermList();

            foreach (string s in moods.Split(','))
            {
                moodTerms.Add(s);
            }

            StaticArgument staticArgument = new StaticArgument
            {
                Results         = 25,
                Adventurousness = 0.4,
                Type            = "artist-description",
                Variety         = 0.4 /* variety of artists */
            };

            staticArgument.Styles.AddRange(styleTerms);

            staticArgument.Moods.AddRange(moodTerms);

            using (var session = new EchoNestSession(ApiKey))
            {
                PlaylistResponse searchResponse = session.Query <Static>().Execute(staticArgument);

                Assert.IsNotNull(searchResponse);
                Assert.IsNotNull(searchResponse.Songs);
                Assert.IsTrue(searchResponse.Songs.Any());

                System.Diagnostics.Debug.WriteLine("Songs for : {0}", title);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    System.Diagnostics.Debug.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
            }
        }
Beispiel #49
0
        public bool MoveNext(CancellationToken token)
        {
            using (var session = new EchoNestSession(EchoNestModule.ApiKey))
            {
                if (token.IsCancellationRequested)
                {
                    token.ThrowIfCancellationRequested();
                }

                var response = session.Query <TopHottt>().Execute(2, _start);

                if (response != null && response.Status.Code == ResponseCode.Success)
                {
                    _start += response.Artists.Count;

                    List <Track> tracks = new List <Track>();

                    foreach (var artist in response.Artists.OrderBy(k => Guid.NewGuid()))
                    {
                        if (token.IsCancellationRequested)
                        {
                            token.ThrowIfCancellationRequested();
                        }

                        var result = _radio
                                     .GetTracksByName(artist.Name)
                                     .Where(a => a.Artist.Equals(artist.Name, StringComparison.InvariantCultureIgnoreCase))
                                     .Take(2);

                        tracks.AddRange(result);
                    }

                    _currentTracks = tracks;

                    return(true);
                }
            }

            return(false);
        }
        public bool MoveNext(CancellationToken token)
        {
            using (var session = new EchoNestSession(EchoNestModule.ApiKey))
            {
                if (token.IsCancellationRequested)
                {
                    token.ThrowIfCancellationRequested();
                }

                var response = session.Query<TopHottt>().Execute(2, _start);

                if (response != null && response.Status.Code == ResponseCode.Success)
                {
                    _start += response.Artists.Count;

                    List<Track> tracks = new List<Track>();

                    foreach (var artist in response.Artists.OrderBy(k => Guid.NewGuid()))
                    {
                        if (token.IsCancellationRequested)
                        {
                            token.ThrowIfCancellationRequested();
                        }

                        var result = _radio
                            .GetTracksByName(artist.Name)
                            .Where(a => a.Artist.Equals(artist.Name, StringComparison.InvariantCultureIgnoreCase))
                            .Take(2);

                        tracks.AddRange(result);
                    }

                    _currentTracks = tracks;

                    return true;
                }
            }

            return false;
        }
Beispiel #51
0
        public void GetSongs_WhereDescription_Christmas_IsNotNull()
        {
            const string description = "christmas";

            using (var session = new EchoNestSession(ApiKey))
            {
                SearchArgument searchArgument = new SearchArgument {
                    Results = 10, Bucket = SongBucket.ArtistHotttness, Sort = "artist_familiarity-desc"
                };
                searchArgument.Description.AddRange(new TermList {
                    description
                });
                SearchResponse searchResponse = session.Query <Search>().Execute(searchArgument);

                Assert.IsNotNull(searchResponse);

                foreach (EchoNest.Song.SongBucketItem song in searchResponse.Songs)
                {
                    System.Diagnostics.Debug.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
            }
        }
        void INavigationAware.OnNavigatedTo(NavigationContext navigationContext)
        {
            Task.Factory.StartNew(() =>
            {
                using (var session = new EchoNestSession(EchoNestModule.ApiKey))
                {
                    var styles = session.Query<ListTerms>().Execute(ListTermsType.Style);
                    var moods = session.Query<ListTerms>().Execute(ListTermsType.Mood);

                    if (styles.Status.Code == ResponseCode.Success)
                    {
                        Styles =
                            new ListCollectionView(styles.Terms.Select(s => new TermModel{Name = s.Name}).ToArray());
                    }

                    if (moods.Status.Code == ResponseCode.Success)
                    {
                        Moods =
                            new ListCollectionView(moods.Terms.Select(s => new TermModel{Name = s.Name}).ToArray());
                    }
                }
            });
        }
        private PlaylistData CreateEchonestPlaylist(string apiKey)
        {
            var seedArtists = new TermList();

            seedArtists.Add(Query);

            StaticArgument staticArgument = new StaticArgument
            {
                Results = 40,
                Artist = seedArtists,
                Type = "artist-radio"
            };

            using (var session = new EchoNestSession(apiKey))
            {
                PlaylistResponse searchResponse = session.Query<Static>().Execute(staticArgument);
                var playlistData = new PlaylistData();
                playlistData.Items = new List<PlaylistDataItem>();
                playlistData.Description = Query;
                playlistData.Title = string.Format("{0} playlist", Query);
                playlistData.SearchKeys = new List<string>();

                foreach (var song in searchResponse.Songs)
                {
                    var item = new PlaylistDataItem();
                    item.Artist = song.ArtistName;
                    item.Title = song.Title;
                    playlistData.Items.Add(item);

                    var searchKey = string.Format("{0} {1}", item.Artist, item.Title);
                    playlistData.SearchKeys.Add(searchKey);
                }

                return playlistData;
            }
        }
Beispiel #54
0
        public void GetFourtyRunningSongs(string query)
        {
            var id = GetSongId(query);
            var songIds = new TermList();
            songIds.Add(id);

            StaticArgument staticArgument = new StaticArgument
            {
                Type = "song-radio",
                SongID = songIds,
                Results = 40,
                MinTempo = 88,
                MaxTempo = 92,
                Variety = 1
            };
                

            using (var session = new EchoNestSession(ApiKey))
            {
                PlaylistResponse searchResponse = session.Query<Static>().Execute(staticArgument);

                Assert.IsNotNull(searchResponse);
                Assert.IsNotNull(searchResponse.Songs);
                Assert.IsTrue(searchResponse.Songs.Any());

                Assert.AreEqual(40, searchResponse.Songs.Count);
            }
        }
Beispiel #55
0
        public void GetDynamicPlaylist_WhereMoodAndStyle_CanSteerDynamicPlaylistByMood(string title, string styles, string moods)
        {
            //arrange
            TermList styleTerms = new TermList();
            foreach (string s in styles.Split(','))
            {
                styleTerms.Add(s);
            }

            TermList moodTerms = new TermList();
            foreach (string s in moods.Split(','))
            {
                moodTerms.Add(s);
            }

            DynamicArgument dynamicArgument = new DynamicArgument
            {
                Adventurousness = 0.4,
                Type = "artist-description",
                Variety = 0.4 /* variety of artists */
            };

            dynamicArgument.Styles.AddRange(styleTerms);

            dynamicArgument.Moods.AddRange(moodTerms);

            //act
            using (EchoNestSession session = new EchoNestSession(ConfigurationManager.AppSettings.Get("echoNestApiKey")))
            {
                //act
                DynamicPlaylistResponse searchResponse = session.Query<Dynamic>().Execute(dynamicArgument);

                //assert
                Assert.IsNotNull(searchResponse);
                Assert.IsNotNull(searchResponse.Songs);
                Assert.IsTrue(searchResponse.Songs.Any());

                // arrange next part of test
                string sessionId = searchResponse.SessionId;

                // output
                Console.WriteLine("Dynamic Playlist Session Id: {0}", sessionId);
                Console.WriteLine();
                Console.WriteLine("Songs for : {0}", title);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
                Console.WriteLine();
                Console.WriteLine("Steering Playlist by mood = -happy");
                Console.WriteLine();

                dynamicArgument = new DynamicArgument { SteerMood = "-happy", SessionId = sessionId };
                searchResponse = session.Query<Dynamic>().Execute(dynamicArgument);
                Console.WriteLine("Next song in dynamic playlist for : {0}", title);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }

                Console.WriteLine();
                Console.WriteLine("Steering Playlist by tempo = +10% (tempo^1.1)");
                Console.WriteLine();
                dynamicArgument = new DynamicArgument { Steer = "tempo^1.1", SessionId = sessionId };
                searchResponse = session.Query<Dynamic>().Execute(dynamicArgument);
                Console.WriteLine("Next song in dynamic playlist for : {0}", title);
                foreach (SongBucketItem song in searchResponse.Songs)
                {
                    Console.WriteLine("\t{0} ({1})", song.Title, song.ArtistName);
                }
                Console.WriteLine();
            }
        }
        public bool MoveNext(CancellationToken token)
        {
            if (_songQueue == null)
            {
                using (var session = new EchoNestSession(EchoNestModule.ApiKey))
                {
                    var response = session.Query<Static>().Execute(_argument);

                    if (response == null)
                    {
                        // Try desperatly once more to see if its really not possible to get a proper response
                        response = session.Query<Static>().Execute(_argument);
                    }

                    if (response == null)
                    {
                        _toastService.Show("Trouble getting customized playlist from EchoNest");
                        return false;
                    }

                    if (response.Status.Code == ResponseCode.Success)
                    {
                        _songQueue = new Queue<SongBucketItem>(response.Songs);
                    }
                    else
                    {
                        _songQueue = new Queue<SongBucketItem>();
                    }
                }
            }

            while (_songQueue.Count > 0)
            {
                if (token.IsCancellationRequested)
                {
                    token.ThrowIfCancellationRequested();
                }

                var song = _songQueue.Dequeue();

                var queryResult = _radio.GetTracksByName(song.ArtistName + " " + song.Title).ToArray();

                if (!queryResult.Any())
                {
                    queryResult = _radio.GetTracksByName(song.ArtistName).ToArray();
                }

                _currentTracks = queryResult.Take(1).ToArray();

                if (_currentTracks.Any())
                {
                    return true;
                }
            }

            return false;
        }
Beispiel #57
0
        public async void GetArtistInfo(string artist, Action<string, Exception> callback)
        {
            Exception ex = null;
            string artistInfo = null;

            try
            {
                if (this.echoNestSession == null)
                {
                    var echoNestApiKey = await this.LoadApiKey();
                    this.echoNestSession = new EchoNestSession(echoNestApiKey);
                }

                var artistQuery = FormatArtistQuery(artist);
                var result = this.echoNestSession.Query<Biography>().Execute(artistQuery);

                StringBuilder sb = new StringBuilder();
                foreach(var bio in result.Biographies)
                {
                    sb.Append(bio.Text);
                }

                artistInfo = sb.ToString();
            }
            catch (Exception e)
            {
                ex = e;
            }

            callback(artistInfo, ex);
        }
Beispiel #58
0
        public void GetPlaylistByArtistOrSong(string query)
        {
            var seedArtists = new TermList();
            seedArtists.Add(query);

            StaticArgument staticArgument = new StaticArgument
            {
                Results = 40,
                Artist = seedArtists,
                Type = "artist-radio"
            };

            using (var session = new EchoNestSession(ApiKey))
            {
                PlaylistResponse searchResponse = session.Query<Static>().Execute(staticArgument);

                Assert.IsNotNull(searchResponse);
                Assert.IsNotNull(searchResponse.Songs);
                Assert.IsTrue(searchResponse.Songs.Any());

                Assert.AreEqual(40, searchResponse.Songs.Count);
            }
        }
        private string GetSongId(EchoNestSession session, string title)
        {
            SearchArgument searchArgument = new SearchArgument
            {
                Title = title
            };

            SearchResponse searchResponse = session.Query<Search>().Execute(searchArgument);
            return searchResponse.Songs.Count > 0 ? searchResponse.Songs.First().ID : string.Empty;
        }
Beispiel #60
0
        public string GetSongId(string title)
        {
            SearchArgument searchArgument = new SearchArgument
            {
                Title = title
            };

            using (var session = new EchoNestSession(ApiKey))
            {
                SearchResponse searchResponse = session.Query<Search>().Execute(searchArgument);

                Assert.IsNotNull(searchResponse);
                Assert.IsNotNull(searchResponse.Songs);
                Assert.IsTrue(searchResponse.Songs.Count > 0);

                return searchResponse.Songs.First().ID;
            }
        }