mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-02-18 13:00:04 -06:00
FF-1407 - fixed issue looking up tv shows with year in their name
This commit is contained in:
@@ -11,6 +11,20 @@ namespace MetaNodes.Tests.TheMovieDb;
|
||||
[TestClass]
|
||||
public class TVEpisodeLookupTests
|
||||
{
|
||||
/// <summary>
|
||||
/// The test context instance
|
||||
/// </summary>
|
||||
private TestContext testContextInstance;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the test context
|
||||
/// </summary>
|
||||
public TestContext TestContext
|
||||
{
|
||||
get { return testContextInstance; }
|
||||
set { testContextInstance = value; }
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TheBatman_s02e01()
|
||||
{
|
||||
@@ -47,6 +61,28 @@ public class TVEpisodeLookupTests
|
||||
Assert.IsFalse(string.IsNullOrWhiteSpace(args.Variables["tvepisode.Overview"] as string));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WithYear()
|
||||
{
|
||||
var logger = new TestLogger();
|
||||
var args = new FileFlows.Plugin.NodeParameters("/test/tv/Paradise PD (2018) - S04E04 - Good Jeans (1080p NF WEB-DL x265 t3nzin).mkv", logger, false, string.Empty, null);
|
||||
|
||||
var element = new TVEpisodeLookup();
|
||||
|
||||
var result = element.Execute(args);
|
||||
TestContext.WriteLine(logger.ToString());
|
||||
|
||||
Assert.AreEqual(1, result);
|
||||
|
||||
|
||||
Assert.AreEqual("Paradise PD", args.Variables["tvepisode.Title"]);
|
||||
Assert.AreEqual(4, args.Variables["tvepisode.Season"]);
|
||||
Assert.AreEqual(4, args.Variables["tvepisode.Episode"]);
|
||||
Assert.AreEqual("Good Jeans", args.Variables["tvepisode.Subtitle"]);
|
||||
Assert.IsFalse(string.IsNullOrWhiteSpace(args.Variables["tvepisode.Overview"] as string));
|
||||
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TheBatman_3x01_2()
|
||||
{
|
||||
|
||||
@@ -65,8 +65,8 @@ public class TVEpisodeLookup : Node
|
||||
public override int Execute(NodeParameters args)
|
||||
{
|
||||
string filename = args.FileName.Replace("\\", "/");
|
||||
filename = filename.Substring(filename.LastIndexOf("/") + 1);
|
||||
filename = filename.Substring(0, filename.LastIndexOf("."));
|
||||
filename = filename.Substring(filename.LastIndexOf("/", StringComparison.Ordinal) + 1);
|
||||
filename = filename.Substring(0, filename.LastIndexOf(".", StringComparison.Ordinal));
|
||||
|
||||
(string lookupName, string year) = TVShowLookup.GetLookupName(filename, false);
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ public class TVShowLookup : Node
|
||||
}
|
||||
|
||||
// remove double spaces in case they were added when removing the year
|
||||
while (lookupName.IndexOf(" ") > 0)
|
||||
while (lookupName.IndexOf(" ", StringComparison.Ordinal) > 0)
|
||||
lookupName = lookupName.Replace(" ", " ");
|
||||
|
||||
return (lookupName, year);
|
||||
@@ -204,13 +204,22 @@ public class TVShowLookup : Node
|
||||
// Replace "1x02" format with "s1e02"
|
||||
text = Regex.Replace(text, @"(?<season>\d+)x(?<episode>\d+)", "s${season}e${episode}", RegexOptions.IgnoreCase);
|
||||
|
||||
string year = null;
|
||||
var reYear = Regex.Match(text, @"(19|20)[\d]{2}", RegexOptions.CultureInvariant);
|
||||
if (reYear.Success)
|
||||
{
|
||||
year = reYear.Value;
|
||||
text = text.Replace("(" + year + ")", string.Empty);
|
||||
text = text.Replace(year, string.Empty);
|
||||
}
|
||||
|
||||
string pattern = @"^(?<showName>[\w\s.-]+)[. _-]?(?:(s|S)(?<season>\d+)(e|E)(?<episode>\d+)(?:-(?<lastEpisode>\d+))?)";
|
||||
|
||||
Match match = Regex.Match(text, pattern);
|
||||
|
||||
if (match.Success == false)
|
||||
return (text, null, null, null);
|
||||
|
||||
|
||||
string show = match.Groups["showName"].Value.Replace(".", " ").TrimEnd();
|
||||
if (show.EndsWith(" -"))
|
||||
show = show[..^2];
|
||||
@@ -219,6 +228,9 @@ public class TVShowLookup : Node
|
||||
string lastEpisodeStr = match.Groups["lastEpisode"].Value;
|
||||
int? lastEpisode = string.IsNullOrEmpty(lastEpisodeStr) ? (int?)null : int.Parse(lastEpisodeStr);
|
||||
|
||||
if (year != null)
|
||||
show += " (" + year + ")";
|
||||
|
||||
return (show, season, episode, lastEpisode);
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,14 @@ namespace VideoNodes.Tests;
|
||||
[TestClass]
|
||||
public abstract class TestBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The test context instance
|
||||
/// </summary>
|
||||
private TestContext testContextInstance;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the test context
|
||||
/// </summary>
|
||||
public TestContext TestContext
|
||||
{
|
||||
get { return testContextInstance; }
|
||||
|
||||
Reference in New Issue
Block a user