コード例 #1
0
        public IEnumerable <Track> AddArtistSongsToPlaylist(Artist artist)
        {
            const int    numSongsPerArtist = 3; //TODO: Expose this to the user.
            TrackList    popularSongs      = _client.GetArtistTopTracks(artist);
            List <Track> songsToAdd        = new List <Track>(numSongsPerArtist);

            foreach (Track popularTrack in popularSongs.Tracks)
            {
                if (!this.ContainsTrack(popularTrack))
                {
                    songsToAdd.Add(popularTrack);

                    if (songsToAdd.Count >= numSongsPerArtist)
                    {
                        break;
                    }
                }
            }

            if (!songsToAdd.Any())
            {
                AlbumInfoList albumList = _client.GetArtistAlbums(artist);

                foreach (AlbumInfo album in albumList.Items)
                {
                    AlbumTrackList      albumTrackList          = _client.GetAlbumTracks(album);
                    IEnumerable <Track> albumTracksByPopularity = albumTrackList.Tracks.OrderByDescending(track => track.Popularity);
                    foreach (Track albumTrack in albumTracksByPopularity)
                    {
                        if (!this.ContainsTrack(albumTrack))
                        {
                            songsToAdd.Add(albumTrack);

                            if (songsToAdd.Count >= numSongsPerArtist)
                            {
                                break;
                            }
                        }
                    }

                    if (songsToAdd.Count >= numSongsPerArtist)
                    {
                        break;
                    }
                }
            }


            _client.AddTracksToPlaylist(_playlist, songsToAdd);

            return(songsToAdd);
        }
コード例 #2
0
        public AlbumInfoList GetArtistAlbums(Artist artist, AlbumType albumTypes)
        {
            AlbumInfoList albumList = GetPagedRequest <AlbumInfoList>(Endpoints.GetArtistAlbums(artist.ID, albumTypes), true);

            return(albumList);
        }
コード例 #3
0
        private void OnNewReleases(object sender, RoutedEventArgs e)
        {
            _atlasViewMode = AtlasViewMode.NewReleasesView;

            //Clear the playlist selection.
            NavigationControl navigationControl = (NavigationControl)sender;

            navigationControl.SelectPlaylist(null);
            OnPlaylistSelectionChanged(navigationControl, e);

            List <NewReleaseItem> newsItems = new List <NewReleaseItem>();

            //Add artists that have new releases.
            //System.Threading.Tasks.Task.Run(() =>
            {
                AlbumType filter         = AlbumType.Album | AlbumType.Single;
                DateTime  cutoff         = DateTime.Now.AddMonths(-3); //TODO: Data-drive this setting.
                int       maxSuggestions = 1;                          //TODO: Data-drive this setting.

                FollowedArtistList followedArtists = SpotifyCacheService.GetFollowedArtists();

                foreach (Artist followedArtist in followedArtists.ArtistItems.Items)
                {
                    //Find if there's any new content available from this artist.
                    AlbumInfoList albums = SpotifyClientService.Client.GetArtistAlbums(followedArtist, filter);

                    foreach (AlbumInfo album in albums.Items)
                    {
                        //if (_userCache.SeenNewsItem(album.ID)) continue;

                        Album albumInfo = SpotifyClientService.Client.GetAlbum(album);

                        if (albumInfo.ReleaseDate > cutoff)
                        {
                            newsItems.Add(new NewReleaseItem(followedArtist, albumInfo));
                            if (newsItems.Count >= maxSuggestions)
                            {
                                break;
                            }
                        }
                        else
                        {
                            //Assume that albums are returned by Spotify by release date, descending.
                            //If we miss the cutoff, skip out.
                            break;
                        }
                    }
                }

                if (newsItems.Any())
                {
                    Dispatcher.Invoke(() =>
                    {
                        //Display a popup.
                        //this.NewsFeedPopup.DataContext = new NewsFeedViewModel(newsItems, userCache);
                        //this.NewsFeedPopup.Width = this.RenderSize.Width * 0.8;
                        //this.NewsFeedPopup.Height = this.RenderSize.Height * 0.8;
                        //this.NewsFeedPopup.IsOpen = true;
                    });
                }
            }
            //);

            AtlasViewOptions viewOptions = new AtlasViewOptions(0);

            this.AtlasView.ViewModel.CreateNewReleaseHierarchy(newsItems.ToList().AsReadOnly(), viewOptions);
            this.AtlasView.UpdateNetwork();
        }