private async Task <IEnumerable <Track> > GetTracksFromPlaylist(string playlistId)
        {
            var index          = 0;
            var playlistTracks = new List <Track>();

            int playlistSize;

            do
            {
                var request = new PlaylistGetItemsRequest
                {
                    Limit  = MaxItemsPerRequest,
                    Offset = index * MaxItemsPerRequest
                };

                var requestedTracks = await spotify.Playlists.GetItems(playlistId, request);

                playlistSize = requestedTracks.Total.GetValueOrDefault();
                playlistTracks.AddRange(requestedTracks.Items.Select(x => mapper.Map <Track>(x.Track)));

                index++;
                await taskManager.ReportProgress("Preparing tracks");
            }while (playlistTracks.Count < playlistSize);

            return(playlistTracks);
        }
예제 #2
0
        public async Task <Track> GetSigleTrackFromPlaylist(string id)
        {
            try
            {
                var spotify = await Authentication.GetSpotifyClientAsync();

                PlaylistGetItemsRequest rr = new PlaylistGetItemsRequest(PlaylistGetItemsRequest.AdditionalTypes.Track)
                {
                    Limit = 1
                };
                var fpl = await spotify.Playlists.GetItems(id, rr);

                return(ConvertTracks(new List <PlaylistTrack <IPlayableItem> > {
                    fpl.Items.FirstOrDefault()
                }).FirstOrDefault());
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #3
0
        public static async void OnNextSong(Spotify user, CurrentlyPlayingContext playing)
        {
            if (!user.Setting.ShuffleOn.Value)
            {
                return;
            }

            if (playing.Context == null)
            {
                Paging <SavedTrack> tracks = await user.spotify.Library.GetTracks();

                int i = rnd.Next(0, tracks.Total.Value);
                LibraryTracksRequest trackReq = new LibraryTracksRequest();
                trackReq.Offset = i;

                Paging <SavedTrack> targetTrack = await user.spotify.Library.GetTracks(trackReq);

                SavedTrack t = targetTrack.Items[0];
                await user.spotify.Player.AddToQueue(new PlayerAddToQueueRequest(t.Track.Uri));
            }
            else if (playing.Context.Type == "playlist" && user.Setting.ShufflePlaylists.Value)
            {
                string       id       = playing.Context.Href.Split('/').Last();
                FullPlaylist playlist = await user.spotify.Playlists.Get(id);

                int i = rnd.Next(0, playlist.Tracks.Total.Value);

                PlaylistGetItemsRequest playlistGet = new PlaylistGetItemsRequest();
                playlistGet.Offset = i;

                Paging <PlaylistTrack <IPlayableItem> > targetTrack = await user.spotify.Playlists.GetItems(id, playlistGet);

                PlaylistTrack <IPlayableItem> t = targetTrack.Items[0];
                await user.spotify.Player.AddToQueue(new PlayerAddToQueueRequest(((FullTrack)t.Track).Uri));
            }
            else if (playing.Context.Type == "album" && user.Setting.ShuffleAlbums.Value)
            {
#warning Not Implemented
            }
        }