mirror of
https://github.com/Sonarr/Sonarr
synced 2026-05-09 05:40:53 +02:00
add rating, genres, years to all trakt import lists
This commit is contained in:
parent
fdda9abcbb
commit
824605325c
5 changed files with 100 additions and 2 deletions
|
|
@ -24,6 +24,26 @@ private IEnumerable<ImportListRequest> GetSeriesRequest()
|
|||
|
||||
link += $"/users/{Settings.Username.Trim()}/lists/{Settings.Listname.ToUrlSlug()}/items/show,season,episode?limit={Settings.Limit}";
|
||||
|
||||
if (Settings.Rating.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
link += $"&ratings={Settings.Rating}";
|
||||
}
|
||||
|
||||
if (Settings.Genres.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
link += $"&genres={Settings.Genres.ToLower()}";
|
||||
}
|
||||
|
||||
if (Settings.Years.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
link += $"&years={Settings.Years}";
|
||||
}
|
||||
|
||||
if (Settings.TraktAdditionalParameters.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
link += $"&{Settings.TraktAdditionalParameters.TrimStart('?').TrimStart('&')}";
|
||||
}
|
||||
|
||||
var request = new ImportListRequest(link, HttpAccept.Json);
|
||||
|
||||
request.HttpRequest.Headers.Add("trakt-api-version", "2");
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
using System.Text.RegularExpressions;
|
||||
using FluentValidation;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.Validation;
|
||||
|
||||
|
|
@ -10,6 +12,16 @@ public TraktListSettingsValidator()
|
|||
{
|
||||
RuleFor(c => c.Username).NotEmpty();
|
||||
RuleFor(c => c.Listname).NotEmpty();
|
||||
|
||||
RuleFor(c => c.Rating)
|
||||
.Matches(@"^\d+\-\d+$", RegexOptions.IgnoreCase)
|
||||
.When(c => c.Rating.IsNotNullOrWhiteSpace())
|
||||
.WithMessage("Not a valid rating");
|
||||
|
||||
RuleFor(c => c.Years)
|
||||
.Matches(@"^\d+(\-\d+)?$", RegexOptions.IgnoreCase)
|
||||
.When(c => c.Years.IsNotNullOrWhiteSpace())
|
||||
.WithMessage("Not a valid year or range of years");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -23,6 +35,18 @@ public class TraktListSettings : TraktSettingsBase<TraktListSettings>
|
|||
[FieldDefinition(2, Label = "ImportListsTraktSettingsListName", HelpText = "ImportListsTraktSettingsListNameHelpText")]
|
||||
public string Listname { get; set; }
|
||||
|
||||
[FieldDefinition(3, Label = "ImportListsTraktSettingsRating", HelpText = "ImportListsTraktSettingsRatingSeriesHelpText")]
|
||||
public string Rating { get; set; }
|
||||
|
||||
[FieldDefinition(4, Label = "ImportListsTraktSettingsGenres", HelpText = "ImportListsTraktSettingsGenresSeriesHelpText")]
|
||||
public string Genres { get; set; }
|
||||
|
||||
[FieldDefinition(5, Label = "ImportListsTraktSettingsYears", HelpText = "ImportListsTraktSettingsYearsSeriesHelpText")]
|
||||
public string Years { get; set; }
|
||||
|
||||
[FieldDefinition(6, Label = "ImportListsTraktSettingsAdditionalParameters", HelpText = "ImportListsTraktSettingsAdditionalParametersHelpText", Advanced = true)]
|
||||
public string TraktAdditionalParameters { get; set; }
|
||||
|
||||
public override NzbDroneValidationResult Validate()
|
||||
{
|
||||
return new NzbDroneValidationResult(Validator.Validate(this));
|
||||
|
|
|
|||
|
|
@ -63,11 +63,41 @@ private IEnumerable<ImportListRequest> GetSeriesRequest()
|
|||
.SetHeader("trakt-api-key", _clientId)
|
||||
.AddQueryParam("limit", _settings.Limit.ToString());
|
||||
|
||||
if (_settings.Rating.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
requestBuilder.AddQueryParam("ratings", _settings.Rating);
|
||||
}
|
||||
|
||||
if (_settings.Genres.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
requestBuilder.AddQueryParam("genres", _settings.Genres.ToLower());
|
||||
}
|
||||
|
||||
if (_settings.Years.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
requestBuilder.AddQueryParam("years", _settings.Years);
|
||||
}
|
||||
|
||||
if (_settings.AccessToken.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
requestBuilder.SetHeader("Authorization", $"Bearer {_settings.AccessToken}");
|
||||
}
|
||||
|
||||
if (_settings.TraktAdditionalParameters.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
var additionalParams = _settings.TraktAdditionalParameters.TrimStart('?').TrimStart('&');
|
||||
|
||||
foreach (var param in additionalParams.Split('&'))
|
||||
{
|
||||
var parts = param.Split('=', 2);
|
||||
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
requestBuilder.AddQueryParam(parts[0], parts[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
yield return new ImportListRequest(requestBuilder.Build());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
using System.Text.RegularExpressions;
|
||||
using FluentValidation;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.Validation;
|
||||
|
||||
|
|
@ -11,6 +13,16 @@ public TraktUserSettingsValidator()
|
|||
RuleFor(c => c.TraktListType).NotNull();
|
||||
RuleFor(c => c.TraktWatchedListType).NotNull();
|
||||
RuleFor(c => c.AuthUser).NotEmpty();
|
||||
|
||||
RuleFor(c => c.Rating)
|
||||
.Matches(@"^\d+\-\d+$", RegexOptions.IgnoreCase)
|
||||
.When(c => c.Rating.IsNotNullOrWhiteSpace())
|
||||
.WithMessage("Not a valid rating");
|
||||
|
||||
RuleFor(c => c.Years)
|
||||
.Matches(@"^\d+(\-\d+)?$", RegexOptions.IgnoreCase)
|
||||
.When(c => c.Years.IsNotNullOrWhiteSpace())
|
||||
.WithMessage("Not a valid year or range of years");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -37,6 +49,18 @@ public TraktUserSettings()
|
|||
[FieldDefinition(4, Label = "Username", HelpText = "ImportListsTraktSettingsUserListUsernameHelpText")]
|
||||
public string Username { get; set; }
|
||||
|
||||
[FieldDefinition(5, Label = "ImportListsTraktSettingsRating", HelpText = "ImportListsTraktSettingsRatingSeriesHelpText")]
|
||||
public string Rating { get; set; }
|
||||
|
||||
[FieldDefinition(6, Label = "ImportListsTraktSettingsGenres", HelpText = "ImportListsTraktSettingsGenresSeriesHelpText")]
|
||||
public string Genres { get; set; }
|
||||
|
||||
[FieldDefinition(7, Label = "ImportListsTraktSettingsYears", HelpText = "ImportListsTraktSettingsYearsSeriesHelpText")]
|
||||
public string Years { get; set; }
|
||||
|
||||
[FieldDefinition(8, Label = "ImportListsTraktSettingsAdditionalParameters", HelpText = "ImportListsTraktSettingsAdditionalParametersHelpText", Advanced = true)]
|
||||
public string TraktAdditionalParameters { get; set; }
|
||||
|
||||
public override NzbDroneValidationResult Validate()
|
||||
{
|
||||
return new NzbDroneValidationResult(Validator.Validate(this));
|
||||
|
|
|
|||
|
|
@ -943,7 +943,7 @@
|
|||
"ImportListsTraktSettingsAdditionalParametersHelpText": "Additional Trakt API parameters",
|
||||
"ImportListsTraktSettingsAuthenticateWithTrakt": "Authenticate with Trakt",
|
||||
"ImportListsTraktSettingsGenres": "Genres",
|
||||
"ImportListsTraktSettingsGenresSeriesHelpText": "Filter series by Trakt Genre Slug (Comma Separated) Only for Popular Lists",
|
||||
"ImportListsTraktSettingsGenresSeriesHelpText": "Filter series by Trakt Genre (action,-romance,-anime)",
|
||||
"ImportListsTraktSettingsLimit": "Limit",
|
||||
"ImportListsTraktSettingsLimitSeriesHelpText": "Limit the number of series to get",
|
||||
"ImportListsTraktSettingsListName": "List Name",
|
||||
|
|
@ -978,7 +978,7 @@
|
|||
"ImportListsTraktSettingsWatchedListTypeCompleted": "100% Watched",
|
||||
"ImportListsTraktSettingsWatchedListTypeInProgress": "In Progress",
|
||||
"ImportListsTraktSettingsYears": "Years",
|
||||
"ImportListsTraktSettingsYearsSeriesHelpText": "Filter series by year or year range",
|
||||
"ImportListsTraktSettingsYearsSeriesHelpText": "Filter series by minimum year or year range (1990-2000)",
|
||||
"ImportListsValidationInvalidApiKey": "API Key is invalid",
|
||||
"ImportListsValidationTestFailed": "Test was aborted due to an error: {exceptionMessage}",
|
||||
"ImportListsValidationUnableToConnectException": "Unable to connect to import list: {exceptionMessage}. Check the log surrounding this error for details.",
|
||||
|
|
|
|||
Loading…
Reference in a new issue