Made the feedback from Sonarr better when Sonarr already has the series #85

pull/110/head
tidusjar 9 years ago
parent 5843dee2a5
commit fe0f6873e5

@ -64,6 +64,7 @@
<Compile Include="SickRage\SickRageStatus.cs" /> <Compile Include="SickRage\SickRageStatus.cs" />
<Compile Include="SickRage\SickRageTvAdd.cs" /> <Compile Include="SickRage\SickRageTvAdd.cs" />
<Compile Include="Sonarr\SonarrAddSeries.cs" /> <Compile Include="Sonarr\SonarrAddSeries.cs" />
<Compile Include="Sonarr\SonarrError.cs" />
<Compile Include="Sonarr\SonarrProfile.cs" /> <Compile Include="Sonarr\SonarrProfile.cs" />
<Compile Include="Sonarr\SystemStatus.cs" /> <Compile Include="Sonarr\SystemStatus.cs" />
<Compile Include="Tv\Authentication.cs" /> <Compile Include="Tv\Authentication.cs" />

@ -1,5 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json;
namespace PlexRequests.Api.Models.Sonarr namespace PlexRequests.Api.Models.Sonarr
{ {
public class Season public class Season
@ -23,6 +25,8 @@ namespace PlexRequests.Api.Models.Sonarr
public string imdbId { get; set; } public string imdbId { get; set; }
public string titleSlug { get; set; } public string titleSlug { get; set; }
public int id { get; set; } public int id { get; set; }
[JsonIgnore]
public string ErrorMessage { get; set; }
} }
public class AddOptions public class AddOptions

@ -0,0 +1,36 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SonarrError.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
namespace PlexRequests.Api.Models.Sonarr
{
public class SonarrError
{
public string propertyName { get; set; }
public string errorMessage { get; set; }
public string attemptedValue { get; set; }
public string[] formattedMessageArguments { get; set; }
}
}

