1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-09 12:32:31 +01:00

Fix typo and rename duplicate ListType property

This commit is contained in:
ta264 2020-01-15 21:41:57 +00:00 committed by Qstick
parent 377d788223
commit 9cf353b423
7 changed files with 179 additions and 42 deletions

View File

@ -13,18 +13,11 @@ namespace NzbDrone.Core.Datastore.Migration
[Migration(166)] [Migration(166)]
public class fix_tmdb_list_config : NzbDroneMigrationBase public class fix_tmdb_list_config : NzbDroneMigrationBase
{ {
protected override void MainDbUpgrade() private readonly JsonSerializerOptions _serializerSettings;
public fix_tmdb_list_config()
{ {
Execute.WithConnection(FixConfig); _serializerSettings = new JsonSerializerOptions
}
private void FixConfig(IDbConnection conn, IDbTransaction tran)
{
var rows = conn.Query<ProviderDefinition166>($"SELECT Id, Implementation, ConfigContract, Settings FROM NetImport WHERE Implementation = 'TMDbImport'");
var corrected = new List<ProviderDefinition166>();
var serializerSettings = new JsonSerializerOptions
{ {
AllowTrailingCommas = true, AllowTrailingCommas = true,
IgnoreNullValues = false, IgnoreNullValues = false,
@ -33,10 +26,102 @@ private void FixConfig(IDbConnection conn, IDbTransaction tran)
PropertyNamingPolicy = JsonNamingPolicy.CamelCase, PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true WriteIndented = true
}; };
}
protected override void MainDbUpgrade()
{
Execute.WithConnection(RenameTMDbListType);
Execute.WithConnection(RenameTraktListType);
Execute.WithConnection(FixConfig);
}
private void RenameTMDbListType(IDbConnection conn, IDbTransaction tran)
{
var rows = conn.Query<ProviderDefinition166>($"SELECT Id, Implementation, ConfigContract, Settings FROM NetImport WHERE Implementation = 'TMDbPopularImport'");
var corrected = new List<ProviderDefinition166>();
foreach (var row in rows) foreach (var row in rows)
{ {
var settings = JsonSerializer.Deserialize<TMDbSettings165>(row.Settings, serializerSettings); var settings = JsonSerializer.Deserialize<TMDbPopularSettings165>(row.Settings, _serializerSettings);
var newSettings = new TMDbPopularSettings166
{
TMDbListType = settings.ListType,
FilterCriteria = new TMDbFilterSettings166
{
MinVoteAverage = settings.FilterCriteria.MinVoteAverage,
MinVotes = settings.FilterCriteria.MinVotes,
Certification = settings.FilterCriteria.Ceritification,
IncludeGenreIds = settings.FilterCriteria.IncludeGenreIds,
ExcludeGenreIds = settings.FilterCriteria.ExcludeGenreIds,
LanguageCode = settings.FilterCriteria.LanguageCode
}
};
corrected.Add(new ProviderDefinition166
{
Id = row.Id,
Implementation = "TMDbPopularImport",
ConfigContract = "TMDbPopularSettings",
Settings = JsonSerializer.Serialize(newSettings, _serializerSettings)
});
}
var updateSql = "UPDATE NetImport SET Settings = @Settings WHERE Id = @Id";
conn.Execute(updateSql, corrected, transaction: tran);
}
private void RenameTraktListType(IDbConnection conn, IDbTransaction tran)
{
var rows = conn.Query<ProviderDefinition166>($"SELECT Id, Implementation, ConfigContract, Settings FROM NetImport WHERE Implementation = 'TraktImport'");
var corrected = new List<ProviderDefinition166>();
foreach (var row in rows)
{
var settings = JsonSerializer.Deserialize<TraktSettings165>(row.Settings, _serializerSettings);
var newSettings = new TraktSettings166
{
AccessToken = settings.AccessToken,
RefreshToken = settings.RefreshToken,
Expires = settings.Expires,
Link = settings.Link,
TraktListType = settings.ListType,
Username = settings.Username,
Listname = settings.Listname,
Rating = settings.Rating,
Certification = settings.Ceritification,
Genres = settings.Genres,
Years = settings.Years,
Limit = settings.Limit,
TraktAdditionalParameters = settings.TraktAdditionalParameters,
SignIn = settings.SignIn
};
corrected.Add(new ProviderDefinition166
{
Id = row.Id,
Implementation = "TraktImport",
ConfigContract = "TraktSettings",
Settings = JsonSerializer.Serialize(newSettings, _serializerSettings)
});
}
var updateSql = "UPDATE NetImport SET Settings = @Settings WHERE Id = @Id";
conn.Execute(updateSql, corrected, transaction: tran);
}
private void FixConfig(IDbConnection conn, IDbTransaction tran)
{
var rows = conn.Query<ProviderDefinition166>($"SELECT Id, Implementation, ConfigContract, Settings FROM NetImport WHERE Implementation = 'TMDbImport'");
var corrected = new List<ProviderDefinition166>();
foreach (var row in rows)
{
var settings = JsonSerializer.Deserialize<TMDbSettings165>(row.Settings, _serializerSettings);
if (settings.ListId.IsNotNullOrWhiteSpace()) if (settings.ListId.IsNotNullOrWhiteSpace())
{ {
@ -50,19 +135,19 @@ private void FixConfig(IDbConnection conn, IDbTransaction tran)
Id = row.Id, Id = row.Id,
Implementation = "TMDbListImport", Implementation = "TMDbListImport",
ConfigContract = "TMDbListSettings", ConfigContract = "TMDbListSettings",
Settings = JsonSerializer.Serialize(newSettings, serializerSettings) Settings = JsonSerializer.Serialize(newSettings, _serializerSettings)
}); });
} }
else else
{ {
var newSettings = new TMDbPopularSettings166 var newSettings = new TMDbPopularSettings166
{ {
ListType = settings.ListType, TMDbListType = settings.ListType,
FilterCriteria = new TMDbFilterSettings166 FilterCriteria = new TMDbFilterSettings166
{ {
MinVoteAverage = settings.MinVoteAverage, MinVoteAverage = settings.MinVoteAverage,
MinVotes = settings.MinVotes, MinVotes = settings.MinVotes,
Ceritification = settings.Ceritification, Certification = settings.Ceritification,
IncludeGenreIds = settings.IncludeGenreIds, IncludeGenreIds = settings.IncludeGenreIds,
ExcludeGenreIds = settings.ExcludeGenreIds, ExcludeGenreIds = settings.ExcludeGenreIds,
LanguageCode = settings.LanguageCode LanguageCode = settings.LanguageCode
@ -74,7 +159,7 @@ private void FixConfig(IDbConnection conn, IDbTransaction tran)
Id = row.Id, Id = row.Id,
Implementation = "TMDbPopularImport", Implementation = "TMDbPopularImport",
ConfigContract = "TMDbPopularSettings", ConfigContract = "TMDbPopularSettings",
Settings = JsonSerializer.Serialize(newSettings, serializerSettings) Settings = JsonSerializer.Serialize(newSettings, _serializerSettings)
}); });
} }
} }
@ -110,13 +195,13 @@ private class TMDbListSettings166
public string ListId { get; set; } public string ListId { get; set; }
} }
private class TMDbPopularSettings166 private class TMDbPopularSettings165
{ {
public int ListType { get; set; } public int ListType { get; set; }
public TMDbFilterSettings166 FilterCriteria { get; set; } public TMDbFilterSettings165 FilterCriteria { get; set; }
} }
private class TMDbFilterSettings166 private class TMDbFilterSettings165
{ {
public string MinVoteAverage { get; set; } public string MinVoteAverage { get; set; }
public string MinVotes { get; set; } public string MinVotes { get; set; }
@ -125,5 +210,57 @@ private class TMDbFilterSettings166
public string ExcludeGenreIds { get; set; } public string ExcludeGenreIds { get; set; }
public int LanguageCode { get; set; } public int LanguageCode { get; set; }
} }
private class TMDbPopularSettings166
{
public int TMDbListType { get; set; }
public TMDbFilterSettings166 FilterCriteria { get; set; }
}
private class TMDbFilterSettings166
{
public string MinVoteAverage { get; set; }
public string MinVotes { get; set; }
public string Certification { get; set; }
public string IncludeGenreIds { get; set; }
public string ExcludeGenreIds { get; set; }
public int LanguageCode { get; set; }
}
private class TraktSettings165
{
public string AccessToken { get; set; }
public string RefreshToken { get; set; }
public DateTime Expires { get; set; }
public string Link { get; set; }
public int ListType { get; set; }
public string Username { get; set; }
public string Listname { get; set; }
public string Rating { get; set; }
public string Ceritification { get; set; }
public string Genres { get; set; }
public string Years { get; set; }
public int Limit { get; set; }
public string TraktAdditionalParameters { get; set; }
public string SignIn { get; set; }
}
private class TraktSettings166
{
public string AccessToken { get; set; }
public string RefreshToken { get; set; }
public DateTime Expires { get; set; }
public string Link { get; set; }
public int TraktListType { get; set; }
public string Username { get; set; }
public string Listname { get; set; }
public string Rating { get; set; }
public string Certification { get; set; }
public string Genres { get; set; }
public string Years { get; set; }
public int Limit { get; set; }
public string TraktAdditionalParameters { get; set; }
public string SignIn { get; set; }
}
} }
} }

