Esempio n. 1
0
        public void GetTVEpisodesForShow_ValidShow_GroupedEpisodes()
        {
            //  Arrange
            iTunesSearchManager search = new iTunesSearchManager();
            string showName            = "Modern Family";

            //  Act
            var items   = search.GetTVEpisodesForShow(showName, 200).Result;
            var seasons = from episode in items.Episodes
                          orderby episode.Number
                          group episode by episode.SeasonNumber into seasonGroup
                          orderby seasonGroup.Key
                          select seasonGroup;

            //  Assert
            foreach (var seasonGroup in seasons)
            {
                Debug.WriteLine("Season number: {0}", seasonGroup.Key);

                foreach (TVEpisode episode in seasonGroup)
                {
                    Debug.WriteLine("Ep {0}: {1}", episode.Number, episode.Name);
                }
            }
        }
Esempio n. 2
0
        public void GetArtistByAMGArtistId_ValidArtist_ReturnsArtist()
        {
            // Arrange
            iTunesSearchManager search = new iTunesSearchManager();
            long amgArtistId           = 116437;

            // Act
            var item = search.GetSongArtistByAMGArtistIdAsync(amgArtistId).Result;

            // Assert
            Assert.IsTrue(item.ArtistName == "R.E.M.");
        }
Esempio n. 3
0
        public void GetPodcasts_ValidPodcast_ReturnsEpisodes()
        {
            //  Arrange
            iTunesSearchManager search = new iTunesSearchManager();
            string showName            = "Radiolab";

            //  Act
            var items = search.GetPodcasts(showName, 200).Result;

            //  Assert
            Assert.IsTrue(items.Podcasts.Any());
        }
Esempio n. 4
0
        public void GetTVSeasonsForShow_ValidShow_ReturnsShows()
        {
            //  Arrange
            iTunesSearchManager search = new iTunesSearchManager();
            string showName            = "Modern Family";

            //  Act
            var items = search.GetTVSeasonsForShow(showName).Result;

            //  Assert
            Assert.IsTrue(items.Seasons.Any());
        }
Esempio n. 5
0
        public void GetSongArtists_ValidArtists_ReturnsArtists()
        {
            // Arrange
            iTunesSearchManager search = new iTunesSearchManager();
            string artist = "R.E.M.";

            // Act
            var items = search.GetSongArtistsAsync(artist, 200).Result;

            // Assert
            Assert.IsTrue(items.Artists.Any());
        }
Esempio n. 6
0
        public void GetAlbumsByAMGArtistId_ValidArtist_ReturnsAlbums()
        {
            // Arrange
            iTunesSearchManager search = new iTunesSearchManager();
            long amgArtistId           = 116437;

            // Act
            var items = search.GetAlbumsByAMGArtistIdAsync(amgArtistId, 200).Result;

            // Assert
            Assert.IsTrue(items.Albums.Any(al => al.CollectionName == "Life's Rich Pageant"));
        }
Esempio n. 7
0
        public void GetArtistByAMGArtistId_InvalidArtist_ReturnsDefaultInstanceOfSongArtist()
        {
            // Arrange
            iTunesSearchManager search = new iTunesSearchManager();
            long amgArtistId           = 5858500001;

            // Act
            var item = search.GetSongArtistByAMGArtistIdAsync(amgArtistId).Result;

            // Assert
            Assert.IsInstanceOfType(item, typeof(SongArtist));
            Assert.IsTrue(item.ArtistName == default(string));
        }
Esempio n. 8
0
        public void GetTVEpisodesForShow_ValidShowAndCountryCode_ReturnsEpisodes()
        {
            //  Arrange
            iTunesSearchManager search = new iTunesSearchManager();
            string showName            = "Top of the Lake";
            string countryCode         = "AU"; /* Australia */

            //  Act
            var items = search.GetTVEpisodesForShow(showName, 200, countryCode).Result;

            //  Assert
            Assert.IsTrue(items.Episodes.Any());
        }
