Skip to content

Commit

Permalink
Refactor class variables
Browse files Browse the repository at this point in the history
  • Loading branch information
byBlurr committed Feb 13, 2021
1 parent 8a871e2 commit dd30410
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions SpotifyShuffle/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ private static void Main(string[] args)
}

private static readonly string CLIENT_ID = "9ffc2360c76f49cd8d7e0b2ac115a18f";
private static SpotifyClient client;
private static EmbedIOAuthServer server;
private static SpotifyClient Client;
private static EmbedIOAuthServer Server;

private static int Tracks = 0;
private static int Locals = 0;
Expand All @@ -31,9 +31,9 @@ private static void Main(string[] args)
private async Task AuthoriseAsync()
{
// create the callback server on localhost:8888, start it and bind the ImplictGrantReceived event to the method
server = new EmbedIOAuthServer(new Uri("http://localhost:8888/callback"), 8888);
await server.Start();
server.ImplictGrantReceived += OnImplicitGrantReceivedAsync;
Server = new EmbedIOAuthServer(new Uri("http://localhost:8888/callback"), 8888);
await Server.Start();
Server.ImplictGrantReceived += OnImplicitGrantReceivedAsync;

// set up our request with the scopes etc, then open the browser for authorisation
ObtainToken();
Expand All @@ -46,7 +46,7 @@ private async Task AuthoriseAsync()
/// </summary>
private static void ObtainToken()
{
var request = new LoginRequest(server.BaseUri, CLIENT_ID, LoginRequest.ResponseType.Token)
var request = new LoginRequest(Server.BaseUri, CLIENT_ID, LoginRequest.ResponseType.Token)
{
Scope = new List<string> { Scopes.PlaylistModifyPrivate, Scopes.PlaylistModifyPublic, Scopes.PlaylistReadPrivate, Scopes.PlaylistReadCollaborative }
};
Expand All @@ -59,17 +59,17 @@ private static void ObtainToken()
private async Task OnImplicitGrantReceivedAsync(object sender, ImplictGrantResponse response)
{
// stop the server and create a new client using the token, get the current users id
await server.Stop();
client = new SpotifyClient(response.AccessToken);
string user = (await client.UserProfile.Current()).Id;
await Server.Stop();
Client = new SpotifyClient(response.AccessToken);
string user = (await Client.UserProfile.Current()).Id;

// make sure the users id isnt null/empty for some strange reason
if (!String.IsNullOrEmpty(user) && !String.IsNullOrWhiteSpace(user))
{
while (true)
{
// get the current users playlists and make sure the list isnt null
Paging<SimplePlaylist> playlists = await client.Playlists.GetUsers(user);
Paging<SimplePlaylist> playlists = await Client.Playlists.GetUsers(user);
if (playlists != null && playlists.Items != null)
{
// list the playlists to the user
Expand Down Expand Up @@ -173,7 +173,7 @@ private async Task OnImplicitGrantReceivedAsync(object sender, ImplictGrantRespo
else
{
Log(LogType.Info, "Program", "Obtaining new token...");
await server.Start();
await Server.Start();
ObtainToken();
return;
}
Expand All @@ -200,7 +200,7 @@ private async Task GetAllTracksAsync(string playlistUri, List<PlaylistTrack<IPla
Log(LogType.Info, "Shuffle", "Gathering tracks from playlist...");
for (int i = 0; i <= loops; i++)
{
var toAdd = await client.Playlists.GetItems(playlistUri, new PlaylistGetItemsRequest() { Offset = i * 100 });
var toAdd = await Client.Playlists.GetItems(playlistUri, new PlaylistGetItemsRequest() { Offset = i * 100 });
allTracks.AddRange(toAdd.Items);
}
}
Expand Down Expand Up @@ -317,7 +317,7 @@ private async Task RemoveSongsFromPlaylistAsync(string playlistUri, List<Item> s
{
Tracks = songsToRemove
};
await client.Playlists.RemoveItems(playlistUri, removeRequest);
await Client.Playlists.RemoveItems(playlistUri, removeRequest);
Log(LogType.Info, "Shuffle", $"Removed {songsToRemove.Count} songs");
}
}
Expand All @@ -330,7 +330,7 @@ private async Task RemoveSongsFromPlaylistAsync(string playlistUri, List<Item> s
{
Tracks = songsToRemoveThisLoop
};
await client.Playlists.RemoveItems(playlistUri, removeRequest);
await Client.Playlists.RemoveItems(playlistUri, removeRequest);
Log(LogType.Info, "Shuffle", "Removed 100 songs");
}
await Task.Delay(50);
Expand All @@ -353,7 +353,7 @@ private async Task AddSongsToPlaylistAsync(string playlistUri, List<string> song
if (songsToAdd.Count > 0)
{
var addRequest = new PlaylistAddItemsRequest(songsToAdd);
await client.Playlists.AddItems(playlistUri, addRequest);
await Client.Playlists.AddItems(playlistUri, addRequest);
Log(LogType.Info, "Shuffle", $"Added back {songsToAdd.Count} songs");
}
}
Expand All @@ -363,7 +363,7 @@ private async Task AddSongsToPlaylistAsync(string playlistUri, List<string> song
songsToAdd.RemoveRange(0, 100);

var addRequest = new PlaylistAddItemsRequest(songsToAddThisLoop);
await client.Playlists.AddItems(playlistUri, addRequest);
await Client.Playlists.AddItems(playlistUri, addRequest);
Log(LogType.Info, "Shuffle", "Added back 100 songs");
}
await Task.Delay(50);
Expand All @@ -381,7 +381,7 @@ private async Task ReorderSongsAsync(string playlistUri)
for (int i = 0; i < Locals; i++)
{
var reorderRequest = new PlaylistReorderItemsRequest(0, rnd.Next(1, (Tracks + Locals)));
await client.Playlists.ReorderItems(playlistUri, reorderRequest);
await Client.Playlists.ReorderItems(playlistUri, reorderRequest);
await Task.Delay(50);
}

Expand Down

0 comments on commit dd30410

Please sign in to comment.