private Response RequestAlbumAndUpdateStatus(RequestedModel request) { var hpSettings = HeadphonesSettings.GetSettings(); Log.Info("Adding album to Headphones : {0}", request.Title); if (!hpSettings.Enabled) { // Approve it request.Approved = true; Log.Warn("We approved Album: {0} but could not add it to Headphones because it has not been setup", request.Title); // Update the record var inserted = Service.UpdateRequest(request); return(Response.AsJson(inserted ? new JsonResponseModel { Result = true, Message = "This has been approved, but It has not been sent to Headphones because it has not been configured." } : new JsonResponseModel { Result = false, Message = "We could not approve this request. Please try again or check the logs." })); } var sender = new HeadphonesSender(HeadphoneApi, hpSettings, Service); var result = sender.AddAlbum(request); return(Response.AsJson(new JsonResponseModel { Result = true, Message = "We have sent the approval to Headphones for processing, This can take a few minutes." })); }
private bool ProcessAlbums(RequestedModel model, HeadphonesSettings hp) { try { if (hp.Enabled) { var sender = new HeadphonesSender(HpApi, hp, RequestService); var result = sender.AddAlbum(model).Result; if (result) { if (ShouldAutoApprove(model.Type, PrSettings, model.RequestedUsers)) { // Approve it now model.Approved = true; } RequestService.UpdateRequest(model); } ; return(result); } return(false); } catch (Exception e) { Log.Error(e); return(false); // It fails so it will get added back into the queue } }
private Response RequestAlbum(string releaseId) { var settings = PrService.GetSettings(); var existingRequest = RequestService.CheckRequest(releaseId); Log.Debug("Checking for an existing request"); if (existingRequest != null) { Log.Debug("We do have an existing album request"); if (!existingRequest.UserHasRequested(Username)) { Log.Debug("Not in the requested list so adding them and updating the request. User: {0}", Username); existingRequest.RequestedUsers.Add(Username); RequestService.UpdateRequest(existingRequest); } return(Response.AsJson(new JsonResponseModel { Result = true, Message = settings.UsersCanViewOnlyOwnRequests ? $"{existingRequest.Title} was successfully added!" : $"{existingRequest.Title} has already been requested!" })); } Log.Debug("This is a new request"); var albumInfo = MusicBrainzApi.GetAlbum(releaseId); DateTime release; DateTimeHelper.CustomParse(albumInfo.ReleaseEvents?.FirstOrDefault()?.date, out release); var artist = albumInfo.ArtistCredits?.FirstOrDefault()?.artist; if (artist == null) { 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 albums = Checker.GetPlexAlbums(); var alreadyInPlex = Checker.IsAlbumAvailable(albums.ToArray(), albumInfo.title, release.ToString("yyyy"), artist.name); 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, MusicBrainzId = albumInfo.id, Overview = albumInfo.disambiguation, PosterPath = img, Type = RequestType.Album, ProviderId = 0, RequestedUsers = new List <string> { Username }, Status = albumInfo.status, Issues = IssueState.None, RequestedDate = DateTime.UtcNow, ReleaseDate = release, ArtistName = artist.name, ArtistId = artist.id }; if (ShouldAutoApprove(RequestType.Album, settings)) { Log.Debug("We don't require approval OR the user is in the whitelist"); var hpSettings = HeadphonesService.GetSettings(); Log.Trace("Headphone Settings:"); Log.Trace(hpSettings.DumpJson()); if (!hpSettings.Enabled) { RequestService.AddRequest(model); return (Response.AsJson(new JsonResponseModel { Result = true, Message = $"{model.Title} was successfully added!" })); } var sender = new HeadphonesSender(HeadphonesApi, hpSettings, RequestService); sender.AddAlbum(model).Wait(); model.Approved = true; RequestService.AddRequest(model); if (ShouldSendNotification()) { var notify2 = new NotificationModel { Title = model.Title, User = Username, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest }; NotificationService.Publish(notify2); } return (Response.AsJson(new JsonResponseModel { Result = true, Message = $"{model.Title} was successfully added!" })); } if (ShouldSendNotification()) { var notify2 = new NotificationModel { Title = model.Title, User = Username, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest }; NotificationService.Publish(notify2); } var result = RequestService.AddRequest(model); return(Response.AsJson(new JsonResponseModel { Result = true, Message = $"{model.Title} was successfully added!" })); }