Skip to content

Commit

Permalink
Implement handling of connectivity issues when re-scrobbling.
Browse files Browse the repository at this point in the history
  • Loading branch information
karaluh committed May 23, 2020
1 parent 0d9db3a commit d9b05a8
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions ScrobblerBrainz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,25 @@ public void ReceiveNotification(string sourceFileUrl, NotificationType type)
{
if (!String.IsNullOrEmpty(userToken)) // But only if the user token is configured.
{
submitListenResponse = httpClient.PostAsync("https://api.listenbrainz.org/1/submit-listens", new StringContent(File.ReadAllText(offlineScrobbles[i]), Encoding.UTF8, "application/json"));
if (submitListenResponse.Result.IsSuccessStatusCode) // If the scrobble succeedes, remove the file.
try
{
try
{
File.Delete(offlineScrobbles[i]);
}
catch(IOException) // Handle the case where the saved scrobble is opened.
submitListenResponse = httpClient.PostAsync("https://api.listenbrainz.org/1/submit-listens", new StringContent(File.ReadAllText(offlineScrobbles[i]), Encoding.UTF8, "application/json"));
if (submitListenResponse.Result.IsSuccessStatusCode) // If the scrobble succeedes, remove the file.
{
// Do nothing, the file will be removed on the next run.
try
{
File.Delete(offlineScrobbles[i]);
}
catch (IOException) // Handle the case where the saved scrobble is opened.
{
// Do nothing, the file will be removed on the next run.
}
}
}
catch // Handle the exception of connectivity issues.
{
// Do nothing, the file will be re-scrobbled on the next run.
}
}
}
//switch (mbApiInterface.Player_GetPlayState())
Expand Down

0 comments on commit d9b05a8

Please sign in to comment.