Skip to content

Commit

Permalink
Refactor Async methods
Browse files Browse the repository at this point in the history
  • Loading branch information
byBlurr committed Feb 13, 2021
1 parent 2350d7a commit 8a871e2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions SpotifyShuffle/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private async Task OnImplicitGrantReceivedAsync(object sender, ImplictGrantRespo
int remainder = (int)playlists.Items[playlistId].Tracks.Total % 100;

// get all the tracks from the playlist and populate the lists
await GetAllTracks(playlistUri, allTracks, loops);
await GetAllTracksAsync(playlistUri, allTracks, loops);
PopulateSongLists(allTracks, songs, songsToRemove);

// recalculate the loops and remainder of the playlist, some of the tracks may have been invalid
Expand All @@ -111,13 +111,13 @@ private async Task OnImplicitGrantReceivedAsync(object sender, ImplictGrantRespo
if (shuffled.Count != songsToRemove.Count) throw new Exception($"For some reason there are not the same amount of songs in each list... Shuffled: {shuffled.Count}, Original: {songsToRemove.Count}");

// remove the tracks from the playlist and then add the shuffled list back
await RemoveSongsFromPlaylist(playlistUri, songsToRemove, loops);
await RemoveSongsFromPlaylistAsync(playlistUri, songsToRemove, loops);
await Task.Delay(100);
await AddSongsToPlaylist(playlistUri, shuffled, loops);
await AddSongsToPlaylistAsync(playlistUri, shuffled, loops);
await Task.Delay(100);

// shuffle local tracks
await ReorderSongs(playlistUri);
await ReorderSongsAsync(playlistUri);

Log(LogType.Success, "Shuffle", "Playlist shuffle complete.");
}
Expand Down Expand Up @@ -195,7 +195,7 @@ private async Task OnImplicitGrantReceivedAsync(object sender, ImplictGrantRespo
/// <param name="playlistUri">Playlist to retreive the songs from</param>
/// <param name="allTracks">List to add the songs to</param>
/// <param name="loops">How many loops are needed to complete the task</param>
private async Task GetAllTracks(string playlistUri, List<PlaylistTrack<IPlayableItem>> allTracks, int loops)
private async Task GetAllTracksAsync(string playlistUri, List<PlaylistTrack<IPlayableItem>> allTracks, int loops)
{
Log(LogType.Info, "Shuffle", "Gathering tracks from playlist...");
for (int i = 0; i <= loops; i++)
Expand Down Expand Up @@ -304,7 +304,7 @@ private List<string> Shuffle(List<Item> songs)
/// <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 RemoveSongsFromPlaylist(string playlistUri, List<Item> songsToRemove, int loops)
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++)
Expand Down Expand Up @@ -343,7 +343,7 @@ private async Task RemoveSongsFromPlaylist(string playlistUri, List<Item> songsT
/// <param name="playlistUri">The playlist to add the songs to</param>
/// <param name="songsToAdd">The songs to add</param>
/// <param name="loops">How many loops of 100 this will take</param>
private async Task AddSongsToPlaylist(string playlistUri, List<string> songsToAdd, int loops)
private async Task AddSongsToPlaylistAsync(string playlistUri, List<string> songsToAdd, int loops)
{
Log(LogType.Info, "Shuffle", "Adding songs back in shuffled order...");
for (int i = 0; i <= loops; i++)
Expand Down Expand Up @@ -374,7 +374,7 @@ private async Task AddSongsToPlaylist(string playlistUri, List<string> songsToAd
/// Reorder the local songs, they should all be at the top of the playlist to begin with
/// </summary>
/// <param name="playlistUri">The playlist being shuffled</param>
private async Task ReorderSongs(string playlistUri)
private async Task ReorderSongsAsync(string playlistUri)
{
Log(LogType.Info, "Shuffle", "Manually shuffling local songs...");
Random rnd = new Random();
Expand Down

0 comments on commit 8a871e2

Please sign in to comment.