Esempio n. 9
0
        public void GetTVSeasonsForShow_ValidShowAndCountryCode_ReturnsShows()
        {
            //  Arrange
            iTunesSearchManager search = new iTunesSearchManager();
            string showName            = "King of the Hill";
            string countryCode         = "AU"; /* Australia */

            //  Act
            var items = search.GetTVSeasonsForShow(showName, 20, countryCode).Result;

            //  Assert
            Assert.IsTrue(items.Seasons.Any());
        }
Esempio n. 10
0
        public void GetTVSeasonById_ValidSeasonId_ReturnsShow()
        {
            //  Arrange
            iTunesSearchManager search = new iTunesSearchManager();
            long seasonId = 327827178;

            //  Act
            var items = search.GetTVSeasonById(seasonId).Result;

            //  Assert
            Assert.IsTrue(items.Seasons.Any());
            Assert.AreEqual("Modern Family", items.Seasons.First().ShowName);
        }
Esempio n. 11
0
        public void GetAlbumsFromSong_ValidAlbums_ReturnsAlbums()
        {
            // Arrange
            iTunesSearchManager search = new iTunesSearchManager();
            string song = "Driver 8";

            // Act
            var items = search.GetAlbumsFromSongAsync(song, 200).Result;

            // Assert
            Assert.IsTrue(items.Albums.Any());
            Assert.IsTrue(items.Albums.Any(al => al.ArtistName == "R.E.M." && al.CollectionName == "Fables of the Reconstruction"));
        }
Esempio n. 12
0
        public void GetAlbums_ValidAlbums_ReturnsAlbums()
        {
            // Arrange
            iTunesSearchManager search = new iTunesSearchManager();
            string album = "Collapse into Now";

            // Act
            var items = search.GetAlbumsAsync(album, 200).Result;

            // Assert
            Assert.IsTrue(items.Albums.Any());
            Assert.IsTrue(items.Albums.Any(al => al.ArtistName == "R.E.M."));
        }
Esempio n. 13
0
        public void GetSongs_ValidSongs_ReturnsSongs()
        {
            // Arrange
            iTunesSearchManager search = new iTunesSearchManager();
            string song = "Driver 8";

            // Act
            var items = search.GetSongsAsync(song, 200).Result;

            // Assert
            Assert.IsTrue(items.Songs.Any());
            Assert.IsTrue(items.Songs.Any(s => s.TrackName == "Driver 8" && s.ArtistName == "R.E.M."));
        }
Esempio n. 14
0
        public void GetPodcastById_ValidId_ReturnsPodcast()
        {
            //  Arrange
            iTunesSearchManager search = new iTunesSearchManager();
            long podcastId             = 1002937870;

            //  Act
            var items = search.GetPodcastById(podcastId).Result;

            //  Assert
            Assert.IsTrue(items.Podcasts.Any());
            Assert.AreEqual("Dear Hank and John", items.Podcasts.First().Name);
            Assert.AreEqual("http://feeds.soundcloud.com/users/soundcloud:users:156542883/sounds.rss", items.Podcasts.First().FeedUrl);
        }
Esempio n. 15
0
        public void GetPodcastById_ValidId_ReturnsPodcast()
        {
            //  Arrange
            iTunesSearchManager search = new iTunesSearchManager();
            long podcastId             = 1002937870;

            //  Act
            var items = search.GetPodcastById(podcastId).Result;

            //  Assert
            Assert.IsTrue(items.Podcasts.Any());
            Assert.AreEqual("Dear Hank and John", items.Podcasts.First().Name);
            Assert.AreEqual("http://dearhankandjohn.libsyn.com/rss", items.Podcasts.First().FeedUrl);
        }
Esempio n. 16
0
        public void GetTVSeasonById_ValidSeasonId_ReturnsCorrectLargeArtwork()
        {
            //  Arrange
            iTunesSearchManager search     = new iTunesSearchManager();
            long   seasonId                = 316075588;
            string expectedShowName        = "Gilmore Girls";
            string expectedLargeArtworkUrl = "http://is1.mzstatic.com/image/thumb/Music71/v4/82/28/39/8228392e-f1f9-3b64-6c0f-14ba1f958a92/source/600x600bb.jpg";

            //  Act
            var items = search.GetTVSeasonById(seasonId).Result;

            //  Assert
            Assert.IsTrue(items.Seasons.Any());
            Assert.AreEqual(expectedShowName, items.Seasons.First().ShowName);
            Assert.AreEqual(expectedLargeArtworkUrl, items.Seasons.First().ArtworkUrlLarge);
        }