View File

@ -33,7 +33,7 @@ private IEnumerable<NetImportRequest> GetMoviesRequests()
{ {
var minVoteCount = Settings.FilterCriteria.MinVotes; var minVoteCount = Settings.FilterCriteria.MinVotes;
var minVoteAverage = Settings.FilterCriteria.MinVoteAverage; var minVoteAverage = Settings.FilterCriteria.MinVoteAverage;
var ceritification = Settings.FilterCriteria.Ceritification; var certification = Settings.FilterCriteria.Certification;
var includeGenreIds = Settings.FilterCriteria.IncludeGenreIds; var includeGenreIds = Settings.FilterCriteria.IncludeGenreIds;
var excludeGenreIds = Settings.FilterCriteria.ExcludeGenreIds; var excludeGenreIds = Settings.FilterCriteria.ExcludeGenreIds;
var languageCode = (TMDbLanguageCodes)Settings.FilterCriteria.LanguageCode; var languageCode = (TMDbLanguageCodes)Settings.FilterCriteria.LanguageCode;
@ -48,7 +48,7 @@ private IEnumerable<NetImportRequest> GetMoviesRequests()
.SetSegment("id", "") .SetSegment("id", "")
.SetSegment("secondaryRoute", "movie"); .SetSegment("secondaryRoute", "movie");
switch (Settings.ListType) switch (Settings.TMDbListType)
{ {
case (int)TMDbPopularListType.Theaters: case (int)TMDbPopularListType.Theaters:
requestBuilder.AddQueryParam("primary_release.gte", threeMonthsAgo) requestBuilder.AddQueryParam("primary_release.gte", threeMonthsAgo)
@ -66,9 +66,9 @@ private IEnumerable<NetImportRequest> GetMoviesRequests()
break; break;
} }
if (ceritification.IsNotNullOrWhiteSpace()) if (certification.IsNotNullOrWhiteSpace())
{ {
requestBuilder.AddQueryParam("certification", ceritification) requestBuilder.AddQueryParam("certification", certification)
.AddQueryParam("certification_country", "US"); .AddQueryParam("certification_country", "US");
} }

View File

@ -8,7 +8,7 @@ public class TMDbPopularSettingsValidator : TMDbSettingsBaseValidator<TMDbPopula
public TMDbPopularSettingsValidator() public TMDbPopularSettingsValidator()
: base() : base()
{ {
RuleFor(c => c.ListType).NotEmpty(); RuleFor(c => c.TMDbListType).NotEmpty();
RuleFor(c => c.FilterCriteria).SetValidator(_ => new TMDbFilterSettingsValidator()); RuleFor(c => c.FilterCriteria).SetValidator(_ => new TMDbFilterSettingsValidator());
} }
@ -20,11 +20,11 @@ public class TMDbPopularSettings : TMDbSettingsBase<TMDbPopularSettings>
public TMDbPopularSettings() public TMDbPopularSettings()
{ {
ListType = (int)TMDbPopularListType.Popular; TMDbListType = (int)TMDbPopularListType.Popular;
} }
[FieldDefinition(1, Label = "List Type", Type = FieldType.Select, SelectOptions = typeof(TMDbPopularListType), HelpText = "Type of list your seeking to import from")] [FieldDefinition(1, Label = "List Type", Type = FieldType.Select, SelectOptions = typeof(TMDbPopularListType), HelpText = "Type of list your seeking to import from")]
public int ListType { get; set; } public int TMDbListType { get; set; }
[FieldDefinition(2)] [FieldDefinition(2)]
public TMDbFilterSettings FilterCriteria { get; } = new TMDbFilterSettings(); public TMDbFilterSettings FilterCriteria { get; } = new TMDbFilterSettings();

View File

@ -22,9 +22,9 @@ public TMDbFilterSettingsValidator()
.WithMessage("Minimum votes must be greater than 0"); .WithMessage("Minimum votes must be greater than 0");
// Any valid certification // Any valid certification
RuleFor(c => c.Ceritification) RuleFor(c => c.Certification)
.Matches(@"^\bNR\b|\bG\b|\bPG\b|\bPG\-13\b|\bR\b|\bNC\-17\b$", RegexOptions.IgnoreCase) .Matches(@"^\bNR\b|\bG\b|\bPG\b|\bPG\-13\b|\bR\b|\bNC\-17\b$", RegexOptions.IgnoreCase)
.When(c => c.Ceritification.IsNotNullOrWhiteSpace()) .When(c => c.Certification.IsNotNullOrWhiteSpace())
.WithMessage("Not a valid certification"); .WithMessage("Not a valid certification");
// CSV of numbers // CSV of numbers
@ -58,8 +58,8 @@ public TMDbFilterSettings()
[FieldDefinition(2, Label = "Minimum Number of Votes", HelpText = "Filter movies by number of votes")] [FieldDefinition(2, Label = "Minimum Number of Votes", HelpText = "Filter movies by number of votes")]
public string MinVotes { get; set; } public string MinVotes { get; set; }
[FieldDefinition(3, Label = "Certification", HelpText = "Filter movies by a single ceritification (NR,G,PG,PG-13,R,NC-17)")] [FieldDefinition(3, Label = "Certification", HelpText = "Filter movies by a single certification (NR,G,PG,PG-13,R,NC-17)")]
public string Ceritification { get; set; } public string Certification { get; set; }
[FieldDefinition(4, Label = "Include Genre Ids", HelpText = "Filter movies by TMDb Genre Ids (Comma Separated)")] [FieldDefinition(4, Label = "Include Genre Ids", HelpText = "Filter movies by TMDb Genre Ids (Comma Separated)")]
public string IncludeGenreIds { get; set; } public string IncludeGenreIds { get; set; }

View File

@ -27,7 +27,7 @@ public TraktParser(TraktSettings settings)
return movies; return movies;
} }
if (_settings.ListType == (int)TraktListType.Popular) if (_settings.TraktListType == (int)TraktListType.Popular)
{ {
var jsonResponse = JsonConvert.DeserializeObject<List<Movie>>(_importResponse.Content); var jsonResponse = JsonConvert.DeserializeObject<List<Movie>>(_importResponse.Content);

View File

@ -37,9 +37,9 @@ private IEnumerable<NetImportRequest> GetMovies(string searchParameters)
{ {
var link = Settings.Link.Trim(); var link = Settings.Link.Trim();
var filtersAndLimit = $"?years={Settings.Years}&genres={Settings.Genres.ToLower()}&ratings={Settings.Rating}&certifications={Settings.Ceritification.ToLower()}&limit={Settings.Limit}{Settings.TraktAdditionalParameters}"; var filtersAndLimit = $"?years={Settings.Years}&genres={Settings.Genres.ToLower()}&ratings={Settings.Rating}&certifications={Settings.Certification.ToLower()}&limit={Settings.Limit}{Settings.TraktAdditionalParameters}";
switch (Settings.ListType) switch (Settings.TraktListType)
{ {
case (int)TraktListType.UserCustomList: case (int)TraktListType.UserCustomList:
var listName = Parser.Parser.ToUrlSlug(Settings.Listname.Trim()); var listName = Parser.Parser.ToUrlSlug(Settings.Listname.Trim());

View File

@ -20,13 +20,13 @@ public TraktSettingsValidator()
// List name required for UserCustomList // List name required for UserCustomList
RuleFor(c => c.Listname) RuleFor(c => c.Listname)
.Matches(@"^[A-Za-z0-9\-_]+$", RegexOptions.IgnoreCase) .Matches(@"^[A-Za-z0-9\-_]+$", RegexOptions.IgnoreCase)
.When(c => c.ListType == (int)TraktListType.UserCustomList) .When(c => c.TraktListType == (int)TraktListType.UserCustomList)
.WithMessage("List name is required when using Custom Trakt Lists"); .WithMessage("List name is required when using Custom Trakt Lists");
// Username required for UserWatchedList/UserWatchList // Username required for UserWatchedList/UserWatchList
RuleFor(c => c.Username) RuleFor(c => c.Username)
.Matches(@"^[A-Za-z0-9\-_]+$", RegexOptions.IgnoreCase) .Matches(@"^[A-Za-z0-9\-_]+$", RegexOptions.IgnoreCase)
.When(c => c.ListType == (int)TraktListType.UserWatchedList || c.ListType == (int)TraktListType.UserWatchList) .When(c => c.TraktListType == (int)TraktListType.UserWatchedList || c.TraktListType == (int)TraktListType.UserWatchList)
.WithMessage("Username is required when using User Trakt Lists"); .WithMessage("Username is required when using User Trakt Lists");
// Loose validation @TODO // Loose validation @TODO
@ -36,9 +36,9 @@ public TraktSettingsValidator()
.WithMessage("Not a valid rating"); .WithMessage("Not a valid rating");
// Any valid certification // Any valid certification
RuleFor(c => c.Ceritification) RuleFor(c => c.Certification)
.Matches(@"^\bNR\b|\bG\b|\bPG\b|\bPG\-13\b|\bR\b|\bNC\-17\b$", RegexOptions.IgnoreCase) .Matches(@"^\bNR\b|\bG\b|\bPG\b|\bPG\-13\b|\bR\b|\bNC\-17\b$", RegexOptions.IgnoreCase)
.When(c => c.Ceritification.IsNotNullOrWhiteSpace()) .When(c => c.Certification.IsNotNullOrWhiteSpace())
.WithMessage("Not a valid cerification"); .WithMessage("Not a valid cerification");
// Loose validation @TODO // Loose validation @TODO
@ -64,11 +64,11 @@ public TraktSettings()
{ {
Link = "https://api.trakt.tv"; Link = "https://api.trakt.tv";
SignIn = "startOAuth"; SignIn = "startOAuth";
ListType = (int)TraktListType.Popular; TraktListType = (int)Trakt.TraktListType.Popular;
Username = ""; Username = "";
Listname = ""; Listname = "";
Rating = "0-100"; Rating = "0-100";
Ceritification = "NR,G,PG,PG-13,R,NC-17"; Certification = "NR,G,PG,PG-13,R,NC-17";
Genres = ""; Genres = "";
Years = ""; Years = "";
Limit = 100; Limit = 100;
@ -92,7 +92,7 @@ public TraktSettings()
public string Link { get; set; } public string Link { get; set; }
[FieldDefinition(1, Label = "List Type", Type = FieldType.Select, SelectOptions = typeof(TraktListType), HelpText = "Trakt list type")] [FieldDefinition(1, Label = "List Type", Type = FieldType.Select, SelectOptions = typeof(TraktListType), HelpText = "Trakt list type")]
public int ListType { get; set; } public int TraktListType { get; set; }
[FieldDefinition(2, Label = "Username", HelpText = "Required for User List (Ignores Filtering Options)")] [FieldDefinition(2, Label = "Username", HelpText = "Required for User List (Ignores Filtering Options)")]
public string Username { get; set; } public string Username { get; set; }
@ -103,8 +103,8 @@ public TraktSettings()
[FieldDefinition(4, Label = "Rating", HelpText = "Filter movies by rating range (0-100)")] [FieldDefinition(4, Label = "Rating", HelpText = "Filter movies by rating range (0-100)")]
public string Rating { get; set; } public string Rating { get; set; }
[FieldDefinition(5, Label = "Ceritification", HelpText = "Filter movies by a ceritification (NR,G,PG,PG-13,R,NC-17), (Comma Separated)")] [FieldDefinition(5, Label = "Certification", HelpText = "Filter movies by a certification (NR,G,PG,PG-13,R,NC-17), (Comma Separated)")]
public string Ceritification { get; set; } public string Certification { get; set; }
[FieldDefinition(6, Label = "Genres", HelpText = "Filter movies by Trakt Genre Slug (Comma Separated)")] [FieldDefinition(6, Label = "Genres", HelpText = "Filter movies by Trakt Genre Slug (Comma Separated)")]
public string Genres { get; set; } public string Genres { get; set; }