Added options for watched, and watchlist, and customlist to trakt

This commit is contained in:
Devin Buhl 2017-01-28 21:17:55 -05:00
parent be083cfd53
commit 5b7d513986
6 changed files with 50 additions and 7 deletions

View File

@ -7,6 +7,16 @@ using NzbDrone.Core.Validation;
namespace NzbDrone.Core.NetImport.CouchPotato
{
public class CouchPotatoSettingsValidator : AbstractValidator<CouchPotatoSettings>
{
public CouchPotatoSettingsValidator()
{
RuleFor(c => c.Link).ValidRootUrl();
RuleFor(c => c.Port).InclusiveBetween(1, 65535);
RuleFor(c => c.ApiKey).NotEmpty();
}
}
public class CouchPotatoSettings : NetImportBaseSettings
{
public CouchPotatoSettings()

View File

@ -15,7 +15,7 @@ namespace NzbDrone.Core.NetImport.Trakt
{
public class TraktImport : HttpNetImportBase<TraktSettings>
{
public override string Name => "Trakt User List";
public override string Name => "Trakt List";
public override bool Enabled => true;
public override bool EnableAuto => false;

View File

@ -0,0 +1,9 @@
namespace NzbDrone.Core.NetImport.Trakt
{
public enum TraktListType
{
WatchList = 0,
Watched = 1,
CustomList = 2
}
}

View File

@ -21,11 +21,22 @@ namespace NzbDrone.Core.NetImport.Trakt
private IEnumerable<NetImportRequest> GetMovies(string searchParameters)
{
// https://api.trakt.tv/users/timdturner/lists/custom1/items/movies
// trakt-api-version = 2
// trakt-api-key = 657bb899dcb81ec8ee838ff09f6e013ff7c740bf0ccfa54dd41e791b9a70b2f0
var link = $"{Settings.Link.Trim()}{Settings.Username.Trim()}";
var request = new NetImportRequest($"{Settings.Link.Trim()}{Settings.Username.Trim()}/lists/{Settings.Listname.Trim()}/items/movies", HttpAccept.Json);
switch (Settings.ListType)
{
case (int)TraktListType.CustomList:
link = link + $"/lists/{Settings.Listname.Trim()}/items/movies";
break;
case (int)TraktListType.WatchList:
link = link + "/watchlist/movies";
break;
case (int)TraktListType.Watched:
link = link + "/watched/movies";
break;
}
var request = new NetImportRequest($"{link}", HttpAccept.Json);
request.HttpRequest.Headers.Add("trakt-api-version", "2");
request.HttpRequest.Headers.Add("trakt-api-key", "657bb899dcb81ec8ee838ff09f6e013ff7c740bf0ccfa54dd41e791b9a70b2f0");

View File

@ -7,6 +7,15 @@ using NzbDrone.Core.Validation;
namespace NzbDrone.Core.NetImport.Trakt
{
public class TraktSettingsValidator : AbstractValidator<TraktSettings>
{
public TraktSettingsValidator()
{
RuleFor(c => c.Link).ValidRootUrl();
RuleFor(c => c.Username).NotEmpty();
}
}
public class TraktSettings : NetImportBaseSettings
{
public TraktSettings()
@ -19,10 +28,13 @@ namespace NzbDrone.Core.NetImport.Trakt
[FieldDefinition(0, Label = "Trakt API URL", HelpText = "Link to to Trakt API URL, do not change unless you know what you are doing.")]
public new string Link { get; set; }
[FieldDefinition(1, Label = "Trakt Username", HelpText = "Trakt Username the list belongs to.")]
[FieldDefinition(1, Label = "Trakt List Type", Type = FieldType.Select, SelectOptions = typeof(TraktListType), HelpText = "Trakt list type, custom or watchlist")]
public int ListType { get; set; }
[FieldDefinition(2, Label = "Trakt Username", HelpText = "Trakt Username the list belongs to.")]
public string Username { get; set; }
[FieldDefinition(2, Label = "Trakt List Name", HelpText = "Trakt List Name")]
[FieldDefinition(3, Label = "Trakt List Name", HelpText = "Required for Custom List")]
public string Listname { get; set; }
}

View File

@ -125,6 +125,7 @@
<Compile Include="Datastore\Migration\123_create_netimport_table.cs" />
<Compile Include="NetImport\Trakt\TraktAPI.cs" />
<Compile Include="NetImport\Trakt\TraktImport.cs" />
<Compile Include="NetImport\Trakt\TraktListType.cs" />
<Compile Include="NetImport\Trakt\TraktParser.cs" />
<Compile Include="NetImport\Trakt\TraktRequestGenerator.cs" />
<Compile Include="NetImport\Trakt\TraktSettings.cs" />