Exemple #1
0
        /// <summary>
        /// Remove the songs from the playlist
        /// </summary>
        /// <param name="playlistUri">The playlist to remove from</param>
        /// <param name="songsToRemove">The songs to remove</param>
        /// <param name="loops">How many loops of 100 this will take</param>
        private async Task RemoveSongsFromPlaylistAsync(string playlistUri, List <Item> songsToRemove, int loops)
        {
            Log(LogType.Info, "Shuffle", "Removing songs from playlist...");
            for (int i = 0; i <= loops; i++)
            {
                if (i == loops)
                {
                    if (songsToRemove.Count > 0)
                    {
                        var removeRequest = new PlaylistRemoveItemsRequest
                        {
                            Tracks = songsToRemove
                        };
                        await Client.Playlists.RemoveItems(playlistUri, removeRequest);

                        Log(LogType.Info, "Shuffle", $"Removed {songsToRemove.Count} songs");
                    }
                }
                else
                {
                    List <Item> songsToRemoveThisLoop = songsToRemove.GetRange(0, 100);
                    songsToRemove.RemoveRange(0, 100);

                    var removeRequest = new PlaylistRemoveItemsRequest
                    {
                        Tracks = songsToRemoveThisLoop
                    };
                    await Client.Playlists.RemoveItems(playlistUri, removeRequest);

                    Log(LogType.Info, "Shuffle", "Removed 100 songs");
                }
                await Task.Delay(50);
            }
        }
Exemple #2
0
        public async Task <bool> RemoveItemsFromPlaylist(string playlistId, List <string> uris)
        {
            try
            {
                var spotify = await Authentication.GetSpotifyClientAsync();

                List <PlaylistRemoveItemsRequest.Item> items = new List <PlaylistRemoveItemsRequest.Item>();
                foreach (var uri in uris)
                {
                    items.Add(new PlaylistRemoveItemsRequest.Item {
                        Uri = uri
                    });
                }
                PlaylistRemoveItemsRequest request = new PlaylistRemoveItemsRequest(items);

                await spotify.Playlists.RemoveItems(playlistId, request);

                return(true);
            }
            catch (Exception)
            {
                ViewModels.Helpers.DisplayDialog("Error", "An error occured, please try again");
                return(false);
            }
        }
        public async Task SyncTracksAsync(PlaylistGenerationContext context)
        {
            FullTrack[] toDelete = context.TargetTracks
                                   .Where(t => !context.SourceTracks.Any(s => s.Id == t.Id))
                                   .ToArray();

            FullTrack[] toAdd = context.SourceTracks
                                .Where(s => !context.TargetTracks.Any(t => t.Id == s.Id))
                                .ToArray();

            foreach (IEnumerable <FullTrack> batch in toDelete.Batch(100))
            {
                PlaylistRemoveItemsRequest req = new PlaylistRemoveItemsRequest
                {
                    Tracks = batch.Select(o => new PlaylistRemoveItemsRequest.Item {
                        Uri = o.Uri
                    }).ToList()
                };

                SnapshotResponse res = await context.Client.Playlists.RemoveItems(context.TargetPlaylist.Id, req);
            }

            foreach (IEnumerable <FullTrack> batch in toAdd.Batch(100))
            {
                SnapshotResponse res = await context.Client.Playlists.AddItems(context.TargetPlaylist.Id, new PlaylistAddItemsRequest(batch.Select(o => o.Uri).ToList()));
            }

            context.TargetTracks = context.TargetTracks
                                   .Except(toDelete)
                                   .Concat(toAdd)
                                   .ToList();
        }
        public async Task RemoveTrackFromPlaylist(ISpotifyClient spotifyClient, string trackId, string playlistId)
        {
            var removeRequest = new PlaylistRemoveItemsRequest
            {
                Tracks = new List <PlaylistRemoveItemsRequest.Item>
                {
                    new PlaylistRemoveItemsRequest.Item
                    {
                        Uri = $"{_trackInlineBaseUri}{trackId}"
                    }
                }
            };

            // Remove the track from the playlist.
            await spotifyClient.Playlists.RemoveItems(playlistId, removeRequest);
        }
Exemple #5
0
        public static async Task <Skip> Skipped(Spotify user, FullTrack track, CurrentlyPlayingContext playing, SpotterAzure_dbContext dbContext)
        {
            if (user.Setting.SkipOn.Value &&
                !(user.Setting.SkipIgnorePlaylist.Value && (playing.Context != null && playing.Context.Type == "playlist")))
            {
                if (playing.Context == null || playing.Context.Type != "playlist" || !(await user.spotify.Playlists.Get(playing.Context.Href.Split('/').Last())).Name.EndsWith(user.Setting.SkipIgnorePostfix))
                {
                    List <bool> Exists = await user.spotify.Library.CheckTracks(new LibraryCheckTracksRequest(new List <string>()
                    {
                        track.Id
                    }));

                    if (Exists[0] || !user.Setting.SkipMustBeLiked.Value)
                    {
                        int recent = user.RecentSkips(track.Id, user.Setting.SkipExpiryHours.Value, dbContext);

                        if (recent >= user.Setting.SkipTrigger - 1)
                        {
                            if (user.KickedTracks.Count(x => ((FullTrack)x.Track).Id == track.Id) == 0)
                            {
                                await user.spotify.Playlists.AddItems(user.KickedPlaylist.Id, new PlaylistAddItemsRequest(new List <string>()
                                {
                                    track.Uri
                                }));

                                Track t = new Track(track, user);
                                user.KickedTracks.Add(new PlaylistTrack <IPlayableItem>());
                                user.KickedTracks.Last().Track = track;
                            }

                            if (Exists[0])
                            {
                                await user.spotify.Library.RemoveTracks(new LibraryRemoveTracksRequest(new List <string>()
                                {
                                    track.Id
                                }));
                            }

                            if (playing.Context.Type == "playlist" && user.Setting.SkipRemoveFromPlaylist.Value)
                            {
                                PlaylistRemoveItemsRequest removeReq = new PlaylistRemoveItemsRequest();

                                PlaylistRemoveItemsRequest.Item removeSongReq = new PlaylistRemoveItemsRequest.Item();
                                removeSongReq.Uri = track.Uri;
                                removeReq.Tracks  = new List <PlaylistRemoveItemsRequest.Item>()
                                {
                                    removeSongReq
                                };

                                await user.spotify.Playlists.RemoveItems(playing.Context.Href.Split('/').Last(), removeReq);
                            }
                        }
                        else
                        {
                        }
                        return(new Skip(track.Id, user));
                    }
                }
            }
            return(null);
        }