private async Task <SearchAlbumViewModel> MapIntoAlbumVm(Album a, string artistId, string artistName, LidarrSettings settings) { var fullAlbum = await _lidarrApi.GetAlbumByForeignId(a.Id, settings.ApiKey, settings.FullUri); var vm = new SearchAlbumViewModel { ForeignAlbumId = a.Id, Monitored = fullAlbum.monitored, Rating = fullAlbum.ratings?.value ?? 0m, ReleaseDate = fullAlbum.releaseDate, Title = a.Title, Disk = fullAlbum.images?.FirstOrDefault(x => x.coverType.Equals("disc"))?.url, ForeignArtistId = artistId, ArtistName = artistName, Cover = fullAlbum.images?.FirstOrDefault(x => x.coverType.Equals("cover"))?.url }; if (vm.Cover.IsNullOrEmpty()) { vm.Cover = fullAlbum.remoteCover; } await Rules.StartSpecificRules(vm, SpecificRules.LidarrAlbum); await RunSearchRules(vm); return(vm); }
private async Task ProcessAlbums(HashSet <LidarrAlbumCache> albumsToSend, StringBuilder sb) { var settings = await _lidarrSettings.GetSettingsAsync(); int count = 0; var ordered = albumsToSend.OrderByDescending(x => x.AddedAt); foreach (var content in ordered) { var info = await _lidarrApi.GetAlbumByForeignId(content.ForeignAlbumId, settings.ApiKey, settings.FullUri); if (info == null) { continue; } try { CreateAlbumHtmlContent(sb, info); count += 1; } catch (Exception e) { _log.LogError(e, "Error when Processing Lidarr Album {0}", info.title); } finally { EndLoopHtml(sb); } if (count == 2) { count = 0; sb.Append("</tr>"); sb.Append("<tr>"); } } }
/// <summary> /// Requests the Album. /// </summary> /// <param name="model">The model.</param> /// <returns></returns> public async Task <RequestEngineResult> RequestAlbum(MusicAlbumRequestViewModel model) { var s = await _lidarrSettings.GetSettingsAsync(); var album = await _lidarrApi.GetAlbumByForeignId(model.ForeignAlbumId, s.ApiKey, s.FullUri); if (album == null) { return(new RequestEngineResult { Result = false, Message = "There was an issue adding this album!", ErrorMessage = "Please try again later" }); } var userDetails = await GetUser(); var requestModel = new AlbumRequest { ForeignAlbumId = model.ForeignAlbumId, ArtistName = album.artist?.artistName, ReleaseDate = album.releaseDate, RequestedDate = DateTime.Now, RequestType = RequestType.Album, Rating = album.ratings?.value ?? 0m, RequestedUserId = userDetails.Id, Title = album.title, Disk = album.images?.FirstOrDefault(x => x.coverType.Equals("disc"))?.url, Cover = album.images?.FirstOrDefault(x => x.coverType.Equals("cover"))?.url, ForeignArtistId = album?.artist?.foreignArtistId ?? string.Empty, RequestedByAlias = model.RequestedByAlias }; if (requestModel.Cover.IsNullOrEmpty()) { requestModel.Cover = album.remoteCover; } var ruleResults = (await RunRequestRules(requestModel)).ToList(); if (ruleResults.Any(x => !x.Success)) { return(new RequestEngineResult { ErrorMessage = ruleResults.FirstOrDefault(x => x.Message.HasValue()).Message }); } if (requestModel.Approved) // The rules have auto approved this { var requestEngineResult = await AddAlbumRequest(requestModel); if (requestEngineResult.Result) { var result = await ApproveAlbum(requestModel); if (result.IsError) { Logger.LogWarning("Tried auto sending Album but failed. Message: {0}", result.Message); return(new RequestEngineResult { Message = result.Message, ErrorMessage = result.Message, Result = false }); } return(requestEngineResult); } // If there are no providers then it's successful but album has not been sent } return(await AddAlbumRequest(requestModel)); }