mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-10 15:32:37 -07:00
Some final tweaks for #32
This commit is contained in:
parent
5e5fe1f395
commit
f3cca9f0e9
3 changed files with 48 additions and 30 deletions
|
@ -26,8 +26,6 @@
|
|||
#endregion
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Versioning;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Octokit;
|
||||
|
@ -62,7 +60,10 @@ namespace PlexRequests.Core
|
|||
};
|
||||
|
||||
var latestRelease = GetLatestRelease();
|
||||
|
||||
if (latestRelease.Result == null)
|
||||
{
|
||||
return new StatusModel { Version = "Unknown" };
|
||||
}
|
||||
var latestVersionArray = latestRelease.Result.Name.Split(new[] { 'v' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var latestVersion = latestVersionArray.Length > 1 ? latestVersionArray[1] : string.Empty;
|
||||
|
||||
|
|
|
@ -111,23 +111,6 @@ namespace PlexRequests.UI.Helpers
|
|||
return false;
|
||||
}
|
||||
}
|
||||
var addedArtist = index.FirstOrDefault(x => x.ArtistID == request.ArtistId);
|
||||
var artistName = addedArtist?.ArtistName ?? string.Empty;
|
||||
while (artistName.Contains("Fetch failed"))
|
||||
{
|
||||
Thread.Sleep(WaitTime);
|
||||
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;
|
||||
if (counter > CounterMax)
|
||||
{
|
||||
Log.Trace("Artist fetch has failed. Counter = {0}. Returning false", counter);
|
||||
Log.Warn("Artist in headphones fetch has failed, we have tried refreshing the artist but no luck.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
counter = 0;
|
||||
var artistStatus = index.Where(x => x.ArtistID == request.ArtistId).Select(x => x.Status).FirstOrDefault();
|
||||
|
@ -145,6 +128,27 @@ namespace PlexRequests.UI.Helpers
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var addedArtist = index.FirstOrDefault(x => x.ArtistID == request.ArtistId);
|
||||
var artistName = addedArtist?.ArtistName ?? string.Empty;
|
||||
counter = 0;
|
||||
while (artistName.Contains("Fetch failed"))
|
||||
{
|
||||
Thread.Sleep(WaitTime);
|
||||
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++;
|
||||
if (counter > CounterMax)
|
||||
{
|
||||
Log.Trace("Artist fetch has failed. Counter = {0}. Returning false", counter);
|
||||
Log.Warn("Artist in headphones fetch has failed, we have tried refreshing the artist but no luck.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -504,13 +504,6 @@ namespace PlexRequests.UI.Modules
|
|||
Log.Debug("This is a new request");
|
||||
|
||||
var albumInfo = MusicBrainzApi.GetAlbum(releaseId);
|
||||
var img = GetMusicBrainzCoverArt(albumInfo.id);
|
||||
|
||||
Log.Trace("Album Details:");
|
||||
Log.Trace(albumInfo.DumpJson());
|
||||
Log.Trace("CoverArt Details:");
|
||||
Log.Trace(img.DumpJson());
|
||||
|
||||
DateTime release;
|
||||
DateTimeHelper.CustomParse(albumInfo.ReleaseEvents?.FirstOrDefault()?.date, out release);
|
||||
|
||||
|
@ -520,6 +513,25 @@ namespace PlexRequests.UI.Modules
|
|||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "We could not find the artist on MusicBrainz. Please try again later or contact your admin" });
|
||||
}
|
||||
|
||||
var alreadyInPlex = CheckIfTitleExistsInPlex(albumInfo.title, release.ToString("yyyy"), artist.name, PlexType.Music);
|
||||
|
||||
if (alreadyInPlex)
|
||||
{
|
||||
return Response.AsJson(new JsonResponseModel
|
||||
{
|
||||
Result = false,
|
||||
Message = $"{albumInfo.title} is already in Plex!"
|
||||
});
|
||||
}
|
||||
|
||||
var img = GetMusicBrainzCoverArt(albumInfo.id);
|
||||
|
||||
Log.Trace("Album Details:");
|
||||
Log.Trace(albumInfo.DumpJson());
|
||||
Log.Trace("CoverArt Details:");
|
||||
Log.Trace(img.DumpJson());
|
||||
|
||||
|
||||
var model = new RequestedModel
|
||||
{
|
||||
Title = albumInfo.title,
|
||||
|
@ -559,6 +571,7 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
var sender = new HeadphonesSender(HeadphonesApi, hpSettings, RequestService);
|
||||
sender.AddAlbum(model);
|
||||
model.Approved = true;
|
||||
RequestService.AddRequest(model);
|
||||
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue