Fixed the issue when sending movies to CouchPotato.

pull/13/head
Jamie Rees 9 years ago
parent 5f9987b85d
commit 65087642e1

@ -43,7 +43,7 @@ namespace PlexRequests.Api
private ApiRequest Api { get; set; }
private static Logger Log = LogManager.GetCurrentClassLogger();
public bool AddMovie(string imdbid, string apiKey, string title, string baseUrl)
public bool AddMovie(string imdbid, string apiKey, string title, Uri baseUrl)
{
var request = new RestRequest { Resource = "/api/{apikey}/movie.add?title={title}&identifier={imdbid}" };
@ -51,7 +51,7 @@ namespace PlexRequests.Api
request.AddUrlSegment("imdbid", imdbid);
request.AddUrlSegment("title", title);
var obj = Api.ExecuteJson<JObject>(request, new Uri(baseUrl));
var obj = Api.ExecuteJson<JObject>(request, baseUrl);
Log.Trace("CP movie Add result count {0}", obj.Count);
if (obj.Count > 0)

@ -24,6 +24,11 @@
// 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 CouchPotatoSettings : Settings
@ -32,5 +37,15 @@ namespace PlexRequests.Core.SettingModels
public int Port { get; set; }
public string ApiKey { get; set; }
public bool Enabled { get; set; }
[JsonIgnore]
public Uri FullUri
{
get
{
var formatted = Ip.ReturnUri(Port);
return formatted;
}
}
}
}

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{0E6395D3-B074-49E8-898D-0EB99E507E0E}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PlexRequests.Helpers.Tests</RootNamespace>
<AssemblyName>PlexRequests.Helpers.Tests</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=3.0.5813.39031, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.0.1\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UriHelperTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PlexRequests.Helpers\PlexRequests.Helpers.csproj">
<Project>{1252336d-42a3-482a-804c-836e60173dfa}</Project>
<Name>PlexRequests.Helpers</Name>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PlexRequests.Helpers.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PlexRequests.Helpers.Tests")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("0e6395d3-b074-49e8-898d-0eb99e507e0e")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,90 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: UriHelperTests.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 NUnit.Framework;
namespace PlexRequests.Helpers.Tests
{
[TestFixture]
public class UriHelperTests
{
[TestCaseSource(nameof(UriData))]
public void CreateUri(string uri, Uri expected)
{
var result = uri.ReturnUri();
Assert.That(result, Is.EqualTo(expected));
}
[TestCaseSource(nameof(UriDataWithPort))]
public void CreateUri(string uri, int port, Uri expected)
{
var result = uri.ReturnUri(port);
Assert.That(result, Is.EqualTo(expected));
}
static readonly object[] UriData =
{
new object[] { "google.com", new Uri("http://google.com/"), },
new object[] { "http://google.com", new Uri("http://google.com/"), },
new object[] { "https://google.com", new Uri("https://google.com/"), },
new object[] { "192.168.1.1", new Uri("http://192.168.1.1")},
new object[] { "0.0.0.0:5533", new Uri("http://0.0.0.0:5533")},
new object[] {"www.google.com", new Uri("http://www.google.com/")},
new object[] {"http://www.google.com/", new Uri("http://www.google.com/") },
new object[] {"https://www.google.com", new Uri("https://www.google.com/") },
new object[] {"www.google.com:443", new Uri("http://www.google.com:443/") },
new object[] {"https://www.google.com:443", new Uri("https://www.google.com:443/") },
new object[] {"http://www.google.com:443/id=2", new Uri("http://www.google.com:443/id=2") },
new object[] {"www.google.com:4438/id=22", new Uri("http://www.google.com:4438/id=22") }
};
static readonly object[] UriDataWithPort =
{
new object[] { "google.com", new Uri("http://google.com/"), },
new object[] { "http://google.com", new Uri("http://google.com/"), },
new object[] { "https://google.com", new Uri("https://google.com/"), },
new object[] { "192.168.1.1", new Uri("http://192.168.1.1")},
new object[] { "0.0.0.0:5533", new Uri("http://0.0.0.0:5533")},
new object[] {"www.google.com", new Uri("http://www.google.com/")},
new object[] {"http://www.google.com/", new Uri("http://www.google.com/") },
new object[] {"https://www.google.com", new Uri("https://www.google.com/") },
new object[] {"www.google.com:443", new Uri("http://www.google.com:443/") },
new object[] {"https://www.google.com:443", new Uri("https://www.google.com:443/") },
new object[] {"http://www.google.com:443/id=2", new Uri("http://www.google.com:443/id=2") },
new object[] {"www.google.com", 80, new Uri("http://www.google.com:80/"), },
new object[] {"www.google.com", 443, new Uri("http://www.google.com:443/") },
new object[] {"http://www.google.com", 443, new Uri("http://www.google.com:443/") },
new object[] {"https://www.google.com", 443, new Uri("https://www.google.com:443/") },
new object[] {"http://www.google.com/id=2", 443, new Uri("http://www.google.com:443/id=2") },
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") },
};
}
}

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.0.1" targetFramework="net46" />
</packages>

