Fix typo and rename duplicate ListType property

pull/2/head
ta264 5 years ago committed by Qstick
parent 377d788223
commit 9cf353b423

@ -13,18 +13,11 @@ namespace NzbDrone.Core.Datastore.Migration
[Migration(166)]
public class fix_tmdb_list_config : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Execute.WithConnection(FixConfig);
}
private readonly JsonSerializerOptions _serializerSettings;
private void FixConfig(IDbConnection conn, IDbTransaction tran)
public fix_tmdb_list_config()
{
var rows = conn.Query<ProviderDefinition166>($"SELECT Id, Implementation, ConfigContract, Settings FROM NetImport WHERE Implementation = 'TMDbImport'");
var corrected = new List<ProviderDefinition166>();
var serializerSettings = new JsonSerializerOptions
_serializerSettings = new JsonSerializerOptions
{
AllowTrailingCommas = true,
IgnoreNullValues = false,
@ -33,10 +26,102 @@ namespace NzbDrone.Core.Datastore.Migration
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
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)
{
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())
{
@ -50,19 +135,19 @@ namespace NzbDrone.Core.Datastore.Migration
Id = row.Id,
Implementation = "TMDbListImport",
ConfigContract = "TMDbListSettings",
Settings = JsonSerializer.Serialize(newSettings, serializerSettings)
Settings = JsonSerializer.Serialize(newSettings, _serializerSettings)
});
}
else
{
var newSettings = new TMDbPopularSettings166
{
ListType = settings.ListType,
TMDbListType = settings.ListType,
FilterCriteria = new TMDbFilterSettings166
{
MinVoteAverage = settings.MinVoteAverage,
MinVotes = settings.MinVotes,
Ceritification = settings.Ceritification,
Certification = settings.Ceritification,
IncludeGenreIds = settings.IncludeGenreIds,
ExcludeGenreIds = settings.ExcludeGenreIds,
LanguageCode = settings.LanguageCode
@ -74,7 +159,7 @@ namespace NzbDrone.Core.Datastore.Migration
Id = row.Id,
Implementation = "TMDbPopularImport",
ConfigContract = "TMDbPopularSettings",
Settings = JsonSerializer.Serialize(newSettings, serializerSettings)
Settings = JsonSerializer.Serialize(newSettings, _serializerSettings)
});
}
}
@ -110,9 +195,25 @@ namespace NzbDrone.Core.Datastore.Migration
public string ListId { get; set; }
}
private class TMDbPopularSettings166
private class TMDbPopularSettings165
{
public int ListType { get; set; }
public TMDbFilterSettings165 FilterCriteria { get; set; }
}
private class TMDbFilterSettings165
{
public string MinVoteAverage { get; set; }
public string MinVotes { get; set; }
public string Ceritification { get; set; }
public string IncludeGenreIds { get; set; }
public string ExcludeGenreIds { get; set; }
public int LanguageCode { get; set; }
}
private class TMDbPopularSettings166
{
public int TMDbListType { get; set; }
public TMDbFilterSettings166 FilterCriteria { get; set; }
}
@ -120,10 +221,46 @@ namespace NzbDrone.Core.Datastore.Migration
{
public string MinVoteAverage { get; set; }
public string MinVotes { get; set; }
public string Ceritification { 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; }
}
}
}

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

@ -8,7 +8,7 @@ namespace NzbDrone.Core.NetImport.TMDb.Popular
public TMDbPopularSettingsValidator()
: base()
{
RuleFor(c => c.ListType).NotEmpty();
RuleFor(c => c.TMDbListType).NotEmpty();
RuleFor(c => c.FilterCriteria).SetValidator(_ => new TMDbFilterSettingsValidator());
}
@ -20,11 +20,11 @@ namespace NzbDrone.Core.NetImport.TMDb.Popular
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")]
public int ListType { get; set; }
public int TMDbListType { get; set; }
[FieldDefinition(2)]
public TMDbFilterSettings FilterCriteria { get; } = new TMDbFilterSettings();

@ -22,9 +22,9 @@ namespace NzbDrone.Core.NetImport.TMDb
.WithMessage("Minimum votes must be greater than 0");
// 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)
.When(c => c.Ceritification.IsNotNullOrWhiteSpace())
.When(c => c.Certification.IsNotNullOrWhiteSpace())
.WithMessage("Not a valid certification");
// CSV of numbers
@ -58,8 +58,8 @@ namespace NzbDrone.Core.NetImport.TMDb
[FieldDefinition(2, Label = "Minimum Number of Votes", HelpText = "Filter movies by number of votes")]
public string MinVotes { get; set; }
[FieldDefinition(3, Label = "Certification", HelpText = "Filter movies by a single ceritification (NR,G,PG,PG-13,R,NC-17)")]
public string Ceritification { get; set; }
[FieldDefinition(3, Label = "Certification", HelpText = "Filter movies by a single certification (NR,G,PG,PG-13,R,NC-17)")]
public string Certification { get; set; }
[FieldDefinition(4, Label = "Include Genre Ids", HelpText = "Filter movies by TMDb Genre Ids (Comma Separated)")]
public string IncludeGenreIds { get; set; }

@ -27,7 +27,7 @@ namespace NzbDrone.Core.NetImport.Trakt
return movies;
}
if (_settings.ListType == (int)TraktListType.Popular)
if (_settings.TraktListType == (int)TraktListType.Popular)
{
var jsonResponse = JsonConvert.DeserializeObject<List<Movie>>(_importResponse.Content);

@ -37,9 +37,9 @@ namespace NzbDrone.Core.NetImport.Trakt
{
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:
var listName = Parser.Parser.ToUrlSlug(Settings.Listname.Trim());

@ -20,13 +20,13 @@ namespace NzbDrone.Core.NetImport.Trakt
// List name required for UserCustomList
RuleFor(c => c.Listname)
.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");
// Username required for UserWatchedList/UserWatchList
RuleFor(c => c.Username)
.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");
// Loose validation @TODO
@ -36,9 +36,9 @@ namespace NzbDrone.Core.NetImport.Trakt
.WithMessage("Not a valid rating");
// 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)
.When(c => c.Ceritification.IsNotNullOrWhiteSpace())
.When(c => c.Certification.IsNotNullOrWhiteSpace())
.WithMessage("Not a valid cerification");
// Loose validation @TODO
@ -64,11 +64,11 @@ namespace NzbDrone.Core.NetImport.Trakt
{
Link = "https://api.trakt.tv";
SignIn = "startOAuth";
ListType = (int)TraktListType.Popular;
TraktListType = (int)Trakt.TraktListType.Popular;
Username = "";
Listname = "";
Rating = "0-100";
Ceritification = "NR,G,PG,PG-13,R,NC-17";
Certification = "NR,G,PG,PG-13,R,NC-17";
Genres = "";
Years = "";
Limit = 100;
@ -92,7 +92,7 @@ namespace NzbDrone.Core.NetImport.Trakt
public string Link { get; set; }
[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)")]
public string Username { get; set; }
@ -103,8 +103,8 @@ namespace NzbDrone.Core.NetImport.Trakt
[FieldDefinition(4, Label = "Rating", HelpText = "Filter movies by rating range (0-100)")]
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)")]
public string Ceritification { get; set; }
[FieldDefinition(5, Label = "Certification", HelpText = "Filter movies by a certification (NR,G,PG,PG-13,R,NC-17), (Comma Separated)")]
public string Certification { get; set; }
[FieldDefinition(6, Label = "Genres", HelpText = "Filter movies by Trakt Genre Slug (Comma Separated)")]
public string Genres { get; set; }

Loading…
Cancel
Save