diff --git a/PlexRequests.Api.Interfaces/ICouchPotatoApi.cs b/PlexRequests.Api.Interfaces/ICouchPotatoApi.cs index bcfdb3dfd..288f09d67 100644 --- a/PlexRequests.Api.Interfaces/ICouchPotatoApi.cs +++ b/PlexRequests.Api.Interfaces/ICouchPotatoApi.cs @@ -33,7 +33,8 @@ namespace PlexRequests.Api.Interfaces { public interface ICouchPotatoApi { - bool AddMovie(string imdbid, string apiKey, string title, Uri baseUrl); + bool AddMovie(string imdbid, string apiKey, string title, Uri baseUrl, string profileID = default(string)); CouchPotatoStatus GetStatus(Uri url, string apiKey); + CouchPotatoProfiles GetProfiles(Uri url, string apiKey); } } \ No newline at end of file diff --git a/PlexRequests.Api.Interfaces/ISickRageApi.cs b/PlexRequests.Api.Interfaces/ISickRageApi.cs new file mode 100644 index 000000000..516b8784f --- /dev/null +++ b/PlexRequests.Api.Interfaces/ISickRageApi.cs @@ -0,0 +1,40 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: ISickRageApi.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; +using PlexRequests.Api.Models.SickRage; + +namespace PlexRequests.Api.Interfaces +{ + public interface ISickRageApi + { + SickRageTvAdd AddSeries(int tvdbId, bool latest, string quality, string apiKey, + Uri baseUrl); + + SickRagePing Ping(string apiKey, Uri baseUrl); + } +} \ No newline at end of file diff --git a/PlexRequests.Api.Interfaces/PlexRequests.Api.Interfaces.csproj b/PlexRequests.Api.Interfaces/PlexRequests.Api.Interfaces.csproj index b76996490..3ea7be621 100644 --- a/PlexRequests.Api.Interfaces/PlexRequests.Api.Interfaces.csproj +++ b/PlexRequests.Api.Interfaces/PlexRequests.Api.Interfaces.csproj @@ -49,6 +49,7 @@ + diff --git a/PlexRequests.Api.Models/Movie/CouchPotatoProfiles.cs b/PlexRequests.Api.Models/Movie/CouchPotatoProfiles.cs new file mode 100644 index 000000000..f63661ecb --- /dev/null +++ b/PlexRequests.Api.Models/Movie/CouchPotatoProfiles.cs @@ -0,0 +1,53 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: CouchPotatoProfiles.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; + +namespace PlexRequests.Api.Models.Movie +{ + public class ProfileList + { + public bool core { get; set; } + public string _rev { get; set; } + public List finish { get; set; } + public List qualities { get; set; } + public string _id { get; set; } + public string _t { get; set; } + public string label { get; set; } + public int minimum_score { get; set; } + public List stop_after { get; set; } + public List wait_for { get; set; } + public int order { get; set; } + public List __invalid_name__3d { get; set; } + } + + public class CouchPotatoProfiles + { + public List list { get; set; } + public bool success { get; set; } + } +} \ No newline at end of file diff --git a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj index 8a4d30e62..bd3151c55 100644 --- a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj +++ b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj @@ -46,6 +46,7 @@ + @@ -57,6 +58,9 @@ + + + diff --git a/PlexRequests.Api.Models/SickRage/SickRagePing.cs b/PlexRequests.Api.Models/SickRage/SickRagePing.cs new file mode 100644 index 000000000..e3a7528da --- /dev/null +++ b/PlexRequests.Api.Models/SickRage/SickRagePing.cs @@ -0,0 +1,40 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: SickRagePing.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.SickRage +{ + public class SickRagePingData + { + public int pid { get; set; } + } + + public class SickRagePing + { + public SickRagePingData data { get; set; } + public string message { get; set; } + public string result { get; set; } + } +} \ No newline at end of file diff --git a/PlexRequests.Api.Models/SickRage/SickRageStatus.cs b/PlexRequests.Api.Models/SickRage/SickRageStatus.cs new file mode 100644 index 000000000..2ea03632d --- /dev/null +++ b/PlexRequests.Api.Models/SickRage/SickRageStatus.cs @@ -0,0 +1,35 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: SickRageStatus.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.SickRage +{ + public static class SickRageStatus + { + public const string Wanted = "wanted"; + public const string Skipped = "skipped"; + public const string Ignored = "Ignored"; + } +} \ No newline at end of file diff --git a/PlexRequests.Api.Models/SickRage/SickRageTvAdd.cs b/PlexRequests.Api.Models/SickRage/SickRageTvAdd.cs new file mode 100644 index 000000000..0fb021163 --- /dev/null +++ b/PlexRequests.Api.Models/SickRage/SickRageTvAdd.cs @@ -0,0 +1,41 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: SickRageTvAdd.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.SickRage +{ + public class SickRageTvAddData + { + public string name { get; set; } + } + + public class SickRageTvAdd + { + public SickRageTvAddData data { get; set; } + public string message { get; set; } + public string result { get; set; } + } + +} \ No newline at end of file diff --git a/PlexRequests.Api/CouchPotatoApi.cs b/PlexRequests.Api/CouchPotatoApi.cs index bdb238ee2..7e660a38d 100644 --- a/PlexRequests.Api/CouchPotatoApi.cs +++ b/PlexRequests.Api/CouchPotatoApi.cs @@ -45,9 +45,17 @@ namespace PlexRequests.Api private ApiRequest Api { get; set; } private static Logger Log = LogManager.GetCurrentClassLogger(); - public bool AddMovie(string imdbid, string apiKey, string title, Uri baseUrl) + public bool AddMovie(string imdbid, string apiKey, string title, Uri baseUrl, string profileId = default(string)) { - var request = new RestRequest { Resource = "/api/{apikey}/movie.add?title={title}&identifier={imdbid}" }; + RestRequest request; + request = string.IsNullOrEmpty(profileId) + ? new RestRequest {Resource = "/api/{apikey}/movie.add?title={title}&identifier={imdbid}"} + : new RestRequest { Resource = "/api/{apikey}/movie.add?title={title}&identifier={imdbid}&profile_id={profileId}" }; + + if (!string.IsNullOrEmpty(profileId)) + { + request.AddUrlSegment("profileId", profileId); + } request.AddUrlSegment("apikey", apiKey); request.AddUrlSegment("imdbid", imdbid); @@ -93,5 +101,19 @@ namespace PlexRequests.Api return Api.Execute(request,url); } + + public CouchPotatoProfiles GetProfiles(Uri url, string apiKey) + { + Log.Trace("Getting CP Profiles, ApiKey = {0}", apiKey); + var request = new RestRequest + { + Resource = "api/{apikey}/profile.list/", + Method = Method.GET + }; + + request.AddUrlSegment("apikey", apiKey); + + return Api.Execute(request, url); + } } } \ No newline at end of file diff --git a/PlexRequests.Api/PlexRequests.Api.csproj b/PlexRequests.Api/PlexRequests.Api.csproj index 5157e905c..2f204c975 100644 --- a/PlexRequests.Api/PlexRequests.Api.csproj +++ b/PlexRequests.Api/PlexRequests.Api.csproj @@ -73,6 +73,7 @@ + diff --git a/PlexRequests.Api/SickrageApi.cs b/PlexRequests.Api/SickrageApi.cs new file mode 100644 index 000000000..f81693f5d --- /dev/null +++ b/PlexRequests.Api/SickrageApi.cs @@ -0,0 +1,91 @@ +#region Copyright + +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: CouchPotatoApi.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; +using NLog; +using PlexRequests.Api.Interfaces; +using PlexRequests.Api.Models.SickRage; +using RestSharp; + +namespace PlexRequests.Api +{ + public class SickrageApi : ISickRageApi + { + private static Logger Log = LogManager.GetCurrentClassLogger(); + + public SickrageApi() + { + Api = new ApiRequest(); + } + + private ApiRequest Api { get; } + + + public SickRageTvAdd AddSeries(int tvdbId, bool latest, string quality, string apiKey, + Uri baseUrl) + { + string status; + var futureStatus = SickRageStatus.Wanted; + + status = latest ? SickRageStatus.Skipped : SickRageStatus.Wanted; + + var request = new RestRequest + { + Resource = "/api/{apiKey}/?cmd=show.addnew", + Method = Method.GET + }; + request.AddUrlSegment("apiKey", apiKey); + request.AddQueryParameter("tvdbid", tvdbId.ToString()); + request.AddQueryParameter("status", status); + request.AddQueryParameter("future_status", futureStatus); + if (!quality.Equals("default", StringComparison.CurrentCultureIgnoreCase)) + { + request.AddQueryParameter("initial", quality); + } + + var obj = Api.Execute(request, baseUrl); + + return obj; + } + + public SickRagePing Ping(string apiKey, Uri baseUrl) + { + var request = new RestRequest + { + Resource = "/api/{apiKey}/?cmd=sb.ping", + Method = Method.GET + }; + + request.AddUrlSegment("apiKey", apiKey); + var obj = Api.ExecuteJson(request, baseUrl); + + return obj; + } + } +} \ No newline at end of file diff --git a/PlexRequests.Api/TvMazeApi.cs b/PlexRequests.Api/TvMazeApi.cs index 5f74ea7f2..8b6cb9f37 100644 --- a/PlexRequests.Api/TvMazeApi.cs +++ b/PlexRequests.Api/TvMazeApi.cs @@ -69,5 +69,18 @@ namespace PlexRequests.Api return Api.Execute(request, new Uri(Uri)); } + public TvMazeShow ShowLookupByTheTvDbId(int theTvDbId) + { + var request = new RestRequest + { + Method = Method.GET, + Resource = "lookup/shows?thetvdb={id}" + }; + request.AddUrlSegment("id", theTvDbId.ToString()); + request.AddHeader("Content-Type", "application/json"); + + return Api.Execute(request, new Uri(Uri)); + } + } } \ No newline at end of file diff --git a/PlexRequests.Core/PlexRequests.Core.csproj b/PlexRequests.Core/PlexRequests.Core.csproj index b7534d1b0..e1c4ee1f3 100644 --- a/PlexRequests.Core/PlexRequests.Core.csproj +++ b/PlexRequests.Core/PlexRequests.Core.csproj @@ -94,6 +94,10 @@ + + {CB37A5F8-6DFC-4554-99D3-A42B502E4591} + PlexRequests.Api.Models + {8CB8D235-2674-442D-9C6A-35FCAEEB160D} PlexRequests.Api diff --git a/PlexRequests.Core/SettingModels/CouchPotatoSettings.cs b/PlexRequests.Core/SettingModels/CouchPotatoSettings.cs index 0c4ccd06f..ff7ea01a5 100644 --- a/PlexRequests.Core/SettingModels/CouchPotatoSettings.cs +++ b/PlexRequests.Core/SettingModels/CouchPotatoSettings.cs @@ -37,12 +37,19 @@ namespace PlexRequests.Core.SettingModels public int Port { get; set; } public string ApiKey { get; set; } public bool Ssl { get; set; } + public string ProfileId { get; set; } + public string SubDir { get; set; } [JsonIgnore] public Uri FullUri { get { + if (!string.IsNullOrEmpty(SubDir)) + { + var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir); + return formattedSubDir; + } var formatted = Ip.ReturnUri(Port, Ssl); return formatted; } diff --git a/PlexRequests.Core/SettingModels/PlexSettings.cs b/PlexRequests.Core/SettingModels/PlexSettings.cs index 89bc01931..fa39af857 100644 --- a/PlexRequests.Core/SettingModels/PlexSettings.cs +++ b/PlexRequests.Core/SettingModels/PlexSettings.cs @@ -36,12 +36,18 @@ namespace PlexRequests.Core.SettingModels public string Ip { get; set; } public int Port { get; set; } public bool Ssl { get; set; } + public string SubDir { get; set; } [JsonIgnore] public Uri FullUri { get { + if (!string.IsNullOrEmpty(SubDir)) + { + var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir); + return formattedSubDir; + } var formatted = Ip.ReturnUri(Port, Ssl); return formatted; } diff --git a/PlexRequests.Core/SettingModels/SickRageSettings.cs b/PlexRequests.Core/SettingModels/SickRageSettings.cs index b06801db4..657de3b50 100644 --- a/PlexRequests.Core/SettingModels/SickRageSettings.cs +++ b/PlexRequests.Core/SettingModels/SickRageSettings.cs @@ -24,13 +24,36 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ************************************************************************/ #endregion + +using System; +using Newtonsoft.Json; +using PlexRequests.Helpers; + namespace PlexRequests.Core.SettingModels { public class SickRageSettings : Settings { + public bool Enabled { get; set; } public string Ip { get; set; } public int Port { get; set; } public string ApiKey { get; set; } - public bool Enabled { get; set; } + public string QualityProfile { get; set; } + public bool Ssl { get; set; } + public string SubDir { get; set; } + + [JsonIgnore] + public Uri FullUri + { + get + { + if (!string.IsNullOrEmpty(SubDir)) + { + var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir); + return formattedSubDir; + } + var formatted = Ip.ReturnUri(Port, Ssl); + return formatted; + } + } } } \ No newline at end of file diff --git a/PlexRequests.Core/SettingModels/SonarrSettings.cs b/PlexRequests.Core/SettingModels/SonarrSettings.cs index 15f486d37..3c680e0e5 100644 --- a/PlexRequests.Core/SettingModels/SonarrSettings.cs +++ b/PlexRequests.Core/SettingModels/SonarrSettings.cs @@ -33,6 +33,7 @@ namespace PlexRequests.Core.SettingModels { public class SonarrSettings : Settings { + public bool Enabled { get; set; } public string Ip { get; set; } public int Port { get; set; } public string ApiKey { get; set; } @@ -40,12 +41,18 @@ namespace PlexRequests.Core.SettingModels public bool SeasonFolders { get; set; } public string RootPath { get; set; } public bool Ssl { get; set; } + public string SubDir { get; set; } [JsonIgnore] public Uri FullUri { get { + if (!string.IsNullOrEmpty(SubDir)) + { + var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir); + return formattedSubDir; + } var formatted = Ip.ReturnUri(Port, Ssl); return formatted; } diff --git a/PlexRequests.Core/Setup.cs b/PlexRequests.Core/Setup.cs index 4681dd3b4..04ce5b9db 100644 --- a/PlexRequests.Core/Setup.cs +++ b/PlexRequests.Core/Setup.cs @@ -24,10 +24,13 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ************************************************************************/ #endregion + +using System; using System.Collections.Generic; using System.Linq; using Mono.Data.Sqlite; +using PlexRequests.Api; using PlexRequests.Core.SettingModels; using PlexRequests.Helpers; using PlexRequests.Store; @@ -70,20 +73,61 @@ namespace PlexRequests.Core private void MigrateDb() // TODO: Remove when no longer needed { + var result = new List(); + RequestedModel[] requestedModels; var repo = new GenericRepository(Db); - var records = repo.GetAll(); - var requestedModels = records as RequestedModel[] ?? records.ToArray(); - if(!requestedModels.Any()) + try + { + var records = repo.GetAll(); + requestedModels = records as RequestedModel[] ?? records.ToArray(); + } + catch (SqliteException) + { + // There is no requested table so they do not have an old version of the DB + return; + } + + if (!requestedModels.Any()) { return; } var jsonRepo = new JsonRequestService(new RequestJsonRepository(Db, new MemoryCacheProvider())); - var result = new List(); - foreach (var r in requestedModels) + + var api = new TvMazeApi(); + + foreach (var r in requestedModels.Where(x => x.Type == RequestType.TvShow)) + { + var show = api.ShowLookupByTheTvDbId(r.ProviderId); + + var model = new RequestedModel + { + Title = show.name, + PosterPath = show.image?.medium, + Type = RequestType.TvShow, + ProviderId = show.externals.thetvdb ?? 0, + ReleaseDate = r.ReleaseDate, + AdminNote = r.AdminNote, + Approved = r.Approved, + Available = r.Available, + ImdbId = show.externals.imdb, + Issues = r.Issues, + LatestTv = r.LatestTv, + OtherMessage = r.OtherMessage, + Overview = show.summary.RemoveHtml(), + RequestedBy = r.RequestedBy, + RequestedDate = r.ReleaseDate, + Status = show.status + }; + var id = jsonRepo.AddRequest(model); + result.Add(id); + } + + foreach (var source in requestedModels.Where(x => x.Type== RequestType.Movie)) { - var id = jsonRepo.AddRequest(r); + var id = jsonRepo.AddRequest(source); result.Add(id); } + if (result.Any(x => x == -1)) { throw new SqliteException("Could not migrate the DB!"); diff --git a/PlexRequests.Helpers.Tests/UriHelperTests.cs b/PlexRequests.Helpers.Tests/UriHelperTests.cs index 7c767dfd0..93fb32997 100644 --- a/PlexRequests.Helpers.Tests/UriHelperTests.cs +++ b/PlexRequests.Helpers.Tests/UriHelperTests.cs @@ -26,6 +26,7 @@ #endregion using System; +using System.Linq.Expressions; using NUnit.Framework; namespace PlexRequests.Helpers.Tests @@ -35,7 +36,7 @@ namespace PlexRequests.Helpers.Tests { [TestCaseSource(nameof(UriData))] public void CreateUri1(string uri, Uri expected) - { + { var result = uri.ReturnUri(); Assert.That(result, Is.EqualTo(expected)); @@ -58,6 +59,14 @@ namespace PlexRequests.Helpers.Tests Assert.That(result, Is.EqualTo(expected)); } + [TestCaseSource(nameof(UriDataWithSubDir))] + public void CreateUriWithSubDir(string uri, int port, bool ssl, string subDir, Uri expected) + { + var result = uri.ReturnUriWithSubDir(port, ssl, subDir); + + Assert.That(result, Is.EqualTo(expected)); + } + static readonly object[] UriData = { new object[] { "google.com", new Uri("http://google.com/"), }, @@ -84,5 +93,13 @@ namespace PlexRequests.Helpers.Tests new object[] {"http://www.google.com/id=2", 443, new Uri("http://www.google.com:443/id=2") }, new object[] {"https://www.google.com/id=2", 443, new Uri("https://www.google.com:443/id=2") }, }; + + static readonly object[] UriDataWithSubDir = +{ + new object[] {"www.google.com", 80, false,"test", new Uri("http://www.google.com:80/test"), }, + new object[] {"www.google.com", 443, false,"test", new Uri("http://www.google.com:443/test") }, + new object[] {"http://www.google.com", 443, true,"test", new Uri("https://www.google.com:443/test") }, + new object[] {"https://www.google.com", 443,true,"test", new Uri("https://www.google.com:443/test") }, + }; } } \ No newline at end of file diff --git a/PlexRequests.Helpers/HtmlRemover.cs b/PlexRequests.Helpers/HtmlRemover.cs index 64d23a6de..43d484255 100644 --- a/PlexRequests.Helpers/HtmlRemover.cs +++ b/PlexRequests.Helpers/HtmlRemover.cs @@ -33,6 +33,10 @@ namespace PlexRequests.Helpers { public static string RemoveHtml(this string value) { + if (string.IsNullOrEmpty(value)) + { + return string.Empty; + } var step1 = Regex.Replace(value, @"<[^>]+>| ", "").Trim(); var step2 = Regex.Replace(step1, @"\s{2,}", " "); return step2; diff --git a/PlexRequests.Helpers/UriHelper.cs b/PlexRequests.Helpers/UriHelper.cs index c33d5ddf4..707f70436 100644 --- a/PlexRequests.Helpers/UriHelper.cs +++ b/PlexRequests.Helpers/UriHelper.cs @@ -53,7 +53,10 @@ namespace PlexRequests.Helpers /// /// The value. /// The port. + /// if set to true [SSL]. + /// The subdir. /// + /// The URI is null, please check your settings to make sure you have configured the applications correctly. /// public static Uri ReturnUri(this string val, int port, bool ssl = default(bool)) { @@ -93,5 +96,21 @@ namespace PlexRequests.Helpers throw new Exception(exception.Message, exception); } } + + public static Uri ReturnUriWithSubDir(this string val, int port, bool ssl, string subDir) + { + var uriBuilder = new UriBuilder(val); + if (ssl) + { + uriBuilder.Scheme = Uri.UriSchemeHttps; + } + if (!string.IsNullOrEmpty(subDir)) + { + uriBuilder.Path = subDir; + } + uriBuilder.Port = port; + + return uriBuilder.Uri; + } } } \ No newline at end of file diff --git a/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs b/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs index 117157927..8e641181e 100644 --- a/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs +++ b/PlexRequests.Services.Tests/PlexAvailabilityCheckerTests.cs @@ -108,7 +108,7 @@ namespace PlexRequests.Services.Tests var requestMock = new Mock(); var plexMock = new Mock(); - var searchResult = new PlexSearch { Video = new List