More headphones #32 I am starting to hate headphones... Sometimes the artists and albums just randomly fail.

pull/140/head
tidusjar 9 years ago
parent f81b1de850
commit 13ee1efd86

@ -39,5 +39,6 @@ namespace PlexRequests.Api.Interfaces
Task<bool> AddArtist(string apiKey, Uri baseUrl, string artistId);
Task<bool> QueueAlbum(string apiKey, Uri baseUrl, string albumId);
Task<List<HeadphonesGetIndex>> GetIndex(string apiKey, Uri baseUrl);
Task<bool> RefreshArtist(string apiKey, Uri baseUrl, string artistId);
}
}

@ -152,6 +152,33 @@ namespace PlexRequests.Api
}
}
public async Task<bool> RefreshArtist(string apiKey, Uri baseUrl, string artistId)
{
Log.Trace("Refreshing artist: {0}", artistId);
var request = new RestRequest
{
Resource = "/api",
Method = Method.GET
};
request.AddQueryParameter("apikey", apiKey);
request.AddQueryParameter("cmd", "queueAlbum");
request.AddQueryParameter("id", artistId);
try
{
var result = await Task.Run(() => Api.Execute(request, baseUrl)).ConfigureAwait(false);
Log.Info("Artist refresh Result: {0}", result.Content);
Log.Trace("Artist refresh Result: {0}", result.DumpJson());
return result.Content.Equals("OK", StringComparison.CurrentCultureIgnoreCase);
}
catch (JsonSerializationException jse)
{
Log.Error(jse);
return false; // If there is no matching result we do not get returned a JSON string, it just returns "false".
}
}
public HeadphonesVersion GetVersion(string apiKey, Uri baseUrl)
{
var request = new RestRequest

@ -24,7 +24,10 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;
@ -46,8 +49,8 @@ namespace PlexRequests.UI.Helpers
RequestService = request;
}
private int WaitTime => 1000;
private int CounterMax => 30;
private int WaitTime => 2000;
private int CounterMax => 60;
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
private IHeadphonesApi Api { get; }
@ -103,12 +106,23 @@ namespace PlexRequests.UI.Helpers
counter++;
Log.Trace("Artist is still not present in the index. Counter = {0}", counter);
index = await Api.GetIndex(Settings.ApiKey, Settings.FullUri);
//Fetch failed name
if (counter > CounterMax)
{
Log.Trace("Artist is still not present in the index. Counter = {0}. Returning false", counter);
return false;
}
}
var addedArtist = index.FirstOrDefault(x => x.ArtistID == request.ArtistId);
var artistName = addedArtist?.ArtistName ?? string.Empty;
while (artistName.Contains("Fetch failed"))
{
await Api.RefreshArtist(Settings.ApiKey, Settings.FullUri, request.ArtistId);
index = await Api.GetIndex(Settings.ApiKey, Settings.FullUri);
artistName = index?.FirstOrDefault(x => x.ArtistID == request.ArtistId)?.ArtistName ?? string.Empty;
}
counter = 0;
var artistStatus = index.Where(x => x.ArtistID == request.ArtistId).Select(x => x.Status).FirstOrDefault();

Loading…
Cancel
Save