Esempio n. 1
0
        public async Task <Playlist> CopyPlaylist(Models.PlaylistRequest request)
        {
            var playlist  = Playlists.First(t => t.Id == request.PlaylistId);
            var savedCopy = await _spotifyWebApi.CreatePlaylist(playlist, SpotifyApi.Playlists(Me), Token);

            Playlists.Add(savedCopy);
            return(savedCopy);
        }
Esempio n. 2
0
        public async Task <IEnumerable <Track> > GetPlaylistTracks(Models.PlaylistRequest request)
        {
            var playlist = Playlists.First(t => t.Id == request.PlaylistId);

            LastTrackSet = await _spotifyWebApi.Get <Envelope <TrackShell> >(playlist.Tracks.Resource, Token);

            while (!string.IsNullOrWhiteSpace(LastTrackSet.Next?.ToString()))
            {
                LastTrackSet = await _spotifyWebApi.Get <Envelope <TrackShell> >(LastTrackSet.Next, Token);
            }

            return(Tracks);
        }
Esempio n. 3
0
        public async Task <ShuffleResponse> ShufflePlaylist(Models.PlaylistRequest request)
        {
            var copiedPlaylist = await CopyPlaylist(request);

            var tracks = await GetPlaylistTracks(request);

            await AddTracks(new AddTracksRequest { PlaylistId = copiedPlaylist.Id, Tracks = tracks.Select(t => t.Uri).Shuffle() });

            Reset();
            var envelope = await _spotifyWebApi.Get <Envelope <Playlist> >(SpotifyApi.Playlists(Me), Token);

            Playlists.AddRange(envelope.Items);
            tracks = await GetPlaylistTracks(new Models.PlaylistRequest {
                PlaylistId = copiedPlaylist.Id
            });

            return(new ShuffleResponse {
                PlaylistName = copiedPlaylist.Name, TracksAdded = tracks.Count()
            });
        }