@ -54,6 +54,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SerializerSettings.cs" />
<Compile Include="StringCipher.cs" />
<Compile Include="UriHelper.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

@ -0,0 +1,93 @@
using System;
namespace PlexRequests.Helpers
{
public static class UriHelper
{
public static Uri ReturnUri(this string val)
{
try
{
var uri = new UriBuilder();
if (val.StartsWith("http://", StringComparison.Ordinal))
{
uri = new UriBuilder(val);
}
else if (val.StartsWith("https://", StringComparison.Ordinal))
{
uri = new UriBuilder(val);
}
else if (val.Contains(":"))
{
var split = val.Split(':', '/');
int port;
int.TryParse(split[1], out port);
uri = split.Length == 3
? new UriBuilder(Uri.UriSchemeHttp, split[0], port, "/" + split[2])
: new UriBuilder(Uri.UriSchemeHttp, split[0], port);
}
else
{
uri = new UriBuilder(Uri.UriSchemeHttp, val);
}
return uri.Uri;
}
catch (Exception exception)
{
throw new Exception(exception.Message, exception);
}
}
/// <summary>
/// Returns the URI.
/// </summary>
/// <param name="val">The value.</param>
/// <param name="port">The port.</param>
/// <returns></returns>
/// <exception cref="System.Exception"></exception>
public static Uri ReturnUri(this string val, int port)
{
try
{
var uri = new UriBuilder();
if (val.StartsWith("http://", StringComparison.Ordinal))
{
var split = val.Split('/');
if (split.Length >= 4)
{
uri = new UriBuilder(Uri.UriSchemeHttp, split[2], port, "/" + split[3]);
}
else
uri = new UriBuilder(new Uri(string.Format("{0}:{1}", val, port)));
}
else if (val.StartsWith("https://", StringComparison.Ordinal))
{
var split = val.Split('/');
if (split.Length >= 4)
{
uri = new UriBuilder(Uri.UriSchemeHttps, split[2], port, "/" + split[3]);
}
else
uri = new UriBuilder(Uri.UriSchemeHttps, split[2], port);
}
else
{
uri = new UriBuilder(Uri.UriSchemeHttp, val, port);
}
return uri.Uri;
}
catch (Exception exception)
{
throw new Exception(exception.Message, exception);
}
}
}
}

@ -71,7 +71,7 @@ function buildRequestContext(result, type) {
var context = {
posterPath: result.posterPath,
id: result.tmdbid,
id: result.providerId,
title: result.title,
overview: result.overview,
year: result.releaseYear,

@ -175,7 +175,6 @@ namespace PlexRequests.UI.Modules
private Response SaveCouchPotato()
{
var couchPotatoSettings = this.Bind<CouchPotatoSettings>();
CpService.SaveSettings(couchPotatoSettings);
return Context.GetRedirect("~/admin/couchpotato");

@ -149,6 +149,11 @@ namespace PlexRequests.UI.Modules
}
Log.Trace("movie with id {0} doesnt exists", movieId);
var settings = CpService.GetSettings();
if (settings.ApiKey == null)
{
Log.Warn("CP apiKey is null");
return Response.AsJson(new { Result = false, Message = "CouchPotato is not yet configured, If you are the Admin, please log in." });
}
Log.Trace("Settings: ");
Log.Trace(settings.DumpJson);
@ -173,7 +178,7 @@ namespace PlexRequests.UI.Modules
var cp = new CouchPotatoApi();
Log.Trace("Adding movie to CP");
var result = cp.AddMovie(model.ImdbId, settings.ApiKey, model.Title, settings.Ip);
var result = cp.AddMovie(model.ImdbId, settings.ApiKey, model.Title, settings.FullUri);
Log.Trace("Adding movie to CP result {0}", result);
if (result)
{

@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlexRequests.UI.Tests", "Pl
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlexRequests.Core.Tests", "PlexRequests.Core.Tests\PlexRequests.Core.Tests.csproj", "{FCFECD5D-47F6-454D-8692-E27A921BE655}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlexRequests.Helpers.Tests", "PlexRequests.Helpers.Tests\PlexRequests.Helpers.Tests.csproj", "{0E6395D3-B074-49E8-898D-0EB99E507E0E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -65,6 +67,10 @@ Global
{FCFECD5D-47F6-454D-8692-E27A921BE655}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FCFECD5D-47F6-454D-8692-E27A921BE655}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FCFECD5D-47F6-454D-8692-E27A921BE655}.Release|Any CPU.Build.0 = Release|Any CPU
{0E6395D3-B074-49E8-898D-0EB99E507E0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E6395D3-B074-49E8-898D-0EB99E507E0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E6395D3-B074-49E8-898D-0EB99E507E0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E6395D3-B074-49E8-898D-0EB99E507E0E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Loading…
Cancel
Save