public async Task <SenderResult> Send(ChildRequests model) { var sonarr = await SonarrSettings.GetSettingsAsync(); if (sonarr.Enabled) { var result = await SendToSonarr(model); if (result != null) { return(new SenderResult { Sent = true, Success = true }); } } var dog = await DogNzbSettings.GetSettingsAsync(); if (dog.Enabled) { var result = await SendToDogNzb(model, dog); if (!result.Failure) { return(new SenderResult { Sent = true, Success = true }); } return(new SenderResult { Message = result.ErrorMessage }); } var sr = await SickRageSettings.GetSettingsAsync(); if (sr.Enabled) { var result = await SendToSickRage(model, sr); if (result) { return(new SenderResult { Sent = true, Success = true }); } return(new SenderResult { Message = "Could not send to SickRage!" }); } return(new SenderResult { Success = true }); }
public async Task <SenderResult> Send(ChildRequests model) { try { var sonarr = await SonarrSettings.GetSettingsAsync(); if (sonarr.Enabled) { var result = await SendToSonarr(model, sonarr); if (result != null) { return(new SenderResult { Sent = true, Success = true }); } } var dog = await DogNzbSettings.GetSettingsAsync(); if (dog.Enabled) { var result = await SendToDogNzb(model, dog); if (!result.Failure) { return(new SenderResult { Sent = true, Success = true }); } return(new SenderResult { Message = result.ErrorMessage }); } var sr = await SickRageSettings.GetSettingsAsync(); if (sr.Enabled) { var result = await SendToSickRage(model, sr); if (result) { return(new SenderResult { Sent = true, Success = true }); } return(new SenderResult { Message = "Could not send to SickRage!" }); } return(new SenderResult { Success = true }); } catch (Exception e) { Logger.LogError(e, "Exception thrown when sending a movie to DVR app, added to the request queue"); // Check if already in request queue var existingQueue = await _requestQueueRepository.FirstOrDefaultAsync(x => x.RequestId == model.Id); if (existingQueue != null) { existingQueue.RetryCount++; existingQueue.Error = e.Message; await _requestQueueRepository.SaveChangesAsync(); } else { await _requestQueueRepository.Add(new RequestQueue { Dts = DateTime.UtcNow, Error = e.Message, RequestId = model.Id, Type = RequestType.TvShow, RetryCount = 0 }); _notificationHelper.Notify(model, NotificationType.ItemAddedToFaultQueue); } } return(new SenderResult { Success = false, Message = "Something went wrong!" }); }
private async Task <Response> GetTvShows() { var settingsTask = PrSettings.GetSettingsAsync(); var requests = await Service.GetAllAsync(); requests = requests.Where(x => x.Type == RequestType.TvShow); var dbTv = requests; var settings = await settingsTask; if (settings.UsersCanViewOnlyOwnRequests && !IsAdmin) { dbTv = dbTv.Where(x => x.UserHasRequested(Username)).ToList(); } IEnumerable <QualityModel> qualities = new List <QualityModel>(); if (IsAdmin) { try { var sonarrSettings = await SonarrSettings.GetSettingsAsync(); if (sonarrSettings.Enabled) { var result = Cache.GetOrSetAsync(CacheKeys.SonarrQualityProfiles, async() => { return(await Task.Run(() => SonarrApi.GetProfiles(sonarrSettings.ApiKey, sonarrSettings.FullUri))); }); qualities = result.Result.Select(x => new QualityModel { Id = x.id.ToString(), Name = x.name }).ToList(); } else { var sickRageSettings = await SickRageSettings.GetSettingsAsync(); if (sickRageSettings.Enabled) { qualities = sickRageSettings.Qualities.Select(x => new QualityModel { Id = x.Key, Name = x.Value }).ToList(); } } } catch (Exception e) { Log.Info(e); } } var viewModel = dbTv.Select(tv => new RequestViewModel { ProviderId = tv.ProviderId, Type = tv.Type, Status = tv.Status, ImdbId = tv.ImdbId, Id = tv.Id, PosterPath = tv.PosterPath, ReleaseDate = tv.ReleaseDate, ReleaseDateTicks = tv.ReleaseDate.Ticks, RequestedDate = tv.RequestedDate, RequestedDateTicks = DateTimeHelper.OffsetUTCDateTime(tv.RequestedDate, DateTimeOffset).Ticks, Released = DateTime.Now > tv.ReleaseDate, Approved = tv.Available || tv.Approved, Title = tv.Title, Overview = tv.Overview, RequestedUsers = IsAdmin ? tv.AllUsers.ToArray() : new string[] { }, ReleaseYear = tv.ReleaseDate.Year.ToString(), Available = tv.Available, Admin = IsAdmin, IssueId = tv.IssueId, TvSeriesRequestType = tv.SeasonsRequested, Qualities = qualities.ToArray(), Episodes = tv.Episodes.ToArray(), }).ToList(); return(Response.AsJson(viewModel)); }
private async Task <Response> UpdateRequestsAsync(RequestedModel[] requestedModels) { var cpSettings = await CpService.GetSettingsAsync(); var updatedRequests = new List <RequestedModel>(); foreach (var r in requestedModels) { if (r.Type == RequestType.Movie) { if (cpSettings.Enabled) { var res = SendMovie(cpSettings, r, CpApi); if (res) { r.Approved = true; updatedRequests.Add(r); } else { Log.Error("Could not approve and send the movie {0} to couch potato!", r.Title); } } else { r.Approved = true; updatedRequests.Add(r); } } if (r.Type == RequestType.TvShow) { var sender = new TvSenderOld(SonarrApi, SickRageApi); // TODO put back var sr = await SickRageSettings.GetSettingsAsync(); var sonarr = await SonarrSettings.GetSettingsAsync(); if (sr.Enabled) { var res = sender.SendToSickRage(sr, r); if (res?.result == "success") { r.Approved = true; updatedRequests.Add(r); } else { Log.Error("Could not approve and send the TV {0} to SickRage!", r.Title); Log.Error("SickRage Message: {0}", res?.message); } } else if (sonarr.Enabled) { var res = await sender.SendToSonarr(sonarr, r); if (!string.IsNullOrEmpty(res?.title)) { r.Approved = true; updatedRequests.Add(r); } else { Log.Error("Could not approve and send the TV {0} to Sonarr!", r.Title); res?.ErrorMessages?.ForEach(x => Log.Error("Error messages: {0}", x)); } } else { r.Approved = true; updatedRequests.Add(r); } } } try { var result = await Service.BatchUpdateAsync(updatedRequests); return(Response.AsJson(result ? new JsonResponseModel { Result = true } : new JsonResponseModel { Result = false, Message = "We could not approve all of the requests. Please try again or check the logs." })); } catch (Exception e) { Log.Fatal(e); return(Response.AsJson(new JsonResponseModel { Result = false, Message = "Something bad happened, please check the logs!" })); } }
private async Task <Response> RequestTvAndUpdateStatus(RequestedModel request, string qualityId) { var sender = new TvSenderOld(SonarrApi, SickRageApi); // TODO put back var sonarrSettings = await SonarrSettings.GetSettingsAsync(); if (sonarrSettings.Enabled) { Log.Trace("Sending to Sonarr"); var result = await sender.SendToSonarr(sonarrSettings, request, qualityId); Log.Trace("Sonarr Result: "); Log.Trace(result.DumpJson()); if (!string.IsNullOrEmpty(result.title)) { Log.Info("Sent successfully, Approving request now."); request.Approved = true; var requestResult = await Service.UpdateRequestAsync(request); Log.Trace("Approval result: {0}", requestResult); if (requestResult) { return(Response.AsJson(new JsonResponseModel { Result = true })); } return (Response.AsJson(new JsonResponseModel { Result = false, Message = "Updated Sonarr but could not approve it in PlexRequests :(" })); } return(Response.AsJson(ValidationHelper.SendSonarrError(result.ErrorMessages))); } var srSettings = await SickRageSettings.GetSettingsAsync(); if (srSettings.Enabled) { Log.Trace("Sending to SickRage"); var result = sender.SendToSickRage(srSettings, request, qualityId); Log.Trace("SickRage Result: "); Log.Trace(result.DumpJson()); if (result?.result == "success") { Log.Info("Sent successfully, Approving request now."); request.Approved = true; var requestResult = await Service.UpdateRequestAsync(request); Log.Trace("Approval result: {0}", requestResult); return(Response.AsJson(requestResult ? new JsonResponseModel { Result = true } : new JsonResponseModel { Result = false, Message = "Updated SickRage but could not approve it in PlexRequests :(" })); } return(Response.AsJson(new JsonResponseModel { Result = false, Message = result?.message != null ? "<b>Message From SickRage: </b>" + result.message : "Could not add the series to SickRage" })); } request.Approved = true; var res = await Service.UpdateRequestAsync(request); return(Response.AsJson(res ? new JsonResponseModel { Result = true, Message = "This has been approved, but It has not been sent to Sonarr/SickRage because it has not been configured" } : new JsonResponseModel { Result = false, Message = "Updated SickRage but could not approve it in PlexRequests :(" })); }
private async Task <Response> GetTvShows() { var requests = await Service.GetAllAsync(); requests = requests.Where(x => x.Type == RequestType.TvShow); var dbTv = requests; if (Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnRequests) && !IsAdmin) { dbTv = dbTv.Where(x => x.UserHasRequested(Username)).ToList(); } IEnumerable <QualityModel> qualities = new List <QualityModel>(); IEnumerable <RootFolderModel> rootFolders = new List <RootFolderModel>(); var sonarrSettings = await SonarrSettings.GetSettingsAsync(); if (IsAdmin) { try { if (sonarrSettings.Enabled) { var result = await Cache.GetOrSetAsync(CacheKeys.SonarrQualityProfiles, async() => { return(await Task.Run(() => SonarrApi.GetProfiles(sonarrSettings.ApiKey, sonarrSettings.FullUri))); }); qualities = result.Select(x => new QualityModel { Id = x.id.ToString(), Name = x.name }).ToList(); var rootFoldersResult = await Cache.GetOrSetAsync(CacheKeys.SonarrRootFolders, async() => { return(await Task.Run(() => SonarrApi.GetRootFolders(sonarrSettings.ApiKey, sonarrSettings.FullUri))); }); rootFolders = rootFoldersResult.Select(x => new RootFolderModel { Id = x.id.ToString(), Path = x.path, FreeSpace = x.freespace }).ToList(); } else { var sickRageSettings = await SickRageSettings.GetSettingsAsync(); if (sickRageSettings.Enabled) { qualities = sickRageSettings.Qualities.Select(x => new QualityModel { Id = x.Key, Name = x.Value }).ToList(); } } } catch (Exception e) { Log.Info(e); } } var canManageRequest = Security.HasAnyPermissions(User, Permissions.Administrator, Permissions.ManageRequests); var allowViewUsers = Security.HasAnyPermissions(User, Permissions.Administrator, Permissions.ViewUsers); var viewModel = dbTv.Select(tv => new RequestViewModel { ProviderId = tv.ProviderId, Type = tv.Type, Status = tv.Status, ImdbId = tv.ImdbId, Id = tv.Id, PosterPath = tv.PosterPath?.Contains("http:") ?? false ? tv.PosterPath?.Replace("http:", "https:") : tv.PosterPath ?? string.Empty, // We make the poster path https on request, but this is just incase ReleaseDate = tv.ReleaseDate, ReleaseDateTicks = tv.ReleaseDate.Ticks, RequestedDate = tv.RequestedDate, RequestedDateTicks = DateTimeHelper.OffsetUTCDateTime(tv.RequestedDate, DateTimeOffset).Ticks, Released = DateTime.Now > tv.ReleaseDate, Approved = tv.Available || tv.Approved, Title = tv.Title, Overview = tv.Overview, RequestedUsers = canManageRequest || allowViewUsers ? tv.AllUsers.ToArray() : new string[] { }, ReleaseYear = tv.ReleaseDate.Year.ToString(), Available = tv.Available, Admin = canManageRequest, IssueId = tv.IssueId, Denied = tv.Denied, DeniedReason = tv.DeniedReason, TvSeriesRequestType = tv.SeasonsRequested, Qualities = qualities.ToArray(), Episodes = tv.Episodes.ToArray(), RootFolders = rootFolders.ToArray(), HasRootFolders = rootFolders.Any(), CurrentRootPath = sonarrSettings.Enabled ? GetRootPath(tv.RootFolderSelected, sonarrSettings).Result : null }).ToList(); return(Response.AsJson(viewModel)); }