From 69fbcadddca3378de4b285deb1c08c5fba6888dd Mon Sep 17 00:00:00 2001 From: Jendrik Weise Date: Sat, 4 Nov 2023 18:34:03 +0100 Subject: [PATCH] Nicer copy extraction --- src/NzbDrone.Core/Parser/LanguageParser.cs | 4 +- .../Parser/Model/SubtitleTitleInfo.cs | 45 +++++-------------- 2 files changed, 14 insertions(+), 35 deletions(-) diff --git a/src/NzbDrone.Core/Parser/LanguageParser.cs b/src/NzbDrone.Core/Parser/LanguageParser.cs index 5b18a7b16..0e6caedca 100644 --- a/src/NzbDrone.Core/Parser/LanguageParser.cs +++ b/src/NzbDrone.Core/Parser/LanguageParser.cs @@ -284,13 +284,13 @@ namespace NzbDrone.Core.Parser .Cast() .Where(tag => !tag.Value.Empty()) .Select(tag => tag.Value.ToLower()); - var title = matchTitle.Groups["title"].Value; + var rawTitle = matchTitle.Groups["title"].Value; return new SubtitleTitleInfo { TitleFirst = matchTitle.Groups["tags1"].Captures.Empty(), LanguageTags = languageTags.ToList(), - RawTitle = title, + RawTitle = rawTitle, Language = language }; } diff --git a/src/NzbDrone.Core/Parser/Model/SubtitleTitleInfo.cs b/src/NzbDrone.Core/Parser/Model/SubtitleTitleInfo.cs index f119e240a..c757ceeb1 100644 --- a/src/NzbDrone.Core/Parser/Model/SubtitleTitleInfo.cs +++ b/src/NzbDrone.Core/Parser/Model/SubtitleTitleInfo.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Text.RegularExpressions; using NzbDrone.Core.Languages; @@ -10,46 +11,24 @@ namespace NzbDrone.Core.Parser.Model public List LanguageTags { get; set; } public Language Language { get; set; } public string RawTitle { get; set; } - public string Title + private Lazy<(string Title, int Copy)> TitleAndCopy => new Lazy<(string title, int copy)>(() => { - get + if (RawTitle is null) { - if (RawTitle is null) - { - return null; - } - - var match = SubtitleTitleRegex.Match(RawTitle); - - if (match.Success) - { - return match.Groups["title"].Success ? match.Groups["title"].ToString() : null; - } - - return RawTitle; + return (null, 0); } - } - public int Copy - { - get + var match = SubtitleTitleRegex.Match(RawTitle); + + if (match.Success) { - if (RawTitle is null) - { - return 0; - } - - var match = SubtitleTitleRegex.Match(RawTitle); - - if (match.Success) - { - return int.Parse(match.Groups["copy"].ToString()); - } - - return 0; + return (match.Groups["title"].Success ? match.Groups["title"].ToString() : null, int.Parse(match.Groups["copy"].ToString())); } - } + return (RawTitle, 0); + }); + public string Title => TitleAndCopy.Value.Title; + public int Copy => TitleAndCopy.Value.Copy; public bool TitleFirst { get; set; } } }