mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 21:03:17 -07:00
More headphones #32 I am starting to hate headphones... Sometimes the artists and albums just randomly fail.
This commit is contained in:
parent
f81b1de850
commit
13ee1efd86
3 changed files with 44 additions and 2 deletions
|
@ -39,5 +39,6 @@ namespace PlexRequests.Api.Interfaces
|
||||||
Task<bool> AddArtist(string apiKey, Uri baseUrl, string artistId);
|
Task<bool> AddArtist(string apiKey, Uri baseUrl, string artistId);
|
||||||
Task<bool> QueueAlbum(string apiKey, Uri baseUrl, string albumId);
|
Task<bool> QueueAlbum(string apiKey, Uri baseUrl, string albumId);
|
||||||
Task<List<HeadphonesGetIndex>> GetIndex(string apiKey, Uri baseUrl);
|
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)
|
public HeadphonesVersion GetVersion(string apiKey, Uri baseUrl)
|
||||||
{
|
{
|
||||||
var request = new RestRequest
|
var request = new RestRequest
|
||||||
|
|
|
@ -24,7 +24,10 @@
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
@ -46,8 +49,8 @@ namespace PlexRequests.UI.Helpers
|
||||||
RequestService = request;
|
RequestService = request;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int WaitTime => 1000;
|
private int WaitTime => 2000;
|
||||||
private int CounterMax => 30;
|
private int CounterMax => 60;
|
||||||
|
|
||||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
private IHeadphonesApi Api { get; }
|
private IHeadphonesApi Api { get; }
|
||||||
|
@ -103,12 +106,23 @@ namespace PlexRequests.UI.Helpers
|
||||||
counter++;
|
counter++;
|
||||||
Log.Trace("Artist is still not present in the index. Counter = {0}", counter);
|
Log.Trace("Artist is still not present in the index. Counter = {0}", counter);
|
||||||
index = await Api.GetIndex(Settings.ApiKey, Settings.FullUri);
|
index = await Api.GetIndex(Settings.ApiKey, Settings.FullUri);
|
||||||
|
//Fetch failed name
|
||||||
if (counter > CounterMax)
|
if (counter > CounterMax)
|
||||||
{
|
{
|
||||||
Log.Trace("Artist is still not present in the index. Counter = {0}. Returning false", counter);
|
Log.Trace("Artist is still not present in the index. Counter = {0}. Returning false", counter);
|
||||||
return false;
|
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;
|
counter = 0;
|
||||||
var artistStatus = index.Where(x => x.ArtistID == request.ArtistId).Select(x => x.Status).FirstOrDefault();
|
var artistStatus = index.Where(x => x.ArtistID == request.ArtistId).Select(x => x.Status).FirstOrDefault();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue