Added code to request the api key for CouchPotato

pull/470/head
tidusjar 8 years ago
parent f9af1dc12b
commit ae64c11485

@ -1,41 +1,43 @@
#region Copyright #region Copyright
// /************************************************************************ // /************************************************************************
// Copyright (c) 2016 Jamie Rees // Copyright (c) 2016 Jamie Rees
// File: ICouchPotatoApi.cs // File: ICouchPotatoApi.cs
// Created By: Jamie Rees // Created By: Jamie Rees
// //
// Permission is hereby granted, free of charge, to any person obtaining // Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the // a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including // "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish, // without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to // distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to // permit persons to whom the Software is furnished to do so, subject to
// the following conditions: // the following conditions:
// //
// The above copyright notice and this permission notice shall be // The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software. // included in all copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// 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 System; using System;
using PlexRequests.Api.Models.Movie; using PlexRequests.Api.Models.Movie;
namespace PlexRequests.Api.Interfaces namespace PlexRequests.Api.Interfaces
{ {
public interface ICouchPotatoApi public interface ICouchPotatoApi
{ {
bool AddMovie(string imdbid, string apiKey, string title, Uri baseUrl, string profileID = default(string)); bool AddMovie(string imdbid, string apiKey, string title, Uri baseUrl, string profileID = default(string));
CouchPotatoStatus GetStatus(Uri url, string apiKey); CouchPotatoStatus GetStatus(Uri url, string apiKey);
CouchPotatoProfiles GetProfiles(Uri url, string apiKey); CouchPotatoProfiles GetProfiles(Uri url, string apiKey);
CouchPotatoMovies GetMovies(Uri baseUrl, string apiKey, string[] status); CouchPotatoMovies GetMovies(Uri baseUrl, string apiKey, string[] status);
}
CoucPotatoApiKey GetApiKey(Uri baseUrl, string username, string password);
}
} }

@ -0,0 +1,38 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: CoucPotatoApiKey.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 Newtonsoft.Json;
namespace PlexRequests.Api.Models.Movie
{
public class CoucPotatoApiKey
{
[JsonProperty("success")]
public bool Result { get; set; }
[JsonProperty("api_key")]
public string ApiKey { get; set; }
}
}

@ -1,71 +1,91 @@
using System; #region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: CouchPotatoAdd.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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PlexRequests.Api.Models.Movie namespace PlexRequests.Api.Models.Movie
{ {
public class CouchPotatoAdd public class CouchPotatoAdd
{ {
public Movie movie { get; set; } public Movie movie { get; set; }
public bool success { get; set; } public bool success { get; set; }
} }
public class Rating public class Rating
{ {
public List<string> imdb { get; set; } public List<string> imdb { get; set; }
} }
public class Images public class Images
{ {
public List<object> disc_art { get; set; }
public List<string> poster { get; set; }
public List<string> backdrop { get; set; }
public List<object> extra_thumbs { get; set; }
public List<string> poster_original { get; set; }
public List<string> actors { get; set; } public List<string> actors { get; set; }
public List<string> backdrop { get; set; }
public List<string> backdrop_original { get; set; } public List<string> backdrop_original { get; set; }
public List<object> clear_art { get; set; }
public List<object> logo { get; set; }
public List<object> banner { get; set; } public List<object> banner { get; set; }
public List<object> landscape { get; set; } public List<object> clear_art { get; set; }
public List<object> disc_art { get; set; }
public List<object> extra_fanart { get; set; } public List<object> extra_fanart { get; set; }
public List<object> extra_thumbs { get; set; }
public List<object> landscape { get; set; }
public List<object> logo { get; set; }
public List<string> poster { get; set; }
public List<string> poster_original { get; set; }
} }
public class Info public class Info
{ {
public Rating rating { get; set; }
public List<string> genres { get; set; }
public int tmdb_id { get; set; }
public string plot { get; set; }
public string tagline { get; set; }
public Release_Date release_date { get; set; }
public int year { get; set; }
public string original_title { get; set; }
public List<string> actor_roles { get; set; } public List<string> actor_roles { get; set; }
public bool via_imdb { get; set; } public List<string> actors { get; set; }
public Images images { get; set; }
public List<string> directors { get; set; } public List<string> directors { get; set; }
public List<string> titles { get; set; } public List<string> genres { get; set; }
public Images images { get; set; }
public string imdb { get; set; } public string imdb { get; set; }
public string mpaa { get; set; } public string mpaa { get; set; }
public bool via_tmdb { get; set; } public string original_title { get; set; }
public List<string> actors { get; set; } public string plot { get; set; }
public List<string> writers { get; set; } public Rating rating { get; set; }
public Release_Date release_date { get; set; }
public string released { get; set; }
public int runtime { get; set; } public int runtime { get; set; }
public string tagline { get; set; }
public List<string> titles { get; set; }
public int tmdb_id { get; set; }
public string type { get; set; } public string type { get; set; }
public string released { get; set; } public bool via_imdb { get; set; }
public bool via_tmdb { get; set; }
public List<string> writers { get; set; }
public int year { get; set; }
} }
public class Release_Date public class Release_Date
{ {
public bool bluray { get; set; }
public int dvd { get; set; } public int dvd { get; set; }
public int expires { get; set; } public int expires { get; set; }
public int theater { get; set; } public int theater { get; set; }
public bool bluray { get; set; }
} }
public class Files public class Files
@ -80,21 +100,19 @@ namespace PlexRequests.Api.Models.Movie
public class Movie public class Movie
{ {
public string status { get; set; }
public Info info { get; set; }
public string _t { get; set; }
public List<object> releases { get; set; }
public string title { get; set; }
public string _rev { get; set; }
public string profile_id { get; set; }
public string _id { get; set; } public string _id { get; set; }
public List<object> tags { get; set; } public string _rev { get; set; }
public int last_edit { get; set; } public string _t { get; set; }
public object category_id { get; set; } public object category_id { get; set; }
public string type { get; set; }
public Files files { get; set; } public Files files { get; set; }
public Identifiers identifiers { get; set; } public Identifiers identifiers { get; set; }
public Info info { get; set; }
public int last_edit { get; set; }
public string profile_id { get; set; }
public List<object> releases { get; set; }
public string status { get; set; }
public List<object> tags { get; set; }
public string title { get; set; }
public string type { get; set; }
} }
}
}

@ -1,111 +1,112 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{CB37A5F8-6DFC-4554-99D3-A42B502E4591}</ProjectGuid> <ProjectGuid>{CB37A5F8-6DFC-4554-99D3-A42B502E4591}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PlexRequests.Api.Models</RootNamespace> <RootNamespace>PlexRequests.Api.Models</RootNamespace>
<AssemblyName>PlexRequests.Api.Models</AssemblyName> <AssemblyName>PlexRequests.Api.Models</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath> <OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath> <OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"> <Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
<HintPath>..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Movie\CouchPotatoAdd.cs" /> <Compile Include="Movie\CouchPotatoAdd.cs" />
<Compile Include="Movie\CouchPotatoMovies.cs" /> <Compile Include="Movie\CouchPotatoMovies.cs" />
<Compile Include="Movie\CouchPotatoProfiles.cs" /> <Compile Include="Movie\CouchPotatoProfiles.cs" />
<Compile Include="Movie\CouchPotatoStatus.cs" /> <Compile Include="Movie\CouchPotatoStatus.cs" />
<Compile Include="Music\HeadphonesAlbumSearchResult.cs" /> <Compile Include="Movie\CoucPotatoApiKey.cs" />
<Compile Include="Music\HeadphonesArtistSearchResult.cs" /> <Compile Include="Music\HeadphonesAlbumSearchResult.cs" />
<Compile Include="Music\HeadphonesGetIndex.cs" /> <Compile Include="Music\HeadphonesArtistSearchResult.cs" />
<Compile Include="Music\HeadphonesVersion.cs" /> <Compile Include="Music\HeadphonesGetIndex.cs" />
<Compile Include="Music\MusicBrainzCoverArt.cs" /> <Compile Include="Music\HeadphonesVersion.cs" />
<Compile Include="Music\MusicBrainzReleaseInfo.cs" /> <Compile Include="Music\MusicBrainzCoverArt.cs" />
<Compile Include="Music\MusicBrainzSearchResults.cs" /> <Compile Include="Music\MusicBrainzReleaseInfo.cs" />
<Compile Include="Notifications\PushbulletPush.cs" /> <Compile Include="Music\MusicBrainzSearchResults.cs" />
<Compile Include="Notifications\PushbulletResponse.cs" /> <Compile Include="Notifications\PushbulletPush.cs" />
<Compile Include="Notifications\PushoverResponse.cs" /> <Compile Include="Notifications\PushbulletResponse.cs" />
<Compile Include="Notifications\SlackNotificationBody.cs" /> <Compile Include="Notifications\PushoverResponse.cs" />
<Compile Include="Plex\PlexAccount.cs" /> <Compile Include="Notifications\SlackNotificationBody.cs" />
<Compile Include="Plex\PlexAuthentication.cs" /> <Compile Include="Plex\PlexAccount.cs" />
<Compile Include="Plex\PlexError.cs" /> <Compile Include="Plex\PlexAuthentication.cs" />
<Compile Include="Plex\PlexFriends.cs" /> <Compile Include="Plex\PlexError.cs" />
<Compile Include="Plex\PlexLibraries.cs" /> <Compile Include="Plex\PlexFriends.cs" />
<Compile Include="Plex\PlexMetadata.cs" /> <Compile Include="Plex\PlexLibraries.cs" />
<Compile Include="Plex\PlexSearch.cs" /> <Compile Include="Plex\PlexMetadata.cs" />
<Compile Include="Plex\PlexStatus.cs" /> <Compile Include="Plex\PlexSearch.cs" />
<Compile Include="Plex\PlexMediaType.cs" /> <Compile Include="Plex\PlexStatus.cs" />
<Compile Include="Plex\PlexUserRequest.cs" /> <Compile Include="Plex\PlexMediaType.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Plex\PlexUserRequest.cs" />
<Compile Include="SickRage\SickRageBase.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SickRage\SickrageShows.cs" /> <Compile Include="SickRage\SickRageBase.cs" />
<Compile Include="SickRage\SickRagePing.cs" /> <Compile Include="SickRage\SickrageShows.cs" />
<Compile Include="SickRage\SickRageSeasonList.cs" /> <Compile Include="SickRage\SickRagePing.cs" />
<Compile Include="SickRage\SickRageShowInformation.cs" /> <Compile Include="SickRage\SickRageSeasonList.cs" />
<Compile Include="SickRage\SickRageStatus.cs" /> <Compile Include="SickRage\SickRageShowInformation.cs" />
<Compile Include="SickRage\SickRageTvAdd.cs" /> <Compile Include="SickRage\SickRageStatus.cs" />
<Compile Include="Sonarr\SonarrAddSeries.cs" /> <Compile Include="SickRage\SickRageTvAdd.cs" />
<Compile Include="Sonarr\SonarrAllSeries.cs" /> <Compile Include="Sonarr\SonarrAddSeries.cs" />
<Compile Include="Sonarr\SonarrError.cs" /> <Compile Include="Sonarr\SonarrAllSeries.cs" />
<Compile Include="Sonarr\SonarrProfile.cs" /> <Compile Include="Sonarr\SonarrError.cs" />
<Compile Include="Sonarr\SystemStatus.cs" /> <Compile Include="Sonarr\SonarrProfile.cs" />
<Compile Include="Tv\Authentication.cs" /> <Compile Include="Sonarr\SystemStatus.cs" />
<Compile Include="Tv\TvMazeSearch.cs" /> <Compile Include="Tv\Authentication.cs" />
<Compile Include="Tv\TvMazeSeasons.cs" /> <Compile Include="Tv\TvMazeSearch.cs" />
<Compile Include="Tv\TVMazeShow.cs" /> <Compile Include="Tv\TvMazeSeasons.cs" />
<Compile Include="Tv\TvSearchResult.cs" /> <Compile Include="Tv\TVMazeShow.cs" />
<Compile Include="Tv\TvShow.cs" /> <Compile Include="Tv\TvSearchResult.cs" />
<Compile Include="Tv\TvShowImages.cs" /> <Compile Include="Tv\TvShow.cs" />
</ItemGroup> <Compile Include="Tv\TvShowImages.cs" />
<ItemGroup> </ItemGroup>
<None Include="app.config" /> <ItemGroup>
<None Include="packages.config" /> <None Include="app.config" />
</ItemGroup> <None Include="packages.config" />
<ItemGroup> </ItemGroup>
<ProjectReference Include="..\PlexRequests.Helpers\PlexRequests.Helpers.csproj"> <ItemGroup>
<Project>{1252336D-42A3-482A-804C-836E60173DFA}</Project> <ProjectReference Include="..\PlexRequests.Helpers\PlexRequests.Helpers.csproj">
<Name>PlexRequests.Helpers</Name> <Project>{1252336D-42A3-482A-804C-836E60173DFA}</Project>
</ProjectReference> <Name>PlexRequests.Helpers</Name>
</ItemGroup> </ProjectReference>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Other similar extension points exist, see Microsoft.Common.targets. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
<Target Name="BeforeBuild"> Other similar extension points exist, see Microsoft.Common.targets.
</Target> <Target Name="BeforeBuild">
<Target Name="AfterBuild"> </Target>
</Target> <Target Name="AfterBuild">
--> </Target>
-->
</Project> </Project>

@ -31,6 +31,7 @@ using Newtonsoft.Json.Linq;
using NLog; using NLog;
using PlexRequests.Api.Interfaces; using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models.Movie; using PlexRequests.Api.Models.Movie;
using PlexRequests.Helpers;
using PlexRequests.Helpers.Exceptions; using PlexRequests.Helpers.Exceptions;
using RestSharp; using RestSharp;
@ -159,5 +160,22 @@ namespace PlexRequests.Api
return new CouchPotatoMovies(); return new CouchPotatoMovies();
} }
} }
public CoucPotatoApiKey GetApiKey(Uri baseUrl, string username, string password)
{
var request = new RestRequest
{
Resource = "getkey/?p={username}&u={password}",
Method = Method.GET
};
request.AddUrlSegment("username", StringHasher.CalcuateMD5Hash(username));
request.AddUrlSegment("password", StringHasher.CalcuateMD5Hash(password));
var obj = RetryHandler.Execute(() => Api.Execute<CoucPotatoApiKey>(request, baseUrl), null,
(exception, timespan) => Log.Error(exception, "Exception when calling GetApiKey for CP, Retrying {0}", timespan));
return obj;
}
} }
} }

@ -1,59 +1,61 @@
#region Copyright #region Copyright
// /************************************************************************ // /************************************************************************
// Copyright (c) 2016 Jamie Rees // Copyright (c) 2016 Jamie Rees
// File: CouchPotatoSettings.cs // File: CouchPotatoSettings.cs
// Created By: Jamie Rees // Created By: Jamie Rees
// //
// Permission is hereby granted, free of charge, to any person obtaining // Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the // a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including // "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish, // without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to // distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to // permit persons to whom the Software is furnished to do so, subject to
// the following conditions: // the following conditions:
// //
// The above copyright notice and this permission notice shall be // The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software. // included in all copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// 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 System; using System;
using Newtonsoft.Json; using Newtonsoft.Json;
using PlexRequests.Helpers; using PlexRequests.Helpers;
namespace PlexRequests.Core.SettingModels namespace PlexRequests.Core.SettingModels
{ {
public class CouchPotatoSettings : Settings public class CouchPotatoSettings : Settings
{ {
public bool Enabled { get; set; } public bool Enabled { get; set; }
public string Ip { get; set; } public string Ip { get; set; }
public int Port { get; set; } public int Port { get; set; }
public string ApiKey { get; set; } public string ApiKey { get; set; }
public bool Ssl { get; set; } public bool Ssl { get; set; }
public string ProfileId { get; set; } public string ProfileId { get; set; }
public string SubDir { get; set; } public string SubDir { get; set; }
public string Username { get; set; }
[JsonIgnore] public string Password { get; set; }
public Uri FullUri
{ [JsonIgnore]
get public Uri FullUri
{ {
if (!string.IsNullOrEmpty(SubDir)) get
{ {
var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir); if (!string.IsNullOrEmpty(SubDir))
return formattedSubDir; {
} var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir);
var formatted = Ip.ReturnUri(Port, Ssl); return formattedSubDir;
return formatted; }
} var formatted = Ip.ReturnUri(Port, Ssl);
} return formatted;
} }
}
}
} }

@ -80,6 +80,7 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SerializerSettings.cs" /> <Compile Include="SerializerSettings.cs" />
<Compile Include="StringCipher.cs" /> <Compile Include="StringCipher.cs" />
<Compile Include="StringHasher.cs" />
<Compile Include="UriHelper.cs" /> <Compile Include="UriHelper.cs" />
<Compile Include="UserClaims.cs" /> <Compile Include="UserClaims.cs" />
</ItemGroup> </ItemGroup>

@ -0,0 +1,52 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: StringHasher.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.Security.Cryptography;
using System.Text;
namespace PlexRequests.Helpers
{
public class StringHasher
{
public static string CalcuateMD5Hash(string input)
{
using (var md5 = MD5.Create())
{
var inputBytes = Encoding.ASCII.GetBytes(input);
var hash = md5.ComputeHash(inputBytes);
var sb = new StringBuilder();
foreach (byte t in hash)
{
sb.Append(t.ToString("x2"));
}
return sb.ToString();
}
}
}
}

@ -171,6 +171,7 @@ namespace PlexRequests.UI.Modules
Post["/sonarrprofiles"] = _ => GetSonarrQualityProfiles(); Post["/sonarrprofiles"] = _ => GetSonarrQualityProfiles();
Post["/cpprofiles", true] = async (x,ct) => await GetCpProfiles(); Post["/cpprofiles", true] = async (x,ct) => await GetCpProfiles();
Post["/cpapikey", true] = async (x,ct) => await GetCpApiKey();
Get["/emailnotification"] = _ => EmailNotifications(); Get["/emailnotification"] = _ => EmailNotifications();
Post["/emailnotification"] = _ => SaveEmailNotifications(); Post["/emailnotification"] = _ => SaveEmailNotifications();
@ -696,6 +697,20 @@ namespace PlexRequests.UI.Modules
return Response.AsJson(profiles); return Response.AsJson(profiles);
} }
private async Task<Response> GetCpApiKey()
{
var settings = this.Bind<CouchPotatoSettings>();
if (string.IsNullOrEmpty(settings.Username) || string.IsNullOrEmpty(settings.Password))
{
return Response.AsJson(new { Message = "Please enter a username and password to request the Api Key", Result = false });
}
var key = CpApi.GetApiKey(settings.FullUri, settings.Username, settings.Password);
return Response.AsJson(key);
}
private Negotiator Logs() private Negotiator Logs()
{ {
return View["Logs"]; return View["Logs"];

@ -1,232 +1,271 @@
@using PlexRequests.UI.Helpers @using PlexRequests.UI.Helpers
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<PlexRequests.Core.SettingModels.CouchPotatoSettings> @inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<PlexRequests.Core.SettingModels.CouchPotatoSettings>
@Html.Partial("_Sidebar") @Html.Partial("_Sidebar")
@{ @{
int port; int port;
if (Model.Port == 0) if (Model.Port == 0)
{ {
port = 5050; port = 5050;
} }
else else
{ {
port = Model.Port; port = Model.Port;
} }
} }
<div class="col-sm-8 col-sm-push-1"> <div class="col-sm-8 col-sm-push-1">
<form class="form-horizontal" method="POST" id="mainForm"> <form class="form-horizontal" method="POST" id="mainForm">
<fieldset> <fieldset>
<legend>CouchPotato Settings</legend> <legend>CouchPotato Settings</legend>
<div class="form-group"> <div class="form-group">
<div class="checkbox"> <div class="checkbox">
@if (Model.Enabled) @if (Model.Enabled)
{ {
<input type="checkbox" id="Enabled" name="Enabled" checked="checked"><label for="Enabled">Enabled</label> <input type="checkbox" id="Enabled" name="Enabled" checked="checked"><label for="Enabled">Enabled</label>
} }
else else
{ {
<input type="checkbox" id="Enabled" name="Enabled"><label for="Enabled">Enabled</label> <input type="checkbox" id="Enabled" name="Enabled"><label for="Enabled">Enabled</label>
} }
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="Ip" class="control-label">CouchPotato Hostname or IP</label> <label for="Ip" class="control-label">CouchPotato Hostname or IP</label>
<div class=""> <div class="">
<input type="text" class="form-control form-control-custom " id="Ip" name="Ip" placeholder="localhost" value="@Model.Ip"> <input type="text" class="form-control form-control-custom " id="Ip" name="Ip" placeholder="localhost" value="@Model.Ip">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="portNumber" class="control-label">Port</label> <label for="portNumber" class="control-label">Port</label>
<div class=""> <div class="">
<input type="text" class="form-control form-control-custom " id="portNumber" name="Port" placeholder="Port Number" value="@port"> <input type="text" class="form-control form-control-custom " id="portNumber" name="Port" placeholder="Port Number" value="@port">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="ApiKey" class="control-label">CouchPotato API Key</label> <label for="ApiKey" class="control-label">CouchPotato API Key</label>
<div> <div>
<input type="text" class="form-control form-control-custom " id="ApiKey" name="ApiKey" value="@Model.ApiKey"> <input type="text" class="form-control form-control-custom " id="ApiKey" name="ApiKey" value="@Model.ApiKey">
</div> </div>
</div> </div>
<div class="form-group">
<div class="checkbox"> <div class="form-group">
<label for="username" class="control-label">Username and Password</label>
@if (Model.Ssl) <div>
{ <input type="text" class="form-control form-control-custom" id="username" name="Username" placeholder="username">
<input type="checkbox" id="Ssl" name="Ssl" checked="checked"><label for="Ssl">SSL</label> </div>
} <br />
else <div>
{ <input type="password" class="form-control form-control-custom" id="password" name="Password" placeholder="Password">
<input type="checkbox" id="Ssl" name="Ssl"><label for="Ssl">SSL</label> </div>
} </div>
<div class="form-group">
</div> <div class="">
</div> <button id="requestToken" class="btn btn-primary-outline">Request Api Key <i class="fa fa-key"></i></button>
<div class="form-group"> </div>
<label for="SubDir" class="control-label">CouchPotato SubDirectory</label> </div>
<div> <div class="form-group">
<input type="text" class="form-control form-control-custom " id="SubDir" name="SubDir" value="@Model.SubDir"> <div class="checkbox">
</div>
</div> @if (Model.Ssl)
{
<input type="checkbox" id="Ssl" name="Ssl" checked="checked"><label for="Ssl">SSL</label>
<div class="form-group"> }
<div> else
<button type="submit" id="getProfiles" class="btn btn-primary-outline">Get Quality Profiles</button> {
</div> <input type="checkbox" id="Ssl" name="Ssl"><label for="Ssl">SSL</label>
</div> }
<div class="form-group">
<label for="select" class="control-label">Quality Profiles</label> </div>
<div id="profiles"> </div>
<select class="form-control form-control-custom" id="select"></select> <div class="form-group">
</div> <label for="SubDir" class="control-label">CouchPotato SubDirectory</label>
</div> <div>
<br/> <input type="text" class="form-control form-control-custom " id="SubDir" name="SubDir" value="@Model.SubDir">
</div>
<div class="form-group"> </div>
<div>
<button id="testCp" type="submit" class="btn btn-primary-outline">Test Connectivity <div id="spinner"> </div></button>
</div> <div class="form-group">
</div> <div>
<button type="submit" id="getProfiles" class="btn btn-primary-outline">Get Quality Profiles</button>
</div>
</div>
<div class="form-group">
<div class="form-group"> <label for="select" class="control-label">Quality Profiles</label>
<div> <div id="profiles">
<button id="save" type="submit" class="btn btn-primary-outline">Submit</button> <select class="form-control form-control-custom" id="select"></select>
</div> </div>
</div> </div>
</fieldset> <br/>
</form>
</div> <div class="form-group">
<div>
<button id="testCp" type="submit" class="btn btn-primary-outline">Test Connectivity <div id="spinner"> </div></button>
</div>
<script> </div>
$(function() {
var baseUrl = '@Html.GetBaseUrl()';
@if (!string.IsNullOrEmpty(Model.ProfileId)) <div class="form-group">
{ <div>
<text> <button id="save" type="submit" class="btn btn-primary-outline">Submit</button>
var qualitySelected = '@Model.ProfileId'; </div>
var $form = $("#mainForm"); </div>
var url = '/admin/cpprofiles'; </fieldset>
url = createBaseUrl(baseUrl, url); </form>
$.ajax({ </div>
type: $form.prop("method"),
data: $form.serialize(),
url: url,
dataType: "json", <script>
success: function(response) { $(function() {
response.list.forEach(function(result) {
if (result._id == qualitySelected) { var baseUrl = '@Html.GetBaseUrl()';
$("#select").append("<option selected='selected' value='" + result._id + "'>" + result.label + "</option>"); @if (!string.IsNullOrEmpty(Model.ProfileId))
} else { {
$("#select").append("<option value='" + result._id + "'>" + result.label + "</option>"); <text>
} var qualitySelected = '@Model.ProfileId';
}); var $form = $("#mainForm");
}, var url = '/admin/cpprofiles';
error: function(e) { url = createBaseUrl(baseUrl, url);
console.log(e); $.ajax({
generateNotify("Something went wrong!", "danger"); type: $form.prop("method"),
} data: $form.serialize(),
}); url: url,
</text> dataType: "json",
} success: function(response) {
response.list.forEach(function(result) {
$('#getProfiles').click(function (e) { if (result._id == qualitySelected) {
e.preventDefault();
var $form = $("#mainForm"); $("#select").append("<option selected='selected' value='" + result._id + "'>" + result.label + "</option>");
var url = createBaseUrl(baseUrl, "/admin/cpprofiles"); } else {
$.ajax({ $("#select").append("<option value='" + result._id + "'>" + result.label + "</option>");
type: $form.prop("method"), }
data: $form.serialize(), });
url: url, },
dataType: "json", error: function(e) {
success: function (response) { console.log(e);
if (response.message) { generateNotify("Something went wrong!", "danger");
generateNotify(response.message, "warning"); }
return; });
} </text>
response.list.forEach(function (result) { }
$("#select").append("<option value='" + result._id + "'>" + result.label + "</option>");
}); $('#requestToken').click(function (e) {
}, e.preventDefault();
error: function (e) { var $form = $("#mainForm");
console.log(e); $.ajax({
generateNotify("Something went wrong!", "danger"); type: $form.prop("method"),
} url: "cpapikey",
}); data: $form.serialize(),
}); dataType: "json",
success: function (response) {
$('#testCp').click(function (e) { if (response.result === true) {
e.preventDefault(); generateNotify("Success!", "success");
var $form = $("#mainForm"); $('#ApiKey').val(response.apiKey);
var url = createBaseUrl(baseUrl,"/test/cp"); } else {
$('#spinner').attr("class", "fa fa-spinner fa-spin"); generateNotify(response.message, "warning");
}
$.ajax({ },
type: $form.prop("method"), error: function (e) {
url: url, console.log(e);
data: $form.serialize(), generateNotify("Something went wrong!", "danger");
dataType: "json", }
success: function (response) { });
console.log(response); });
if (response.result === true) {
$('#spinner').attr("class", "fa fa-check"); $('#getProfiles').click(function (e) {
generateNotify(response.message, "success"); e.preventDefault();
$('#authToken').val(response.authToken); var $form = $("#mainForm");
} else { var url = createBaseUrl(baseUrl, "/admin/cpprofiles");
generateNotify(response.message, "warning"); $.ajax({
$('#spinner').attr("class", "fa fa-times"); type: $form.prop("method"),
} data: $form.serialize(),
}, url: url,
error: function (e) { dataType: "json",
console.log(e); success: function (response) {
generateNotify("Something went wrong!", "danger"); if (response.message) {
$('#spinner').attr("class", "fa fa-times"); generateNotify(response.message, "warning");
} return;
}); }
}); response.list.forEach(function (result) {
$("#select").append("<option value='" + result._id + "'>" + result.label + "</option>");
$('#save').click(function (e) { });
e.preventDefault(); },
var port = $('#portNumber').val(); error: function (e) {
if (isNaN(port)) { console.log(e);
generateNotify("You must specify a Port.", "warning"); generateNotify("Something went wrong!", "danger");
return; }
} });
var $form = $("#mainForm"); });
var qualityProfile = $("#profiles option:selected").val();
var data = $form.serialize(); $('#testCp').click(function (e) {
data = data + "&profileId=" + qualityProfile; e.preventDefault();
var $form = $("#mainForm");
$.ajax({ var url = createBaseUrl(baseUrl,"/test/cp");
type: $form.prop("method"), $('#spinner').attr("class", "fa fa-spinner fa-spin");
data: data,
url: $form.prop("action"), $.ajax({
dataType: "json", type: $form.prop("method"),
success: function (response) { url: url,
if (response.result === true) { data: $form.serialize(),
generateNotify(response.message, "success"); dataType: "json",
} else { success: function (response) {
generateNotify(response.message, "warning"); console.log(response);
} if (response.result === true) {
}, $('#spinner').attr("class", "fa fa-check");
error: function (e) { generateNotify(response.message, "success");
console.log(e); $('#authToken').val(response.authToken);
generateNotify("Something went wrong!", "danger"); } else {
} generateNotify(response.message, "warning");
}); $('#spinner').attr("class", "fa fa-times");
}); }
},
}); error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
$('#spinner').attr("class", "fa fa-times");
}
});
});
$('#save').click(function (e) {
e.preventDefault();
var port = $('#portNumber').val();
if (isNaN(port)) {
generateNotify("You must specify a Port.", "warning");
return;
}
var $form = $("#mainForm");
var qualityProfile = $("#profiles option:selected").val();
var data = $form.serialize();
data = data + "&profileId=" + qualityProfile;
$.ajax({
type: $form.prop("method"),
data: data,
url: $form.prop("action"),
dataType: "json",
success: function (response) {
if (response.result === true) {
generateNotify(response.message, "success");
} else {
generateNotify(response.message, "warning");
}
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
}
});
});
});
</script> </script>
Loading…
Cancel
Save