From d397cdf5fb9b4626bc75bd25ec35a64f8b8260ad Mon Sep 17 00:00:00 2001 From: Bogdan Date: Thu, 23 Feb 2023 09:33:30 +0200 Subject: [PATCH] Fixed: (Cardigann) Implement validate as field filter --- .../Definitions/Cardigann/CardigannBase.cs | 20 +++++++------- .../Definitions/Cardigann/CardigannParser.cs | 27 ++++++------------- 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannBase.cs b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannBase.cs index 01333eadd..b8ed63a1b 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannBase.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannBase.cs @@ -747,18 +747,20 @@ namespace NzbDrone.Core.Indexers.Cardigann // for debugging var debugData = data.Replace("\r", "\\r").Replace("\n", "\\n").Replace("\xA0", "\\xA0"); var strTag = (string)filter.Args; - if (strTag != null) - { - strTag = string.Format("({0}):", strTag); - } - else - { - strTag = ":"; - } + strTag = strTag != null ? $"({strTag}):" : ":"; - _logger.Debug(string.Format("CardigannIndexer ({0}): strdump{1} {2}", _definition.Id, strTag, debugData)); + _logger.Debug($"CardigannIndexer ({_definition.Id}): strdump{strTag} {debugData}"); + break; + case "validate": + char[] delimiters = { ',', ' ', '/', ')', '(', '.', ';', '[', ']', '"', '|', ':' }; + var args = (string)filter.Args; + var argsList = args.ToLower().Split(delimiters, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); + var validList = argsList.ToList(); + var validIntersect = validList.Intersect(data.ToLower().Split(delimiters, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)).ToList(); + data = string.Join(", ", validIntersect); break; default: + _logger.Error($"CardigannIndexer ({_definition.Id}): Unsupported field filter: {filter.Name}"); break; } } diff --git a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannParser.cs b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannParser.cs index 76d81b121..2cdb12967 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannParser.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannParser.cs @@ -585,8 +585,12 @@ namespace NzbDrone.Core.Indexers.Cardigann value = release.PosterUrl; break; case "genre": + release.Genres ??= new List(); char[] delimiters = { ',', ' ', '/', ')', '(', '.', ';', '[', ']', '"', '|', ':' }; - release.Genres = release.Genres.Union(value.Split(delimiters, System.StringSplitOptions.RemoveEmptyEntries)).ToList(); + release.Genres = release.Genres + .Union(value.Split(delimiters, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)) + .Select(x => x.Replace("_", " ")) + .ToList(); value = string.Join(", ", release.Genres); break; case "year": @@ -632,29 +636,14 @@ namespace NzbDrone.Core.Indexers.Cardigann switch (filter.Name) { case "andmatch": - var characterLimit = -1; - if (filter.Args != null) - { - characterLimit = int.Parse(filter.Args); - } - - var queryKeywords = variables[".Keywords"] as string; - + // See IndexerBase.FilterReleasesByQuery break; case "strdump": // for debugging - _logger.Debug(string.Format("CardigannIndexer ({0}): row strdump: {1}", _definition.Id, row.ToString())); - break; - case "validate": - char[] delimiters = { ',', ' ', '/', ')', '(', '.', ';', '[', ']', '"', '|', ':' }; - var args = (string)filter.Args; - var argsList = args.ToLower().Split(delimiters, StringSplitOptions.RemoveEmptyEntries); - var validList = argsList.ToList(); - var validIntersect = validList.Intersect(row.ToString().ToLower().Split(delimiters, StringSplitOptions.RemoveEmptyEntries)).ToList(); - row = string.Join(", ", validIntersect); + _logger.Debug($"CardigannIndexer ({_definition.Id}): row strdump: {row}"); break; default: - _logger.Error(string.Format("CardigannIndexer ({0}): Unsupported rows filter: {1}", _definition.Id, filter.Name)); + _logger.Error($"CardigannIndexer ({_definition.Id}): Unsupported rows filter: {filter.Name}"); break; } }