From e02c8e4014aba9c95b822c0c4bae16a29fefa362 Mon Sep 17 00:00:00 2001 From: Jamie Date: Sun, 26 Aug 2018 23:42:53 +0100 Subject: [PATCH] It works now when we request an album when we do not have the artist in Lidarr. Waiting on https://github.com/lidarr/Lidarr/issues/459 to do when we have the artist --- src/Ombi.Api.Lidarr/LidarrApi.cs | 4 ++-- src/Ombi.Api.Lidarr/Models/ArtistAdd.cs | 1 + src/Ombi.Core/Senders/MusicSender.cs | 22 ++++++++++++++++--- .../requests/music/musicrequests.component.ts | 7 +++--- .../ClientApp/app/services/request.service.ts | 2 +- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/Ombi.Api.Lidarr/LidarrApi.cs b/src/Ombi.Api.Lidarr/LidarrApi.cs index 572a2b55c..cf358699c 100644 --- a/src/Ombi.Api.Lidarr/LidarrApi.cs +++ b/src/Ombi.Api.Lidarr/LidarrApi.cs @@ -113,7 +113,7 @@ namespace Ombi.Api.Lidarr return Api.Request(request); } - public Task MontiorAlbum(int albumId, string apiKey, string baseUrl) + public async Task MontiorAlbum(int albumId, string apiKey, string baseUrl) { var request = new Request($"{ApiVersion}/album/monitor", baseUrl, HttpMethod.Put); request.AddJsonBody(new @@ -122,7 +122,7 @@ namespace Ombi.Api.Lidarr monitored = true }); AddHeaders(request, apiKey); - return Api.Request(request); + return (await Api.Request>(request)).FirstOrDefault(); } public Task> GetAllAlbumsByArtistId(int artistId, string apiKey, string baseUrl) diff --git a/src/Ombi.Api.Lidarr/Models/ArtistAdd.cs b/src/Ombi.Api.Lidarr/Models/ArtistAdd.cs index e77a239e6..65aec3ac8 100644 --- a/src/Ombi.Api.Lidarr/Models/ArtistAdd.cs +++ b/src/Ombi.Api.Lidarr/Models/ArtistAdd.cs @@ -44,5 +44,6 @@ namespace Ombi.Api.Lidarr.Models public int selectedOption { get; set; } public bool monitored { get; set; } public bool searchForMissingAlbums { get; set; } + public string[] AlbumsToMonitor { get; set; } // Uses the MusicBrainzAlbumId! } } \ No newline at end of file diff --git a/src/Ombi.Core/Senders/MusicSender.cs b/src/Ombi.Core/Senders/MusicSender.cs index 3baa26003..5e1e44126 100644 --- a/src/Ombi.Core/Senders/MusicSender.cs +++ b/src/Ombi.Core/Senders/MusicSender.cs @@ -57,7 +57,8 @@ namespace Ombi.Core.Senders { monitored = true, searchForMissingAlbums = false, - selectedOption = 6 // None + selectedOption = 6, // None + AlbumsToMonitor = new[] {model.ForeignAlbumId} }, added = DateTime.Now, monitored = true, @@ -76,7 +77,7 @@ namespace Ombi.Core.Senders if (result != null && result.id > 0) { // Setup the albums - await SetupAlbum(model, result, settings); + return new SenderResult { Message = "Album has been requested!", Sent = true, Success = true }; } } else @@ -91,9 +92,24 @@ namespace Ombi.Core.Senders { // Get the album id var albums = await _lidarrApi.GetAllAlbumsByArtistId(artist.id, settings.ApiKey, settings.FullUri); - // Get the album we want. var album = albums.FirstOrDefault(x => x.foreignAlbumId.Equals(model.ForeignAlbumId, StringComparison.InvariantCultureIgnoreCase)); + var maxRetryCount = 10; // 5 seconds + var currentRetry = 0; + while (!albums.Any() || album == null) + { + if (currentRetry >= maxRetryCount) + { + break; + } + currentRetry++; + await Task.Delay(500); + albums = await _lidarrApi.GetAllAlbumsByArtistId(artist.id, settings.ApiKey, settings.FullUri); + album = albums.FirstOrDefault(x => + x.foreignAlbumId.Equals(model.ForeignAlbumId, StringComparison.InvariantCultureIgnoreCase)); + } + // Get the album we want. + if (album == null) { return new SenderResult { Message = "Could not find album in Lidarr", Sent = false, Success = false }; diff --git a/src/Ombi/ClientApp/app/requests/music/musicrequests.component.ts b/src/Ombi/ClientApp/app/requests/music/musicrequests.component.ts index f004b4019..8f8096acd 100644 --- a/src/Ombi/ClientApp/app/requests/music/musicrequests.component.ts +++ b/src/Ombi/ClientApp/app/requests/music/musicrequests.component.ts @@ -88,9 +88,10 @@ export class MusicRequestsComponent implements OnInit { } public removeRequest(request: IAlbumRequest) { - this.requestService.removeAlbumRequest(request); - this.removeRequestFromUi(request); - this.loadRequests(this.amountToLoad, this.currentlyLoaded = 0); + this.requestService.removeAlbumRequest(request).subscribe(x => { + this.removeRequestFromUi(request); + this.loadRequests(this.amountToLoad, this.currentlyLoaded = 0); + }); } public changeAvailability(request: IAlbumRequest, available: boolean) { diff --git a/src/Ombi/ClientApp/app/services/request.service.ts b/src/Ombi/ClientApp/app/services/request.service.ts index 045a73310..039939a84 100644 --- a/src/Ombi/ClientApp/app/services/request.service.ts +++ b/src/Ombi/ClientApp/app/services/request.service.ts @@ -167,7 +167,7 @@ export class RequestService extends ServiceHelpers { return this.http.get(`${this.url}music/search/${search}`, {headers: this.headers}); } - public removeAlbumRequest(request: IAlbumRequest) { + public removeAlbumRequest(request: IAlbumRequest): any { this.http.delete(`${this.url}music/${request.id}`, {headers: this.headers}).subscribe(); }