Exemplo n.º 1
0
        private bool ProcessTvShow(RequestedModel tvModel, SonarrSettings sonarr, SickRageSettings sickrage)
        {
            try
            {
                var sender = new TvSenderOld(SonarrApi, SrApi);
                if (sonarr.Enabled)
                {
                    var task = sender.SendToSonarr(sonarr, tvModel, sonarr.QualityProfile);
                    var a    = task.Result;
                    if (string.IsNullOrEmpty(a?.title))
                    {
                        // Couldn't send it
                        return(false);
                    }
                    return(true);
                }

                if (sickrage.Enabled)
                {
                    var result = sender.SendToSickRage(sickrage, tvModel);
                    if (result?.result != "success")
                    {
                        // Couldn't send it
                        return(false);
                    }

                    // Approve it
                    tvModel.Approved = true;
                    RequestService.UpdateRequest(tvModel);
                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                Log.Error(e);
                return(false); // It fails so it will get added back into the queue
            }
        }
Exemplo n.º 2
0
        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!"
                }));
            }
        }
Exemplo n.º 3
0
        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 :("
            }));
        }