@ -26,13 +26,9 @@
#endregion #endregion
using System; using System;
using System.IO; using System.IO;
using System.Net;
using System.Text;
using System.Xml;
using System.Xml.Serialization; using System.Xml.Serialization;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog; using NLog;
@ -99,17 +95,18 @@ namespace PlexRequests.Api
try try
{ {
var json = JsonConvert.DeserializeObject<T>(response.Content); var json = JsonConvert.DeserializeObject<T>(response.Content);
return json; return json;
} }
catch (Exception e) catch (Exception e)
{ {
Log.Fatal(e); Log.Error(e);
Log.Info(response.Content); Log.Error(response.Content);
throw; throw;
} }
} }
public T DeserializeXml<T>(string input) private T DeserializeXml<T>(string input)
where T : class where T : class
{ {
var ser = new XmlSerializer(typeof(T)); var ser = new XmlSerializer(typeof(T));

@ -30,6 +30,8 @@ using System.Linq;
using NLog; using NLog;
using PlexRequests.Api.Interfaces; using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models.Sonarr; using PlexRequests.Api.Models.Sonarr;
using PlexRequests.Helpers;
using RestSharp; using RestSharp;
namespace PlexRequests.Api namespace PlexRequests.Api
@ -56,7 +58,8 @@ namespace PlexRequests.Api
public SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, int seasonCount, int[] seasons, string apiKey, Uri baseUrl) public SonarrAddSeries AddSeries(int tvdbId, string title, int qualityId, bool seasonFolders, string rootPath, int seasonCount, int[] seasons, string apiKey, Uri baseUrl)
{ {
Log.Debug("Adding series {0}", title);
Log.Debug("Seasons = {0}, out of {1} seasons", seasons.DumpJson(), seasonCount);
var request = new RestRequest var request = new RestRequest
{ {
Resource = "/api/Series?", Resource = "/api/Series?",
@ -74,7 +77,6 @@ namespace PlexRequests.Api
rootFolderPath = rootPath rootFolderPath = rootPath
}; };
for (var i = 1; i <= seasonCount; i++) for (var i = 1; i <= seasonCount; i++)
{ {
var season = new Season var season = new Season
@ -85,11 +87,20 @@ namespace PlexRequests.Api
options.seasons.Add(season); options.seasons.Add(season);
} }
Log.Debug("Sonarr API Options:");
Log.Debug(options.DumpJson());
request.AddHeader("X-Api-Key", apiKey); request.AddHeader("X-Api-Key", apiKey);
request.AddJsonBody(options); request.AddJsonBody(options);
var obj = Api.ExecuteJson<SonarrAddSeries>(request, baseUrl); var obj = Api.ExecuteJson<SonarrAddSeries>(request, baseUrl);
if (obj == null)
{
var error = Api.ExecuteJson<SonarrError>(request, baseUrl);
obj = new SonarrAddSeries { ErrorMessage = error.errorMessage };
}
return obj; return obj;
} }

@ -24,17 +24,13 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/ // ************************************************************************/
#endregion #endregion
using Nancy;
using NLog; using NLog;
using PlexRequests.Api.Interfaces; using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models.SickRage; using PlexRequests.Api.Models.SickRage;
using PlexRequests.Api.Models.Sonarr; using PlexRequests.Api.Models.Sonarr;
using PlexRequests.Core;
using PlexRequests.Core.SettingModels; using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers; using PlexRequests.Helpers;
using PlexRequests.Store; using PlexRequests.Store;
using PlexRequests.UI.Models;
namespace PlexRequests.UI.Helpers namespace PlexRequests.UI.Helpers
{ {

@ -131,7 +131,7 @@ namespace PlexRequests.UI.Modules
return Response.AsJson(new JsonResponseModel return Response.AsJson(new JsonResponseModel
{ {
Result = false, Result = false,
Message = "Could not add the series to Sonarr" Message = result.ErrorMessage ?? "Could not add the series to Sonarr"
}); });
} }
@ -276,7 +276,7 @@ namespace PlexRequests.UI.Modules
if (sonarr.Enabled) if (sonarr.Enabled)
{ {
var result = sender.SendToSonarr(sonarr, r); var result = sender.SendToSonarr(sonarr, r);
if (result != null) if (!string.IsNullOrEmpty(result?.title))
{ {
r.Approved = true; r.Approved = true;
updatedRequests.Add(r); updatedRequests.Add(r);
@ -284,6 +284,7 @@ namespace PlexRequests.UI.Modules
else else
{ {
Log.Error("Could not approve and send the TV {0} to Sonarr!", r.Title); Log.Error("Could not approve and send the TV {0} to Sonarr!", r.Title);
Log.Error("Error message: {0}", result?.ErrorMessage);
} }
} }
} }

@ -371,18 +371,19 @@ namespace PlexRequests.UI.Modules
if (sonarrSettings.Enabled) if (sonarrSettings.Enabled)
{ {
var result = sender.SendToSonarr(sonarrSettings, model); var result = sender.SendToSonarr(sonarrSettings, model);
if (result != null) if (result != null && !string.IsNullOrEmpty(result.title))
{ {
model.Approved = true; model.Approved = true;
Log.Debug("Adding tv to database requests (No approval required & Sonarr)"); Log.Debug("Adding tv to database requests (No approval required & Sonarr)");
RequestService.AddRequest(model); RequestService.AddRequest(model);
var notify1 = new NotificationModel { Title = model.Title, User = model.RequestedBy, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest };
NotificationService.Publish(notify1);
return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullShowName} was successfully added!" }); return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullShowName} was successfully added!" });
} }
var notify1 = new NotificationModel { Title = model.Title, User = model.RequestedBy, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest };
NotificationService.Publish(notify1);
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Something went wrong adding the movie to Sonarr! Please check your settings." });
return Response.AsJson(new JsonResponseModel { Result = false, Message = result?.ErrorMessage ?? "Something went wrong adding the movie to Sonarr! Please check your settings." });
} }

Loading…
Cancel
Save