Esempio n. 17
0
        public void GetTVSeasonById_ValidSeasonId_ReturnsCorrectLargeArtwork()
        {
            //  Arrange
            iTunesSearchManager search     = new iTunesSearchManager();
            long   seasonId                = 316075588;
            string expectedShowName        = "Gilmore Girls";
            string expectedLargeArtworkUrl = "http://is3.mzstatic.com/image/thumb/Music71/v4/8f/5c/1d/8f5c1d3d-c025-de7d-099e-6f55764e0d21/source/600x600bb.jpg";

            //  Act
            var items = search.GetTVSeasonById(seasonId).Result;

            //  Assert
            Assert.IsTrue(items.Seasons.Any());
            Assert.AreEqual(expectedShowName, items.Seasons.First().ShowName);
            Assert.AreEqual(expectedLargeArtworkUrl, items.Seasons.First().ArtworkUrlLarge);
        }
Esempio n. 18
0
        public async Task <List <ArtworkData> > GetPossibleAlbumArt(string country, string artist, string albumName)
        {
            var searchManager = new iTunesSearchManager();

            var artists = await searchManager.GetSongArtistsAsync(artist);

            var foundArtist = artists.Artists.FirstOrDefault();

            if (foundArtist is null)
            {
                return(null);
            }

            var albums = await searchManager.GetAlbumsByArtistIdAsync(foundArtist.ArtistId);

            var options = new List <FuzzyStringComparisonOptions>
            {
                FuzzyStringComparisonOptions.UseOverlapCoefficient,
                FuzzyStringComparisonOptions.UseLongestCommonSubsequence,
                FuzzyStringComparisonOptions.UseLongestCommonSubstring
            };

            var bestMatches = albums.Albums.Where(x =>
                                                  x.CollectionName != null && albumName.ApproximatelyEquals(x.CollectionName,
                                                                                                            FuzzyStringComparisonTolerance.Strong, options.ToArray())).ToList();

            return(bestMatches.Concat(albums.Albums.Where(x => x.CollectionName != null && !bestMatches.Contains(x)))
                   .Concat(albums.Albums.Where(x => x.CollectionName is null))
                   .Where(x => !string.IsNullOrWhiteSpace(x.ArtworkUrl100))
                   .Select(x => new ArtworkData
            {
                Url = x.ArtworkUrl100.Replace("100x100bb", "600x600bb"),
                Album = x.CollectionName,
                Artist = x.ArtistName
            })
                   .Take(20).ToList());
        }
Esempio n. 19
0
        public async Task <byte[]> DownloadArtwork(string country, string artist, string albumName)
        {
            var searchManager = new iTunesSearchManager();

            var artists = await searchManager.GetSongArtistsAsync(artist);

            var foundArtist = artists.Artists.FirstOrDefault();

            if (foundArtist is null)
            {
                return(null);
            }

            var albums = await searchManager.GetAlbumsByArtistIdAsync(foundArtist.ArtistId);

            var album = albums.Albums.FirstOrDefault(x =>
                                                     x.CollectionName != null && x.CollectionName.Contains(albumName) &&
                                                     !string.IsNullOrWhiteSpace(x.ArtworkUrl100));

            if (album != null)
            {
                var artworkUri = album.ArtworkUrl100.Replace("100x100bb", "1000x1000bb");

                var clientHandler = new HttpClientHandler
                {
                    ServerCertificateCustomValidationCallback = delegate { return(true); }
                };

                using var client = new HttpClient(clientHandler);

                var data = await client.GetByteArrayAsync(artworkUri);

                return(data);
            }

            return(null);
        }
Esempio n. 20
0
 public iTunesRepository()
 {
     _manager = new iTunesSearchManager();
 }