diff --git a/src/NzbDrone.Core/IndexerSearch/MoviesSearchService.cs b/src/NzbDrone.Core/IndexerSearch/MoviesSearchService.cs index 7f86259c2e..f1ed4bd8dd 100644 --- a/src/NzbDrone.Core/IndexerSearch/MoviesSearchService.cs +++ b/src/NzbDrone.Core/IndexerSearch/MoviesSearchService.cs @@ -62,8 +62,8 @@ public void Execute(MissingMoviesSearchCommand message) var movies = _movieService.MoviesWithoutFiles(pagingSpec).Records.ToList(); - var queue = _queueService.GetQueue().Where(q => q.Movie != null).Select(q => q.Movie.Id); - var missing = movies.Where(e => !queue.Contains(e.Id)).ToList(); + var queuedMovieIds = new HashSet(_queueService.GetQueue().Where(q => q.Movie != null).Select(q => q.Movie.Id)); + var missing = movies.Where(e => !queuedMovieIds.Contains(e.Id)).ToList(); SearchForBulkMovies(missing, message.Trigger == CommandTrigger.Manual).GetAwaiter().GetResult(); } @@ -82,8 +82,8 @@ public void Execute(CutoffUnmetMoviesSearchCommand message) var movies = _movieCutoffService.MoviesWhereCutoffUnmet(pagingSpec).Records.ToList(); - var queue = _queueService.GetQueue().Where(q => q.Movie != null).Select(q => q.Movie.Id); - var missing = movies.Where(e => !queue.Contains(e.Id)).ToList(); + var queuedMovieIds = new HashSet(_queueService.GetQueue().Where(q => q.Movie != null).Select(q => q.Movie.Id)); + var missing = movies.Where(e => !queuedMovieIds.Contains(e.Id)).ToList(); SearchForBulkMovies(missing, message.Trigger == CommandTrigger.Manual).GetAwaiter().GetResult(); } diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index 6368d6d4df..e0b7dafefd 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -25,6 +25,9 @@ namespace NzbDrone.Core.MetadataSource.SkyHook { public class SkyHookProxy : IProvideMovieInfo, ISearchForNewMovie { + private static readonly Regex ImdbUrlRegex = new Regex(@"\bimdb\.com/title/(tt\d{7,})\b", RegexOptions.Compiled | RegexOptions.IgnoreCase); + private static readonly Regex TmdbUrlRegex = new Regex(@"\bthemoviedb\.org/movie/(\d+)\b", RegexOptions.Compiled | RegexOptions.IgnoreCase); + private readonly IHttpClient _httpClient; private readonly Logger _logger; @@ -406,7 +409,7 @@ public List SearchForNewMovie(string title) { try { - var match = new Regex(@"\bimdb\.com/title/(tt\d{7,})\b", RegexOptions.IgnoreCase).Match(title); + var match = ImdbUrlRegex.Match(title); if (match.Success) { @@ -414,7 +417,7 @@ public List SearchForNewMovie(string title) } else { - match = new Regex(@"\bthemoviedb\.org/movie/(\d+)\b", RegexOptions.IgnoreCase).Match(title); + match = TmdbUrlRegex.Match(title); if (match.Success) { diff --git a/src/NzbDrone.Core/Movies/MovieService.cs b/src/NzbDrone.Core/Movies/MovieService.cs index 60242f938d..9a18da5edf 100644 --- a/src/NzbDrone.Core/Movies/MovieService.cs +++ b/src/NzbDrone.Core/Movies/MovieService.cs @@ -125,31 +125,32 @@ public Movie FindByTitle(string title, int year) public Movie FindByTitle(List titles, int? year, List otherTitles, List candidates) { - var cleanTitles = titles.Select(t => t.CleanMovieTitle().ToLowerInvariant()); + var cleanTitlesSet = new HashSet(titles.Select(t => t.CleanMovieTitle().ToLowerInvariant())); + var otherTitlesSet = new HashSet(otherTitles); - var result = candidates.Where(x => cleanTitles.Contains(x.MovieMetadata.Value.CleanTitle) || cleanTitles.Contains(x.MovieMetadata.Value.CleanOriginalTitle)) + var result = candidates.Where(x => cleanTitlesSet.Contains(x.MovieMetadata.Value.CleanTitle) || cleanTitlesSet.Contains(x.MovieMetadata.Value.CleanOriginalTitle)) .AllWithYear(year) .ToList(); if (result == null || result.Count == 0) { result = - candidates.Where(movie => otherTitles.Contains(movie.MovieMetadata.Value.CleanTitle)).AllWithYear(year).ToList(); + candidates.Where(movie => otherTitlesSet.Contains(movie.MovieMetadata.Value.CleanTitle)).AllWithYear(year).ToList(); } if (result == null || result.Count == 0) { result = candidates - .Where(m => m.MovieMetadata.Value.AlternativeTitles.Any(t => cleanTitles.Contains(t.CleanTitle) || - otherTitles.Contains(t.CleanTitle))) + .Where(m => m.MovieMetadata.Value.AlternativeTitles.Any(t => cleanTitlesSet.Contains(t.CleanTitle) || + otherTitlesSet.Contains(t.CleanTitle))) .AllWithYear(year).ToList(); } if (result == null || result.Count == 0) { result = candidates - .Where(m => m.MovieMetadata.Value.Translations.Any(t => cleanTitles.Contains(t.CleanTitle) || - otherTitles.Contains(t.CleanTitle))) + .Where(m => m.MovieMetadata.Value.Translations.Any(t => cleanTitlesSet.Contains(t.CleanTitle) || + otherTitlesSet.Contains(t.CleanTitle))) .AllWithYear(year).ToList(); } diff --git a/src/NzbDrone.Core/Notifications/Pushsafer/PushsaferSettings.cs b/src/NzbDrone.Core/Notifications/Pushsafer/PushsaferSettings.cs index 3b310b3d74..ee764ff29d 100644 --- a/src/NzbDrone.Core/Notifications/Pushsafer/PushsaferSettings.cs +++ b/src/NzbDrone.Core/Notifications/Pushsafer/PushsaferSettings.cs @@ -10,6 +10,8 @@ namespace NzbDrone.Core.Notifications.Pushsafer { public class PushsaferSettingsValidator : AbstractValidator { + private static readonly Regex HexColorRegex = new Regex("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$", RegexOptions.Compiled); + public PushsaferSettingsValidator() { RuleFor(c => c.ApiKey).NotEmpty(); @@ -18,7 +20,7 @@ public PushsaferSettingsValidator() RuleFor(c => c.Sound).ValidParsedStringRange(0, 62).When(c => c.Sound.IsNotNullOrWhiteSpace()); RuleFor(c => c.Vibration).ValidParsedStringRange(1, 3).When(c => c.Vibration.IsNotNullOrWhiteSpace()); RuleFor(c => c.Icon).ValidParsedStringRange(1, 181).When(c => c.Icon.IsNotNullOrWhiteSpace()); - RuleFor(c => c.IconColor).Matches(new Regex("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$")).When(c => c.IconColor.IsNotNullOrWhiteSpace()); + RuleFor(c => c.IconColor).Matches(HexColorRegex).When(c => c.IconColor.IsNotNullOrWhiteSpace()); } } diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index 5a614c1efc..efd104e124 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -15,6 +15,8 @@ public static class Parser { private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(Parser)); + private static readonly Regex ImdbIdRegex = new Regex(@"^(\d{1,10}|(tt)\d{1,10})$", RegexOptions.Compiled); + private static readonly Regex EditionRegex = new Regex(@"\(?\b(?(((Recut.|Extended.|Ultimate.)?(Director.?s|Collector.?s|Theatrical|Ultimate|Extended|Despecialized|(Special|Rouge|Final|Assembly|Imperial|Diamond|Signature|Hunter|Rekall)(?=(.(Cut|Edition|Version)))|\d{2,3}(th)?.Anniversary)(?:.(Cut|Edition|Version))?(.(Extended|Uncensored|Remastered|Unrated|Uncut|Open.?Matte|IMAX|Fan.?Edit))?|((Uncensored|Remastered|Unrated|Uncut|Open?.Matte|IMAX|Fan.?Edit|Restored|((2|3|4)in1))))))\b\)?", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static readonly Regex ReportEditionRegex = new Regex(@"^.+?" + EditionRegex, RegexOptions.Compiled | RegexOptions.IgnoreCase); @@ -380,9 +382,7 @@ public static string ReplaceGermanUmlauts(string s) public static string NormalizeImdbId(string imdbId) { - var imdbRegex = new Regex(@"^(\d{1,10}|(tt)\d{1,10})$"); - - if (!imdbRegex.IsMatch(imdbId)) + if (!ImdbIdRegex.IsMatch(imdbId)) { return null; }