Nicer copy extraction

This commit is contained in:
Jendrik Weise 2023-11-04 18:34:03 +01:00
parent 46dcbc3f85
commit 69fbcadddc
2 changed files with 14 additions and 35 deletions

View File

@ -284,13 +284,13 @@ namespace NzbDrone.Core.Parser
.Cast<Capture>() .Cast<Capture>()
.Where(tag => !tag.Value.Empty()) .Where(tag => !tag.Value.Empty())
.Select(tag => tag.Value.ToLower()); .Select(tag => tag.Value.ToLower());
var title = matchTitle.Groups["title"].Value; var rawTitle = matchTitle.Groups["title"].Value;
return new SubtitleTitleInfo return new SubtitleTitleInfo
{ {
TitleFirst = matchTitle.Groups["tags1"].Captures.Empty(), TitleFirst = matchTitle.Groups["tags1"].Captures.Empty(),
LanguageTags = languageTags.ToList(), LanguageTags = languageTags.ToList(),
RawTitle = title, RawTitle = rawTitle,
Language = language Language = language
}; };
} }

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using NzbDrone.Core.Languages; using NzbDrone.Core.Languages;
@ -10,46 +11,24 @@ namespace NzbDrone.Core.Parser.Model
public List<string> LanguageTags { get; set; } public List<string> LanguageTags { get; set; }
public Language Language { get; set; } public Language Language { get; set; }
public string RawTitle { 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, 0);
{
return null;
}
var match = SubtitleTitleRegex.Match(RawTitle);
if (match.Success)
{
return match.Groups["title"].Success ? match.Groups["title"].ToString() : null;
}
return RawTitle;
} }
}
public int Copy var match = SubtitleTitleRegex.Match(RawTitle);
{
get if (match.Success)
{ {
if (RawTitle is null) return (match.Groups["title"].Success ? match.Groups["title"].ToString() : null, int.Parse(match.Groups["copy"].ToString()));
{
return 0;
}
var match = SubtitleTitleRegex.Match(RawTitle);
if (match.Success)
{
return int.Parse(match.Groups["copy"].ToString());
}
return 0;
} }
}
return (RawTitle, 0);
});
public string Title => TitleAndCopy.Value.Title;
public int Copy => TitleAndCopy.Value.Copy;
public bool TitleFirst { get; set; } public bool TitleFirst { get; set; }
} }
} }