New: Add Watched filter type to Trakt User Import List
This commit is contained in:
parent
03f5174a4b
commit
a131c88d5f
|
@ -26,24 +26,24 @@ namespace NzbDrone.Core.ImportLists.Trakt.Popular
|
||||||
return listItems;
|
return listItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
var jsonResponse = new List<TraktSeriesResource>();
|
var traktSeries = new List<TraktSeriesResource>();
|
||||||
|
|
||||||
if (_settings.TraktListType == (int)TraktPopularListType.Popular)
|
if (_settings.TraktListType == (int)TraktPopularListType.Popular)
|
||||||
{
|
{
|
||||||
jsonResponse = STJson.Deserialize<List<TraktSeriesResource>>(_importResponse.Content);
|
traktSeries = STJson.Deserialize<List<TraktSeriesResource>>(_importResponse.Content);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jsonResponse = STJson.Deserialize<List<TraktResponse>>(_importResponse.Content).SelectList(c => c.Show);
|
traktSeries = STJson.Deserialize<List<TraktResponse>>(_importResponse.Content).SelectList(c => c.Show);
|
||||||
}
|
}
|
||||||
|
|
||||||
// no movies were return
|
// no series were returned
|
||||||
if (jsonResponse == null)
|
if (traktSeries == null)
|
||||||
{
|
{
|
||||||
return listItems;
|
return listItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var series in jsonResponse)
|
foreach (var series in traktSeries)
|
||||||
{
|
{
|
||||||
listItems.AddIfNotNull(new ImportListItemInfo()
|
listItems.AddIfNotNull(new ImportListItemInfo()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using Newtonsoft.Json;
|
using System.Collections.Generic;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace NzbDrone.Core.ImportLists.Trakt
|
namespace NzbDrone.Core.ImportLists.Trakt
|
||||||
{
|
{
|
||||||
|
@ -16,6 +17,8 @@ namespace NzbDrone.Core.ImportLists.Trakt
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
public int? Year { get; set; }
|
public int? Year { get; set; }
|
||||||
public TraktSeriesIdsResource Ids { get; set; }
|
public TraktSeriesIdsResource Ids { get; set; }
|
||||||
|
[JsonPropertyName("aired_episodes")]
|
||||||
|
public int AiredEpisodes { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TraktResponse
|
public class TraktResponse
|
||||||
|
@ -23,13 +26,29 @@ namespace NzbDrone.Core.ImportLists.Trakt
|
||||||
public TraktSeriesResource Show { get; set; }
|
public TraktSeriesResource Show { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class TraktWatchedEpisodeResource
|
||||||
|
{
|
||||||
|
public int? Plays { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TraktWatchedSeasonResource
|
||||||
|
{
|
||||||
|
public int? Number { get; set; }
|
||||||
|
public List<TraktWatchedEpisodeResource> Episodes { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TraktWatchedResponse : TraktResponse
|
||||||
|
{
|
||||||
|
public List<TraktWatchedSeasonResource> Seasons { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public class RefreshRequestResponse
|
public class RefreshRequestResponse
|
||||||
{
|
{
|
||||||
[JsonProperty("access_token")]
|
[JsonPropertyName("access_token")]
|
||||||
public string AccessToken { get; set; }
|
public string AccessToken { get; set; }
|
||||||
[JsonProperty("expires_in")]
|
[JsonPropertyName("expires_in")]
|
||||||
public int ExpiresIn { get; set; }
|
public int ExpiresIn { get; set; }
|
||||||
[JsonProperty("refresh_token")]
|
[JsonPropertyName("refresh_token")]
|
||||||
public string RefreshToken { get; set; }
|
public string RefreshToken { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,20 +22,20 @@ namespace NzbDrone.Core.ImportLists.Trakt
|
||||||
return series;
|
return series;
|
||||||
}
|
}
|
||||||
|
|
||||||
var jsonResponse = STJson.Deserialize<List<TraktResponse>>(_importResponse.Content);
|
var traktResponses = STJson.Deserialize<List<TraktResponse>>(_importResponse.Content);
|
||||||
|
|
||||||
// no series were return
|
// no series were returned
|
||||||
if (jsonResponse == null)
|
if (traktResponses == null)
|
||||||
{
|
{
|
||||||
return series;
|
return series;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var show in jsonResponse)
|
foreach (var traktResponse in traktResponses)
|
||||||
{
|
{
|
||||||
series.AddIfNotNull(new ImportListItemInfo()
|
series.AddIfNotNull(new ImportListItemInfo()
|
||||||
{
|
{
|
||||||
Title = show.Show.Title,
|
Title = traktResponse.Show.Title,
|
||||||
TvdbId = show.Show.Ids.Tvdb.GetValueOrDefault()
|
TvdbId = traktResponse.Show.Ids.Tvdb.GetValueOrDefault()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,11 @@ namespace NzbDrone.Core.ImportLists.Trakt.User
|
||||||
|
|
||||||
public override string Name => "Trakt User";
|
public override string Name => "Trakt User";
|
||||||
|
|
||||||
|
public override IParseImportListResponse GetParser()
|
||||||
|
{
|
||||||
|
return new TraktUserParser(Settings);
|
||||||
|
}
|
||||||
|
|
||||||
public override IImportListRequestGenerator GetRequestGenerator()
|
public override IImportListRequestGenerator GetRequestGenerator()
|
||||||
{
|
{
|
||||||
return new TraktUserRequestGenerator()
|
return new TraktUserRequestGenerator()
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Common.Serializer;
|
||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.ImportLists.Trakt.User
|
||||||
|
{
|
||||||
|
public class TraktUserParser : TraktParser
|
||||||
|
{
|
||||||
|
private readonly TraktUserSettings _settings;
|
||||||
|
private ImportListResponse _importResponse;
|
||||||
|
|
||||||
|
public TraktUserParser(TraktUserSettings settings)
|
||||||
|
{
|
||||||
|
_settings = settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IList<ImportListItemInfo> ParseResponse(ImportListResponse importResponse)
|
||||||
|
{
|
||||||
|
_importResponse = importResponse;
|
||||||
|
|
||||||
|
var listItems = new List<ImportListItemInfo>();
|
||||||
|
|
||||||
|
if (!PreProcess(_importResponse))
|
||||||
|
{
|
||||||
|
return listItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
var traktSeries = new List<TraktSeriesResource>();
|
||||||
|
|
||||||
|
if (_settings.TraktListType == (int)TraktUserListType.UserWatchedList)
|
||||||
|
{
|
||||||
|
var jsonWatchedResponse = STJson.Deserialize<List<TraktWatchedResponse>>(_importResponse.Content);
|
||||||
|
|
||||||
|
switch (_settings.TraktWatchedListType)
|
||||||
|
{
|
||||||
|
case (int)TraktUserWatchedListType.InProgress:
|
||||||
|
traktSeries = jsonWatchedResponse.Where(c => c.Seasons.Where(s => s.Number > 0).Sum(s => s.Episodes.Count) < c.Show.AiredEpisodes).SelectList(c => c.Show);
|
||||||
|
break;
|
||||||
|
case (int)TraktUserWatchedListType.CompletelyWatched:
|
||||||
|
traktSeries = jsonWatchedResponse.Where(c => c.Seasons.Where(s => s.Number > 0).Sum(s => s.Episodes.Count) == c.Show.AiredEpisodes).SelectList(c => c.Show);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
traktSeries = jsonWatchedResponse.SelectList(c => c.Show);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
traktSeries = STJson.Deserialize<List<TraktResponse>>(_importResponse.Content).SelectList(c => c.Show);
|
||||||
|
}
|
||||||
|
|
||||||
|
// no series were returned
|
||||||
|
if (traktSeries == null)
|
||||||
|
{
|
||||||
|
return listItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var series in traktSeries)
|
||||||
|
{
|
||||||
|
listItems.AddIfNotNull(new ImportListItemInfo()
|
||||||
|
{
|
||||||
|
Title = series.Title,
|
||||||
|
TvdbId = series.Ids.Tvdb.GetValueOrDefault(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return listItems;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,7 +30,7 @@ namespace NzbDrone.Core.ImportLists.Trakt.User
|
||||||
link += $"/users/{userName}/watchlist/shows?limit={Settings.Limit}";
|
link += $"/users/{userName}/watchlist/shows?limit={Settings.Limit}";
|
||||||
break;
|
break;
|
||||||
case (int)TraktUserListType.UserWatchedList:
|
case (int)TraktUserListType.UserWatchedList:
|
||||||
link += $"/users/{userName}/watched/shows?limit={Settings.Limit}";
|
link += $"/users/{userName}/watched/shows?extended=full&limit={Settings.Limit}";
|
||||||
break;
|
break;
|
||||||
case (int)TraktUserListType.UserCollectionList:
|
case (int)TraktUserListType.UserCollectionList:
|
||||||
link += $"/users/{userName}/collection/shows?limit={Settings.Limit}";
|
link += $"/users/{userName}/collection/shows?limit={Settings.Limit}";
|
||||||
|
|
|
@ -9,6 +9,7 @@ namespace NzbDrone.Core.ImportLists.Trakt.User
|
||||||
: base()
|
: base()
|
||||||
{
|
{
|
||||||
RuleFor(c => c.TraktListType).NotNull();
|
RuleFor(c => c.TraktListType).NotNull();
|
||||||
|
RuleFor(c => c.TraktWatchedListType).NotNull();
|
||||||
RuleFor(c => c.AuthUser).NotEmpty();
|
RuleFor(c => c.AuthUser).NotEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,12 +21,16 @@ namespace NzbDrone.Core.ImportLists.Trakt.User
|
||||||
public TraktUserSettings()
|
public TraktUserSettings()
|
||||||
{
|
{
|
||||||
TraktListType = (int)TraktUserListType.UserWatchList;
|
TraktListType = (int)TraktUserListType.UserWatchList;
|
||||||
|
TraktWatchedListType = (int)TraktUserWatchedListType.All;
|
||||||
}
|
}
|
||||||
|
|
||||||
[FieldDefinition(1, Label = "List Type", Type = FieldType.Select, SelectOptions = typeof(TraktUserListType), HelpText = "Type of list you're seeking to import from")]
|
[FieldDefinition(1, Label = "List Type", Type = FieldType.Select, SelectOptions = typeof(TraktUserListType), HelpText = "Type of list you're seeking to import from")]
|
||||||
public int TraktListType { get; set; }
|
public int TraktListType { get; set; }
|
||||||
|
|
||||||
[FieldDefinition(2, Label = "Username", HelpText = "Username for the List to import from (empty to use Auth User)")]
|
[FieldDefinition(2, Label = "Watched List Filter", Type = FieldType.Select, SelectOptions = typeof(TraktUserWatchedListType), HelpText = "If List Type is Watched. Series do you want to import from")]
|
||||||
|
public int TraktWatchedListType { get; set; }
|
||||||
|
|
||||||
|
[FieldDefinition(3, Label = "Username", HelpText = "Username for the List to import from (empty to use Auth User)")]
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.ImportLists.Trakt.User
|
||||||
|
{
|
||||||
|
public enum TraktUserWatchedListType
|
||||||
|
{
|
||||||
|
[EnumMember(Value = "All")]
|
||||||
|
All = 0,
|
||||||
|
[EnumMember(Value = "In Progress")]
|
||||||
|
InProgress = 1,
|
||||||
|
[EnumMember(Value = "100% Watched")]
|
||||||
|
CompletelyWatched = 2
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue