From d6b3c7ac2ce6f74efa0f770677187e808ffcda36 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Sat, 14 Oct 2017 00:02:08 +0100 Subject: [PATCH] Added support for a new TV and Movie provider. DogNZB --- src/Ombi.Api.DogNzb/DogNzbApi.cs | 84 +++++++++++++++++ src/Ombi.Api.DogNzb/IDogNzbApi.cs | 13 +++ src/Ombi.Api.DogNzb/Models/DogNzbAddResult.cs | 45 +++++++++ src/Ombi.Api.DogNzb/Models/DogNzbError.cs | 41 ++++++++ .../Models/DogNzbMovieAddResult.cs | 55 +++++++++++ src/Ombi.Api.DogNzb/Models/DogNzbMovies.cs | 93 +++++++++++++++++++ src/Ombi.Api.DogNzb/Models/DogNzbTvShows.cs | 84 +++++++++++++++++ src/Ombi.Api.DogNzb/Ombi.Api.DogNzb.csproj | 11 +++ src/Ombi.Core/Engine/MovieRequestEngine.cs | 4 +- src/Ombi.Core/Engine/TvRequestEngine.cs | 13 ++- src/Ombi.Core/Ombi.Core.csproj | 1 + src/Ombi.Core/Senders/IMovieSender.cs | 3 +- src/Ombi.Core/Senders/ITvSender.cs | 6 +- src/Ombi.Core/Senders/MovieSender.cs | 54 ++++++++--- src/Ombi.Core/Senders/MovieSenderResult.cs | 9 -- src/Ombi.Core/Senders/SenderResult.cs | 9 ++ src/Ombi.Core/Senders/TvSender.cs | 60 +++++++++++- src/Ombi.DependencyInjection/IocExtensions.cs | 7 +- .../Ombi.DependencyInjection.csproj | 1 + .../Models/External/DogNzbSettings.cs | 10 ++ src/Ombi.sln | 9 +- .../ClientApp/app/interfaces/ISettings.ts | 7 ++ .../app/services/settings.service.ts | 15 ++- .../app/settings/dognzb/dognzb.component.html | 54 +++++++++++ .../app/settings/dognzb/dognzb.component.ts | 46 +++++++++ .../ClientApp/app/settings/settings.module.ts | 3 + .../app/settings/settingsmenu.component.html | 2 + src/Ombi/Controllers/SettingsController.cs | 21 +++++ 28 files changed, 714 insertions(+), 46 deletions(-) create mode 100644 src/Ombi.Api.DogNzb/DogNzbApi.cs create mode 100644 src/Ombi.Api.DogNzb/IDogNzbApi.cs create mode 100644 src/Ombi.Api.DogNzb/Models/DogNzbAddResult.cs create mode 100644 src/Ombi.Api.DogNzb/Models/DogNzbError.cs create mode 100644 src/Ombi.Api.DogNzb/Models/DogNzbMovieAddResult.cs create mode 100644 src/Ombi.Api.DogNzb/Models/DogNzbMovies.cs create mode 100644 src/Ombi.Api.DogNzb/Models/DogNzbTvShows.cs create mode 100644 src/Ombi.Api.DogNzb/Ombi.Api.DogNzb.csproj delete mode 100644 src/Ombi.Core/Senders/MovieSenderResult.cs create mode 100644 src/Ombi.Core/Senders/SenderResult.cs create mode 100644 src/Ombi.Settings/Settings/Models/External/DogNzbSettings.cs create mode 100644 src/Ombi/ClientApp/app/settings/dognzb/dognzb.component.html create mode 100644 src/Ombi/ClientApp/app/settings/dognzb/dognzb.component.ts diff --git a/src/Ombi.Api.DogNzb/DogNzbApi.cs b/src/Ombi.Api.DogNzb/DogNzbApi.cs new file mode 100644 index 000000000..13ad18539 --- /dev/null +++ b/src/Ombi.Api.DogNzb/DogNzbApi.cs @@ -0,0 +1,84 @@ +using System; +using System.IO; +using System.Net.Http; +using System.Threading.Tasks; +using System.Xml.Serialization; +using Microsoft.Extensions.Logging; +using Ombi.Api.DogNzb.Models; + +namespace Ombi.Api.DogNzb +{ + public class DogNzbApi : IDogNzbApi + { + public DogNzbApi(IApi api, ILogger log) + { + _api = api; + _log = log; + } + + private readonly IApi _api; + private readonly ILogger _log; + private const string BaseUrl = "https://api.dognzb.cr/"; + + public async Task ListMovies(string apiKey) + { + var request = new Request("watchlist", BaseUrl, HttpMethod.Get, ContentType.Xml); + + request.AddQueryString("t", "list"); + request.AddQueryString("imdbid", string.Empty); + request.AddQueryString("apikey", apiKey); + + return await _api.Request(request); + } + + public async Task ListTvShows(string apiKey) + { + var request = new Request("watchlist", BaseUrl, HttpMethod.Get, ContentType.Xml); + + request.AddQueryString("t", "list"); + request.AddQueryString("tvdbid", string.Empty); + request.AddQueryString("apikey", apiKey); + + return await _api.Request(request); + } + + public async Task AddTvShow(string apiKey, string tvdbId) + { + var request = new Request("watchlist", BaseUrl, HttpMethod.Get, ContentType.Xml); + + request.AddQueryString("t", "add"); + request.AddQueryString("tvdbid", tvdbId); + request.AddQueryString("apikey", apiKey); + var result = await _api.RequestContent(request); + try + { + XmlSerializer serializer = new XmlSerializer(typeof(DogNzbAddResult)); + StringReader reader = new StringReader(result); + return (DogNzbAddResult)serializer.Deserialize(reader); + } + catch (Exception e) + { + _log.LogError(e, "Error when adding TV Shows to DogNzb"); + XmlSerializer serializer = new XmlSerializer(typeof(DogNzbError)); + StringReader reader = new StringReader(result); + var error = (DogNzbError)serializer.Deserialize(reader); + + return new DogNzbAddResult + { + Failure = true, + ErrorMessage = error.Description + }; + } + } + + public async Task AddMovie(string apiKey, string imdbid) + { + var request = new Request("watchlist", BaseUrl, HttpMethod.Get, ContentType.Xml); + + request.AddQueryString("t", "add"); + request.AddQueryString("imdbid", imdbid); + request.AddQueryString("apikey", apiKey); + return await _api.Request(request); + } + } +} diff --git a/src/Ombi.Api.DogNzb/IDogNzbApi.cs b/src/Ombi.Api.DogNzb/IDogNzbApi.cs new file mode 100644 index 000000000..2f220cb15 --- /dev/null +++ b/src/Ombi.Api.DogNzb/IDogNzbApi.cs @@ -0,0 +1,13 @@ +using System.Threading.Tasks; +using Ombi.Api.DogNzb.Models; + +namespace Ombi.Api.DogNzb +{ + public interface IDogNzbApi + { + Task AddMovie(string apiKey, string imdbid); + Task AddTvShow(string apiKey, string tvdbId); + Task ListMovies(string apiKey); + Task ListTvShows(string apiKey); + } +} \ No newline at end of file diff --git a/src/Ombi.Api.DogNzb/Models/DogNzbAddResult.cs b/src/Ombi.Api.DogNzb/Models/DogNzbAddResult.cs new file mode 100644 index 000000000..d2b25a350 --- /dev/null +++ b/src/Ombi.Api.DogNzb/Models/DogNzbAddResult.cs @@ -0,0 +1,45 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2017 Jamie Rees +// File: DogNzbAddResult.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 + +using System.Xml.Serialization; + +namespace Ombi.Api.DogNzb.Models +{ + [XmlRoot(ElementName = "uuid")] + public class DogNzbAddResult + { + [XmlAttribute(AttributeName = "code")] + public string Code { get; set; } + [XmlAttribute(AttributeName = "description")] + public string Description { get; set; } + + + // We set the below + public bool Failure { get; set; } + public string ErrorMessage { get; set; } + } +} \ No newline at end of file diff --git a/src/Ombi.Api.DogNzb/Models/DogNzbError.cs b/src/Ombi.Api.DogNzb/Models/DogNzbError.cs new file mode 100644 index 000000000..b880f201f --- /dev/null +++ b/src/Ombi.Api.DogNzb/Models/DogNzbError.cs @@ -0,0 +1,41 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2017 Jamie Rees +// File: DogNzbError.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 + +using System.Xml.Serialization; + +namespace Ombi.Api.DogNzb.Models +{ + + [XmlRoot(ElementName = "error")] + public class DogNzbError + { + [XmlAttribute(AttributeName = "code")] + public string Code { get; set; } + [XmlAttribute(AttributeName = "description")] + public string Description { get; set; } + } +} \ No newline at end of file diff --git a/src/Ombi.Api.DogNzb/Models/DogNzbMovieAddResult.cs b/src/Ombi.Api.DogNzb/Models/DogNzbMovieAddResult.cs new file mode 100644 index 000000000..2b86e2f4b --- /dev/null +++ b/src/Ombi.Api.DogNzb/Models/DogNzbMovieAddResult.cs @@ -0,0 +1,55 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2017 Jamie Rees +// File: DogNzbMovieAddResult.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 + +using System.Xml.Serialization; + +namespace Ombi.Api.DogNzb.Models +{ + [XmlRoot(ElementName = "channel")] + public class MovieAddResultChannel + { + [XmlElement(ElementName = "title")] + public string Title { get; set; } + [XmlElement(ElementName = "link")] + public string Link { get; set; } + [XmlElement(ElementName = "description")] + public string Description { get; set; } + [XmlElement(ElementName = "language")] + public string Language { get; set; } + } + + [XmlRoot(ElementName = "rss")] + public class DogNzbMovieAddResult + { + [XmlElement(ElementName = "channel")] + public MovieAddResultChannel Channel { get; set; } + [XmlAttribute(AttributeName = "version")] + public string Version { get; set; } + [XmlAttribute(AttributeName = "atom", Namespace = "http://www.w3.org/2000/xmlns/")] + public string Atom { get; set; } + } +} \ No newline at end of file diff --git a/src/Ombi.Api.DogNzb/Models/DogNzbMovies.cs b/src/Ombi.Api.DogNzb/Models/DogNzbMovies.cs new file mode 100644 index 000000000..d81a54176 --- /dev/null +++ b/src/Ombi.Api.DogNzb/Models/DogNzbMovies.cs @@ -0,0 +1,93 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2017 Jamie Rees +// File: DogNzbMovies.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 + +using System.Collections.Generic; +using System.Xml.Serialization; + +namespace Ombi.Api.DogNzb.Models +{ + + [XmlRoot(ElementName = "response", Namespace = "http://www.newznab.com/DTD/2010/feeds/attributes/")] + public class Response + { + [XmlAttribute(AttributeName = "total")] + public string Total { get; set; } + } + + [XmlRoot(ElementName = "item")] + public class Item + { + [XmlElement(ElementName = "title")] + public string Title { get; set; } + [XmlElement(ElementName = "imdbid")] + public string Imdbid { get; set; } + [XmlElement(ElementName = "plot")] + public string Plot { get; set; } + [XmlElement(ElementName = "actors")] + public string Actors { get; set; } + [XmlElement(ElementName = "genres")] + public string Genres { get; set; } + [XmlElement(ElementName = "year")] + public string Year { get; set; } + [XmlElement(ElementName = "runtime")] + public string Runtime { get; set; } + [XmlElement(ElementName = "certification")] + public string Certification { get; set; } + [XmlElement(ElementName = "trailer")] + public string Trailer { get; set; } + [XmlElement(ElementName = "poster")] + public string Poster { get; set; } + } + + [XmlRoot(ElementName = "channel")] + public class Channel + { + [XmlElement(ElementName = "title")] + public string Title { get; set; } + [XmlElement(ElementName = "description")] + public string Description { get; set; } + [XmlElement(ElementName = "uuid")] + public string Uuid { get; set; } + [XmlElement(ElementName = "response", Namespace = "http://www.newznab.com/DTD/2010/feeds/attributes/")] + public Response Response { get; set; } + [XmlElement(ElementName = "item")] + public List Item { get; set; } + } + + [XmlRoot(ElementName = "rss")] + public class DogNzbMovies + { + [XmlElement(ElementName = "channel")] + public Channel Channel { get; set; } + [XmlAttribute(AttributeName = "version")] + public string Version { get; set; } + [XmlAttribute(AttributeName = "atom", Namespace = "http://www.w3.org/2000/xmlns/")] + public string Atom { get; set; } + [XmlAttribute(AttributeName = "newznab", Namespace = "http://www.w3.org/2000/xmlns/")] + public string Newznab { get; set; } + } +} \ No newline at end of file diff --git a/src/Ombi.Api.DogNzb/Models/DogNzbTvShows.cs b/src/Ombi.Api.DogNzb/Models/DogNzbTvShows.cs new file mode 100644 index 000000000..94b2501f5 --- /dev/null +++ b/src/Ombi.Api.DogNzb/Models/DogNzbTvShows.cs @@ -0,0 +1,84 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2017 Jamie Rees +// File: DogNzbTvShows.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 + +using System.Xml.Serialization; + +namespace Ombi.Api.DogNzb.Models +{ + + + [XmlRoot(ElementName = "item")] + public class TvItem + { + [XmlElement(ElementName = "title")] + public string Title { get; set; } + [XmlElement(ElementName = "tvdbid")] + public string Tvdbid { get; set; } + [XmlElement(ElementName = "plot")] + public string Plot { get; set; } + [XmlElement(ElementName = "actors")] + public string Actors { get; set; } + [XmlElement(ElementName = "genres")] + public string Genres { get; set; } + [XmlElement(ElementName = "network")] + public string Network { get; set; } + [XmlElement(ElementName = "status")] + public string Status { get; set; } + [XmlElement(ElementName = "trailer")] + public string Trailer { get; set; } + [XmlElement(ElementName = "poster")] + public string Poster { get; set; } + } + + [XmlRoot(ElementName = "channel")] + public class TvChannel + { + [XmlElement(ElementName = "title")] + public string Title { get; set; } + [XmlElement(ElementName = "description")] + public string Description { get; set; } + [XmlElement(ElementName = "uuid")] + public string Uuid { get; set; } + [XmlElement(ElementName = "response", Namespace = "http://www.newznab.com/DTD/2010/feeds/attributes/")] + public Response Response { get; set; } + [XmlElement(ElementName = "item")] + public TvItem Item { get; set; } + } + + [XmlRoot(ElementName = "rss")] + public class DogNzbTvShows + { + [XmlElement(ElementName = "channel")] + public TvChannel Channel { get; set; } + [XmlAttribute(AttributeName = "version")] + public string Version { get; set; } + [XmlAttribute(AttributeName = "atom", Namespace = "http://www.w3.org/2000/xmlns/")] + public string Atom { get; set; } + [XmlAttribute(AttributeName = "newznab", Namespace = "http://www.w3.org/2000/xmlns/")] + public string Newznab { get; set; } + } +} \ No newline at end of file diff --git a/src/Ombi.Api.DogNzb/Ombi.Api.DogNzb.csproj b/src/Ombi.Api.DogNzb/Ombi.Api.DogNzb.csproj new file mode 100644 index 000000000..a3651df3c --- /dev/null +++ b/src/Ombi.Api.DogNzb/Ombi.Api.DogNzb.csproj @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git a/src/Ombi.Core/Engine/MovieRequestEngine.cs b/src/Ombi.Core/Engine/MovieRequestEngine.cs index 8f849acc3..350f11155 100644 --- a/src/Ombi.Core/Engine/MovieRequestEngine.cs +++ b/src/Ombi.Core/Engine/MovieRequestEngine.cs @@ -87,7 +87,7 @@ namespace Ombi.Core.Engine if (requestModel.Approved) // The rules have auto approved this { var result = await Sender.Send(requestModel); - if (result.Success && result.MovieSent) + if (result.Success && result.Sent) { return await AddMovieRequest(requestModel, fullMovieName); } @@ -153,7 +153,7 @@ namespace Ombi.Core.Engine if (request.Approved) { var result = await Sender.Send(request); - if (result.Success && result.MovieSent) + if (result.Success && result.Sent) { return new RequestEngineResult { diff --git a/src/Ombi.Core/Engine/TvRequestEngine.cs b/src/Ombi.Core/Engine/TvRequestEngine.cs index cd5fc7f18..2dca57cea 100644 --- a/src/Ombi.Core/Engine/TvRequestEngine.cs +++ b/src/Ombi.Core/Engine/TvRequestEngine.cs @@ -16,6 +16,7 @@ using Ombi.Core.Engine.Interfaces; using Ombi.Core.Helpers; using Ombi.Core.Rule; using Ombi.Core.Rule.Interfaces; +using Ombi.Core.Senders; using Ombi.Store.Entities.Requests; using Ombi.Store.Repository; @@ -188,7 +189,7 @@ namespace Ombi.Core.Engine { await Audit.Record(AuditType.Approved, AuditArea.TvRequest, $"Approved Request {request.Title}", Username); // Autosend - await TvSender.SendToSonarr(request); + await TvSender.Send(request); } return new RequestEngineResult { @@ -292,7 +293,15 @@ namespace Ombi.Core.Engine if (model.Approved) { // Autosend - await TvSender.SendToSonarr(model); + var result = await TvSender.Send(model); + if (result.Success) + { + return new RequestEngineResult { RequestAdded = true }; + } + return new RequestEngineResult + { + ErrorMessage = result.Message + }; } return new RequestEngineResult { RequestAdded = true }; diff --git a/src/Ombi.Core/Ombi.Core.csproj b/src/Ombi.Core/Ombi.Core.csproj index 58024b76d..741c727d9 100644 --- a/src/Ombi.Core/Ombi.Core.csproj +++ b/src/Ombi.Core/Ombi.Core.csproj @@ -21,6 +21,7 @@ + diff --git a/src/Ombi.Core/Senders/IMovieSender.cs b/src/Ombi.Core/Senders/IMovieSender.cs index 28e29cab0..cf8ddf33b 100644 --- a/src/Ombi.Core/Senders/IMovieSender.cs +++ b/src/Ombi.Core/Senders/IMovieSender.cs @@ -1,10 +1,11 @@ using System.Threading.Tasks; +using Ombi.Core.Senders; using Ombi.Store.Entities.Requests; namespace Ombi.Core { public interface IMovieSender { - Task Send(MovieRequests model); + Task Send(MovieRequests model); } } \ No newline at end of file diff --git a/src/Ombi.Core/Senders/ITvSender.cs b/src/Ombi.Core/Senders/ITvSender.cs index bff588fd5..9a28be38d 100644 --- a/src/Ombi.Core/Senders/ITvSender.cs +++ b/src/Ombi.Core/Senders/ITvSender.cs @@ -1,12 +1,10 @@ using System.Threading.Tasks; -using Ombi.Api.Sonarr.Models; -using Ombi.Core.Settings.Models.External; using Ombi.Store.Entities.Requests; -namespace Ombi.Core +namespace Ombi.Core.Senders { public interface ITvSender { - Task SendToSonarr(ChildRequests model, string qualityId = null); + Task Send(ChildRequests model); } } \ No newline at end of file diff --git a/src/Ombi.Core/Senders/MovieSender.cs b/src/Ombi.Core/Senders/MovieSender.cs index bb5738978..f0c9b3f0c 100644 --- a/src/Ombi.Core/Senders/MovieSender.cs +++ b/src/Ombi.Core/Senders/MovieSender.cs @@ -1,32 +1,54 @@ using System.Linq; -using Ombi.Core.Settings; -using Ombi.Settings.Settings.Models.External; using System.Threading.Tasks; using Microsoft.Extensions.Logging; +using Ombi.Api.DogNzb.Models; using Ombi.Api.Radarr; +using Ombi.Core.Settings; using Ombi.Helpers; +using Ombi.Settings.Settings.Models.External; using Ombi.Store.Entities.Requests; +using Ombi.Api.DogNzb; -namespace Ombi.Core +namespace Ombi.Core.Senders { public class MovieSender : IMovieSender { - public MovieSender(ISettingsService radarrSettings, IRadarrApi api, ILogger log) + public MovieSender(ISettingsService radarrSettings, IRadarrApi api, ILogger log, + ISettingsService dogSettings, IDogNzbApi dogApi) { RadarrSettings = radarrSettings; RadarrApi = api; Log = log; + DogNzbSettings = dogSettings; + DogNzbApi = dogApi; } private ISettingsService RadarrSettings { get; } private IRadarrApi RadarrApi { get; } private ILogger Log { get; } + private IDogNzbApi DogNzbApi { get; } + private ISettingsService DogNzbSettings { get; } - public async Task Send(MovieRequests model) + public async Task Send(MovieRequests model) { //var cpSettings = await CouchPotatoSettings.GetSettingsAsync(); //var watcherSettings = await WatcherSettings.GetSettingsAsync(); var radarrSettings = await RadarrSettings.GetSettingsAsync(); + if (radarrSettings.Enabled) + { + return await SendToRadarr(model, radarrSettings); + } + + var dogSettings = await DogNzbSettings.GetSettingsAsync(); + if (dogSettings.Enabled) + { + await SendToDogNzb(model,dogSettings); + return new SenderResult + { + Success = true, + Sent = true, + }; + } //if (cpSettings.Enabled) //{ @@ -38,19 +60,21 @@ namespace Ombi.Core // return SendToWatcher(model, watcherSettings); //} - if (radarrSettings.Enabled) - { - return await SendToRadarr(model, radarrSettings); - } - return new MovieSenderResult + return new SenderResult { Success = true, - MovieSent = false, + Sent = false, }; } - private async Task SendToRadarr(MovieRequests model, RadarrSettings settings) + private async Task SendToDogNzb(FullBaseRequest model, DogNzbSettings settings) + { + var id = model.ImdbId; + return await DogNzbApi.AddMovie(settings.ApiKey, id); + } + + private async Task SendToRadarr(MovieRequests model, RadarrSettings settings) { var qualityToUse = int.Parse(settings.DefaultQualityProfile); if (model.QualityOverride > 0) @@ -64,13 +88,13 @@ namespace Ombi.Core if (!string.IsNullOrEmpty(result.Error?.message)) { Log.LogError(LoggingEvents.RadarrCacher,result.Error.message); - return new MovieSenderResult { Success = false, Message = result.Error.message, MovieSent = false }; + return new SenderResult { Success = false, Message = result.Error.message, Sent = false }; } if (!string.IsNullOrEmpty(result.title)) { - return new MovieSenderResult { Success = true, MovieSent = false }; + return new SenderResult { Success = true, Sent = false }; } - return new MovieSenderResult { Success = true, MovieSent = false }; + return new SenderResult { Success = true, Sent = false }; } private async Task RadarrRootPath(int overrideId, RadarrSettings settings) diff --git a/src/Ombi.Core/Senders/MovieSenderResult.cs b/src/Ombi.Core/Senders/MovieSenderResult.cs deleted file mode 100644 index 83de6a2db..000000000 --- a/src/Ombi.Core/Senders/MovieSenderResult.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Ombi.Core -{ - public class MovieSenderResult - { - public bool Success { get; set; } - public string Message { get; set; } - public bool MovieSent { get; set; } - } -} \ No newline at end of file diff --git a/src/Ombi.Core/Senders/SenderResult.cs b/src/Ombi.Core/Senders/SenderResult.cs new file mode 100644 index 000000000..26a0d6e08 --- /dev/null +++ b/src/Ombi.Core/Senders/SenderResult.cs @@ -0,0 +1,9 @@ +namespace Ombi.Core.Senders +{ + public class SenderResult + { + public bool Success { get; set; } + public string Message { get; set; } + public bool Sent { get; set; } + } +} \ No newline at end of file diff --git a/src/Ombi.Core/Senders/TvSender.cs b/src/Ombi.Core/Senders/TvSender.cs index 267bc3a3f..45f960a36 100644 --- a/src/Ombi.Core/Senders/TvSender.cs +++ b/src/Ombi.Core/Senders/TvSender.cs @@ -3,10 +3,11 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.Extensions.Logging; +using Ombi.Api.DogNzb; +using Ombi.Api.DogNzb.Models; using Ombi.Api.Sonarr; using Ombi.Api.Sonarr.Models; using Ombi.Core.Settings; -using Ombi.Core.Settings.Models.External; using Ombi.Helpers; using Ombi.Settings.Settings.Models.External; using Ombi.Store.Entities.Requests; @@ -15,16 +16,65 @@ namespace Ombi.Core.Senders { public class TvSender : ITvSender { - public TvSender(ISonarrApi sonarrApi, ILogger log, ISettingsService settings) + public TvSender(ISonarrApi sonarrApi, ILogger log, ISettingsService sonarrSettings, + ISettingsService dog, IDogNzbApi dogApi) { SonarrApi = sonarrApi; Logger = log; - Settings = settings; + SonarrSettings = sonarrSettings; + DogNzbSettings = dog; + DogNzbApi = dogApi; } private ISonarrApi SonarrApi { get; } + private IDogNzbApi DogNzbApi { get; } private ILogger Logger { get; } - private ISettingsService Settings { get; } + private ISettingsService SonarrSettings { get; } + private ISettingsService DogNzbSettings { get; } + + public async Task 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 + }; + } + return new SenderResult + { + Success = true + }; + } + + private async Task SendToDogNzb(ChildRequests model, DogNzbSettings settings) + { + var id = model.ParentRequest.TvDbId; + return await DogNzbApi.AddTvShow(settings.ApiKey, id.ToString()); + } /// /// Send the request to Sonarr to process @@ -35,7 +85,7 @@ namespace Ombi.Core.Senders /// public async Task SendToSonarr(ChildRequests model, string qualityId = null) { - var s = await Settings.GetSettingsAsync(); + var s = await SonarrSettings.GetSettingsAsync(); if (!s.Enabled) { return null; diff --git a/src/Ombi.DependencyInjection/IocExtensions.cs b/src/Ombi.DependencyInjection/IocExtensions.cs index 02eae541b..b4b54d4dd 100644 --- a/src/Ombi.DependencyInjection/IocExtensions.cs +++ b/src/Ombi.DependencyInjection/IocExtensions.cs @@ -1,12 +1,7 @@ using System.Diagnostics.CodeAnalysis; -using System.IO; using System.Security.Principal; using Hangfire; -using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.Extensions.DependencyInjection; using Ombi.Api.Discord; @@ -34,6 +29,7 @@ using Ombi.Notifications.Agents; using Ombi.Schedule.Jobs.Radarr; using Ombi.Api; using Ombi.Api.CouchPotato; +using Ombi.Api.DogNzb; using Ombi.Api.FanartTv; using Ombi.Api.Mattermost; using Ombi.Api.Pushbullet; @@ -99,6 +95,7 @@ namespace Ombi.DependencyInjection services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } public static void RegisterStore(this IServiceCollection services) { diff --git a/src/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj b/src/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj index 8dc69d646..2bdd6caf8 100644 --- a/src/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj +++ b/src/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj @@ -17,6 +17,7 @@ + diff --git a/src/Ombi.Settings/Settings/Models/External/DogNzbSettings.cs b/src/Ombi.Settings/Settings/Models/External/DogNzbSettings.cs new file mode 100644 index 000000000..3d4c0f043 --- /dev/null +++ b/src/Ombi.Settings/Settings/Models/External/DogNzbSettings.cs @@ -0,0 +1,10 @@ +namespace Ombi.Settings.Settings.Models.External +{ + public class DogNzbSettings : Settings + { + public bool Enabled { get; set; } + public string ApiKey { get; set; } + public bool Movies { get; set; } + public bool TvShows { get; set; } + } +} \ No newline at end of file diff --git a/src/Ombi.sln b/src/Ombi.sln index da9d4aac9..984494cea 100644 --- a/src/Ombi.sln +++ b/src/Ombi.sln @@ -80,7 +80,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi.Api.Pushover", "Ombi.A EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi.Schedule.Tests", "Ombi.Schedule.Tests\Ombi.Schedule.Tests.csproj", "{BDD8B924-016E-4CDA-9FFA-50B0A34BCD3C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ombi.Api.CouchPotato", "Ombi.Api.CouchPotato\Ombi.Api.CouchPotato.csproj", "{87D7897D-7C73-4856-A0AA-FF5948F4EA86}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi.Api.CouchPotato", "Ombi.Api.CouchPotato\Ombi.Api.CouchPotato.csproj", "{87D7897D-7C73-4856-A0AA-FF5948F4EA86}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ombi.Api.DogNzb", "Ombi.Api.DogNzb\Ombi.Api.DogNzb.csproj", "{4F3BF03A-6AAC-4960-A2CD-1EAD7273115E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -208,6 +210,10 @@ Global {87D7897D-7C73-4856-A0AA-FF5948F4EA86}.Debug|Any CPU.Build.0 = Debug|Any CPU {87D7897D-7C73-4856-A0AA-FF5948F4EA86}.Release|Any CPU.ActiveCfg = Release|Any CPU {87D7897D-7C73-4856-A0AA-FF5948F4EA86}.Release|Any CPU.Build.0 = Release|Any CPU + {4F3BF03A-6AAC-4960-A2CD-1EAD7273115E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F3BF03A-6AAC-4960-A2CD-1EAD7273115E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F3BF03A-6AAC-4960-A2CD-1EAD7273115E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F3BF03A-6AAC-4960-A2CD-1EAD7273115E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -237,6 +243,7 @@ Global {CA55DD4F-4EFF-4906-A848-35FCC7BD5654} = {9293CA11-360A-4C20-A674-B9E794431BF5} {BDD8B924-016E-4CDA-9FFA-50B0A34BCD3C} = {6F42AB98-9196-44C4-B888-D5E409F415A1} {87D7897D-7C73-4856-A0AA-FF5948F4EA86} = {9293CA11-360A-4C20-A674-B9E794431BF5} + {4F3BF03A-6AAC-4960-A2CD-1EAD7273115E} = {9293CA11-360A-4C20-A674-B9E794431BF5} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {192E9BF8-00B4-45E4-BCCC-4C215725C869} diff --git a/src/Ombi/ClientApp/app/interfaces/ISettings.ts b/src/Ombi/ClientApp/app/interfaces/ISettings.ts index 678eb57df..c65c93995 100644 --- a/src/Ombi/ClientApp/app/interfaces/ISettings.ts +++ b/src/Ombi/ClientApp/app/interfaces/ISettings.ts @@ -127,3 +127,10 @@ export interface ICouchPotatoSettings extends IExternalSettings { username: string; password: string; } + +export interface IDogNzbSettings extends ISettings { + enabled: boolean; + apiKey: string; + movies: boolean; + tvShows: boolean; +} diff --git a/src/Ombi/ClientApp/app/services/settings.service.ts b/src/Ombi/ClientApp/app/services/settings.service.ts index 57eb0c405..454ac7f48 100644 --- a/src/Ombi/ClientApp/app/services/settings.service.ts +++ b/src/Ombi/ClientApp/app/services/settings.service.ts @@ -10,6 +10,7 @@ import { ICouchPotatoSettings, ICustomizationSettings, IDiscordNotifcationSettings, + IDogNzbSettings, IEmailNotificationSettings, IEmbySettings, ILandingPageSettings, @@ -198,12 +199,22 @@ export class SettingsService extends ServiceAuthHelpers { } public getCouchPotatoSettings(): Observable { - return this.httpAuth.get(`${this.url}/UserManagement`).map(this.extractData).catch(this.handleError); + return this.httpAuth.get(`${this.url}/CouchPotato`).map(this.extractData).catch(this.handleError); } public saveCouchPotatoSettings(settings: ICouchPotatoSettings): Observable { return this.httpAuth - .post(`${this.url}/UserManagement`, JSON.stringify(settings), { headers: this.headers }) + .post(`${this.url}/CouchPotato`, JSON.stringify(settings), { headers: this.headers }) + .map(this.extractData).catch(this.handleError); + } + + public getDogNzbSettings(): Observable { + return this.httpAuth.get(`${this.url}/DogNzb`).map(this.extractData).catch(this.handleError); + } + + public saveDogNzbSettings(settings: IDogNzbSettings): Observable { + return this.httpAuth + .post(`${this.url}/DogNzb`, JSON.stringify(settings), { headers: this.headers }) .map(this.extractData).catch(this.handleError); } } diff --git a/src/Ombi/ClientApp/app/settings/dognzb/dognzb.component.html b/src/Ombi/ClientApp/app/settings/dognzb/dognzb.component.html new file mode 100644 index 000000000..827f1ac2d --- /dev/null +++ b/src/Ombi/ClientApp/app/settings/dognzb/dognzb.component.html @@ -0,0 +1,54 @@ + + + + +
+
+ DogNzb Settings +
+
+
+
+ + +
+
+ + + +
+ + + + + The API Key is required +
+ + + + +
+
+ +
+
+
+
+
+
+ + +
+
+ +
+
+ + +
+
+ +
+
+
+
\ No newline at end of file diff --git a/src/Ombi/ClientApp/app/settings/dognzb/dognzb.component.ts b/src/Ombi/ClientApp/app/settings/dognzb/dognzb.component.ts new file mode 100644 index 000000000..68cbcf16f --- /dev/null +++ b/src/Ombi/ClientApp/app/settings/dognzb/dognzb.component.ts @@ -0,0 +1,46 @@ +import { Component, OnInit } from "@angular/core"; +import { FormBuilder, FormGroup, Validators } from "@angular/forms"; + +import { NotificationService, SettingsService } from "../../services"; + +@Component({ + templateUrl: "./dognzb.component.html", +}) +export class DogNzbComponent implements OnInit { + + public form: FormGroup; + + public profilesRunning: boolean; + + constructor(private readonly settingsService: SettingsService, + private readonly fb: FormBuilder, + private readonly notificationService: NotificationService) { } + + public ngOnInit() { + this.settingsService.getDogNzbSettings().subscribe(x => { + this.form = this.fb.group({ + enabled: [x.enabled], + apiKey: [x.apiKey, Validators.required], + movies: [x.movies], + tvShows: [x.tvShows], + }); + }); + } + + public onSubmit(form: FormGroup) { + if (form.invalid) { + this.notificationService.error("Validation", "Please check your entered values"); + return; + } + + const settings = form.value; + + this.settingsService.saveDogNzbSettings(settings).subscribe(x => { + if (x) { + this.notificationService.success("Settings Saved", "Successfully saved the DogNzb settings"); + } else { + this.notificationService.success("Settings Saved", "There was an error when saving the DogNzb settings"); + } + }); + } +} diff --git a/src/Ombi/ClientApp/app/settings/settings.module.ts b/src/Ombi/ClientApp/app/settings/settings.module.ts index 938a2a7e0..a89fc44ce 100644 --- a/src/Ombi/ClientApp/app/settings/settings.module.ts +++ b/src/Ombi/ClientApp/app/settings/settings.module.ts @@ -14,6 +14,7 @@ import { PipeModule } from "../pipes/pipe.module"; import { AboutComponent } from "./about/about.component"; import { CouchPotatoComponent } from "./couchpotato/couchpotato.component"; import { CustomizationComponent } from "./customization/customization.component"; +import { DogNzbComponent } from "./dognzb/dognzb.component"; import { EmbyComponent } from "./emby/emby.component"; import { LandingPageComponent } from "./landingpage/landingpage.component"; import { DiscordComponent } from "./notifications/discord.component"; @@ -53,6 +54,7 @@ const routes: Routes = [ { path: "Settings/UserManagement", component: UserManagementComponent, canActivate: [AuthGuard] }, { path: "Settings/Update", component: UpdateComponent, canActivate: [AuthGuard] }, { path: "Settings/CouchPotato", component: CouchPotatoComponent, canActivate: [AuthGuard] }, + { path: "Settings/DogNzb", component: DogNzbComponent, canActivate: [AuthGuard] }, ]; @NgModule({ @@ -94,6 +96,7 @@ const routes: Routes = [ AboutComponent, WikiComponent, CouchPotatoComponent, + DogNzbComponent, ], exports: [ RouterModule, diff --git a/src/Ombi/ClientApp/app/settings/settingsmenu.component.html b/src/Ombi/ClientApp/app/settings/settingsmenu.component.html index 2237891ba..2084d1f12 100644 --- a/src/Ombi/ClientApp/app/settings/settingsmenu.component.html +++ b/src/Ombi/ClientApp/app/settings/settingsmenu.component.html @@ -29,6 +29,7 @@ @@ -40,6 +41,7 @@