Finish coverage for Emby.Naming.Video
This commit is contained in:
parent
5741150367
commit
3466dc5581
|
@ -120,9 +120,9 @@ namespace Emby.Naming.Common
|
|||
|
||||
VideoFileStackingExpressions = new[]
|
||||
{
|
||||
"(.*?)([ _.-]*(?:cd|dvd|p(?:ar)?t|dis[ck])[ _.-]*[0-9]+)(.*?)(\\.[^.]+)$",
|
||||
"(.*?)([ _.-]*(?:cd|dvd|p(?:ar)?t|dis[ck])[ _.-]*[a-d])(.*?)(\\.[^.]+)$",
|
||||
"(.*?)([ ._-]*[a-d])(.*?)(\\.[^.]+)$"
|
||||
"(?<title>.*?)(?<volume>[ _.-]*(?:cd|dvd|p(?:ar)?t|dis[ck])[ _.-]*[0-9]+)(?<ignore>.*?)(?<extension>\\.[^.]+)$",
|
||||
"(?<title>.*?)(?<volume>[ _.-]*(?:cd|dvd|p(?:ar)?t|dis[ck])[ _.-]*[a-d])(?<ignore>.*?)(?<extension>\\.[^.]+)$",
|
||||
"(?<title>.*?)(?<volume>[ ._-]*[a-d])(?<ignore>.*?)(?<extension>\\.[^.]+)$"
|
||||
};
|
||||
|
||||
CleanDateTimes = new[]
|
||||
|
|
|
@ -45,7 +45,8 @@ namespace Emby.Naming.Video
|
|||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
// Currently unreachable code if new rule.MediaType is desired add if clause with proper tests
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
if (rule.RuleType == ExtraRuleType.Filename)
|
||||
|
@ -70,6 +71,9 @@ namespace Emby.Naming.Video
|
|||
}
|
||||
else if (rule.RuleType == ExtraRuleType.Regex)
|
||||
{
|
||||
// Currently unreachable code if new rule.MediaType is desired add if clause with proper tests
|
||||
throw new InvalidOperationException();
|
||||
/*
|
||||
var filename = Path.GetFileName(path);
|
||||
|
||||
var regex = new Regex(rule.Token, RegexOptions.IgnoreCase);
|
||||
|
@ -79,6 +83,7 @@ namespace Emby.Naming.Video
|
|||
result.ExtraType = rule.ExtraType;
|
||||
result.Rule = rule;
|
||||
}
|
||||
*/
|
||||
}
|
||||
else if (rule.RuleType == ExtraRuleType.DirectoryName)
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace Emby.Naming.Video
|
|||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(path));
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
|
||||
// Note: the tags need be be surrounded be either a space ( ), hyphen -, dot . or underscore _.
|
||||
|
|
|
@ -86,10 +86,10 @@ namespace Emby.Naming.Video
|
|||
|
||||
if (match1.Success)
|
||||
{
|
||||
var title1 = match1.Groups[1].Value;
|
||||
var volume1 = match1.Groups[2].Value;
|
||||
var ignore1 = match1.Groups[3].Value;
|
||||
var extension1 = match1.Groups[4].Value;
|
||||
var title1 = match1.Groups["title"].Value;
|
||||
var volume1 = match1.Groups["volume"].Value;
|
||||
var ignore1 = match1.Groups["ignore"].Value;
|
||||
var extension1 = match1.Groups["extension"].Value;
|
||||
|
||||
var j = i + 1;
|
||||
while (j < list.Count)
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Emby.Naming.Video
|
|||
{
|
||||
stubType = default;
|
||||
|
||||
if (path == null)
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,35 @@ namespace Emby.Naming.Video
|
|||
/// </summary>
|
||||
public class VideoFileInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="VideoFileInfo"/> class.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of file.</param>
|
||||
/// <param name="path">Path to the file.</param>
|
||||
/// <param name="container">Container type.</param>
|
||||
/// <param name="year">Year of release.</param>
|
||||
/// <param name="extraType">Extra type.</param>
|
||||
/// <param name="extraRule">Extra rule.</param>
|
||||
/// <param name="format3D">Format 3D.</param>
|
||||
/// <param name="is3D">Is 3D.</param>
|
||||
/// <param name="isStub">Is Stub.</param>
|
||||
/// <param name="stubType">Stub type.</param>
|
||||
/// <param name="isDirectory">Is directory.</param>
|
||||
public VideoFileInfo(string name, string? path, string? container, int? year = default, ExtraType? extraType = default, ExtraRule? extraRule = default, string? format3D = default, bool is3D = default, bool isStub = default, string? stubType = default, bool isDirectory = default)
|
||||
{
|
||||
Path = path;
|
||||
Container = container;
|
||||
Name = name;
|
||||
Year = year;
|
||||
ExtraType = extraType;
|
||||
ExtraRule = extraRule;
|
||||
Format3D = format3D;
|
||||
Is3D = is3D;
|
||||
IsStub = isStub;
|
||||
StubType = stubType;
|
||||
IsDirectory = isDirectory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path.
|
||||
/// </summary>
|
||||
|
@ -23,7 +52,7 @@ namespace Emby.Naming.Video
|
|||
/// Gets or sets the name.
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
public string? Name { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the year.
|
||||
|
@ -84,8 +113,7 @@ namespace Emby.Naming.Video
|
|||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
// Makes debugging easier
|
||||
return Name ?? base.ToString();
|
||||
return "VideoFileInfo(Name: '" + Name + "')";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ namespace Emby.Naming.Video
|
|||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(path));
|
||||
return null;
|
||||
}
|
||||
|
||||
bool isStub = false;
|
||||
|
@ -99,20 +99,18 @@ namespace Emby.Naming.Video
|
|||
}
|
||||
}
|
||||
|
||||
return new VideoFileInfo
|
||||
{
|
||||
Path = path,
|
||||
Container = container,
|
||||
IsStub = isStub,
|
||||
Name = name,
|
||||
Year = year,
|
||||
StubType = stubType,
|
||||
Is3D = format3DResult.Is3D,
|
||||
Format3D = format3DResult.Format3D,
|
||||
ExtraType = extraResult.ExtraType,
|
||||
IsDirectory = isDirectory,
|
||||
ExtraRule = extraResult.Rule
|
||||
};
|
||||
return new VideoFileInfo(
|
||||
path: path,
|
||||
container: container,
|
||||
isStub: isStub,
|
||||
name: name,
|
||||
year: year,
|
||||
stubType: stubType,
|
||||
is3D: format3DResult.Is3D,
|
||||
format3D: format3DResult.Format3D,
|
||||
extraType: extraResult.ExtraType,
|
||||
isDirectory: isDirectory,
|
||||
extraRule: extraResult.Rule);
|
||||
}
|
||||
|
||||
public bool IsVideoFile(string path)
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
using Emby.Naming.Common;
|
||||
using System;
|
||||
using Emby.Naming.Common;
|
||||
using Emby.Naming.Video;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using Xunit;
|
||||
using MediaType = Emby.Naming.Common.MediaType;
|
||||
|
||||
namespace Jellyfin.Naming.Tests.Video
|
||||
{
|
||||
|
@ -93,6 +95,27 @@ namespace Jellyfin.Naming.Tests.Video
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestExtraInfo_InvalidRuleMediaType()
|
||||
{
|
||||
var options = new NamingOptions { VideoExtraRules = new[] { new ExtraRule(ExtraType.Unknown, ExtraRuleType.DirectoryName, " ", MediaType.Photo) } };
|
||||
Assert.Throws<InvalidOperationException>(() => GetExtraTypeParser(options).GetExtraInfo("sample.jpg"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestExtraInfo_InvalidRuleType()
|
||||
{
|
||||
var options = new NamingOptions { VideoExtraRules = new[] { new ExtraRule(ExtraType.Unknown, ExtraRuleType.Regex, " ", MediaType.Video) } };
|
||||
Assert.Throws<InvalidOperationException>(() => GetExtraTypeParser(options).GetExtraInfo("sample.mp4"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestFlagsParser()
|
||||
{
|
||||
var flags = new FlagParser(_videoOptions).GetFlags(string.Empty);
|
||||
Assert.Empty(flags);
|
||||
}
|
||||
|
||||
private ExtraResolver GetExtraTypeParser(NamingOptions videoOptions)
|
||||
{
|
||||
return new ExtraResolver(videoOptions);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using Emby.Naming.Common;
|
||||
using Emby.Naming.Common;
|
||||
using Emby.Naming.Video;
|
||||
using Xunit;
|
||||
|
||||
|
@ -23,6 +23,7 @@ namespace Jellyfin.Naming.Tests.Video
|
|||
Test("video.hdtv.disc", true, "tv");
|
||||
Test("video.pdtv.disc", true, "tv");
|
||||
Test("video.dsr.disc", true, "tv");
|
||||
Test(string.Empty, false, "tv");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Linq;
|
||||
using System.Linq;
|
||||
using Emby.Naming.Common;
|
||||
using Emby.Naming.Video;
|
||||
using MediaBrowser.Model.IO;
|
||||
|
@ -369,6 +369,26 @@ namespace Jellyfin.Naming.Tests.Video
|
|||
Assert.Single(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestFourRooms()
|
||||
{
|
||||
var files = new[]
|
||||
{
|
||||
@"Four Rooms - A.avi",
|
||||
@"Four Rooms - A.mp4"
|
||||
};
|
||||
|
||||
var resolver = GetResolver();
|
||||
|
||||
var result = resolver.Resolve(files.Select(i => new FileSystemMetadata
|
||||
{
|
||||
IsDirectory = false,
|
||||
FullName = i
|
||||
}).ToList()).ToList();
|
||||
|
||||
Assert.Equal(2, result.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMovieTrailer()
|
||||
{
|
||||
|
@ -431,6 +451,13 @@ namespace Jellyfin.Naming.Tests.Video
|
|||
Assert.Single(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDirectoryStack()
|
||||
{
|
||||
var stack = new FileStack();
|
||||
Assert.False(stack.ContainsFile("XX", true));
|
||||
}
|
||||
|
||||
private VideoListResolver GetResolver()
|
||||
{
|
||||
return new VideoListResolver(_namingOptions);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Emby.Naming.Common;
|
||||
using Emby.Naming.Video;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
@ -14,165 +15,135 @@ namespace Jellyfin.Naming.Tests.Video
|
|||
{
|
||||
yield return new object[]
|
||||
{
|
||||
new VideoFileInfo()
|
||||
{
|
||||
Path = @"/server/Movies/7 Psychos.mkv/7 Psychos.mkv",
|
||||
Container = "mkv",
|
||||
Name = "7 Psychos"
|
||||
}
|
||||
new VideoFileInfo(
|
||||
path: @"/server/Movies/7 Psychos.mkv/7 Psychos.mkv",
|
||||
container: "mkv",
|
||||
name: "7 Psychos")
|
||||
};
|
||||
yield return new object[]
|
||||
{
|
||||
new VideoFileInfo()
|
||||
{
|
||||
Path = @"/server/Movies/3 days to kill (2005)/3 days to kill (2005).mkv",
|
||||
Container = "mkv",
|
||||
Name = "3 days to kill",
|
||||
Year = 2005
|
||||
}
|
||||
new VideoFileInfo(
|
||||
path: @"/server/Movies/3 days to kill (2005)/3 days to kill (2005).mkv",
|
||||
container: "mkv",
|
||||
name: "3 days to kill",
|
||||
year: 2005)
|
||||
};
|
||||
yield return new object[]
|
||||
{
|
||||
new VideoFileInfo()
|
||||
{
|
||||
Path = @"/server/Movies/American Psycho/American.Psycho.mkv",
|
||||
Container = "mkv",
|
||||
Name = "American.Psycho",
|
||||
}
|
||||
new VideoFileInfo(
|
||||
path: @"/server/Movies/American Psycho/American.Psycho.mkv",
|
||||
container: "mkv",
|
||||
name: "American.Psycho")
|
||||
};
|
||||
yield return new object[]
|
||||
{
|
||||
new VideoFileInfo()
|
||||
{
|
||||
Path = @"/server/Movies/brave (2007)/brave (2006).3d.sbs.mkv",
|
||||
Container = "mkv",
|
||||
Name = "brave",
|
||||
Year = 2006,
|
||||
Is3D = true,
|
||||
Format3D = "sbs",
|
||||
}
|
||||
new VideoFileInfo(
|
||||
path: @"/server/Movies/brave (2007)/brave (2006).3d.sbs.mkv",
|
||||
container: "mkv",
|
||||
name: "brave",
|
||||
year: 2006,
|
||||
is3D: true,
|
||||
format3D: "sbs")
|
||||
};
|
||||
yield return new object[]
|
||||
{
|
||||
new VideoFileInfo()
|
||||
{
|
||||
Path = @"/server/Movies/300 (2007)/300 (2006).3d1.sbas.mkv",
|
||||
Container = "mkv",
|
||||
Name = "300",
|
||||
Year = 2006
|
||||
}
|
||||
new VideoFileInfo(
|
||||
path: @"/server/Movies/300 (2007)/300 (2006).3d1.sbas.mkv",
|
||||
container: "mkv",
|
||||
name: "300",
|
||||
year: 2006)
|
||||
};
|
||||
yield return new object[]
|
||||
{
|
||||
new VideoFileInfo()
|
||||
{
|
||||
Path = @"/server/Movies/300 (2007)/300 (2006).3d.sbs.mkv",
|
||||
Container = "mkv",
|
||||
Name = "300",
|
||||
Year = 2006,
|
||||
Is3D = true,
|
||||
Format3D = "sbs",
|
||||
}
|
||||
new VideoFileInfo(
|
||||
path: @"/server/Movies/300 (2007)/300 (2006).3d.sbs.mkv",
|
||||
container: "mkv",
|
||||
name: "300",
|
||||
year: 2006,
|
||||
is3D: true,
|
||||
format3D: "sbs")
|
||||
};
|
||||
yield return new object[]
|
||||
{
|
||||
new VideoFileInfo()
|
||||
{
|
||||
Path = @"/server/Movies/brave (2007)/brave (2006)-trailer.bluray.disc",
|
||||
Container = "disc",
|
||||
Name = "brave",
|
||||
Year = 2006,
|
||||
IsStub = true,
|
||||
StubType = "bluray",
|
||||
}
|
||||
new VideoFileInfo(
|
||||
path: @"/server/Movies/brave (2007)/brave (2006)-trailer.bluray.disc",
|
||||
container: "disc",
|
||||
name: "brave",
|
||||
year: 2006,
|
||||
isStub: true,
|
||||
stubType: "bluray")
|
||||
};
|
||||
yield return new object[]
|
||||
{
|
||||
new VideoFileInfo()
|
||||
{
|
||||
Path = @"/server/Movies/300 (2007)/300 (2006)-trailer.bluray.disc",
|
||||
Container = "disc",
|
||||
Name = "300",
|
||||
Year = 2006,
|
||||
IsStub = true,
|
||||
StubType = "bluray",
|
||||
}
|
||||
new VideoFileInfo(
|
||||
path: @"/server/Movies/300 (2007)/300 (2006)-trailer.bluray.disc",
|
||||
container: "disc",
|
||||
name: "300",
|
||||
year: 2006,
|
||||
isStub: true,
|
||||
stubType: "bluray")
|
||||
};
|
||||
yield return new object[]
|
||||
{
|
||||
new VideoFileInfo()
|
||||
{
|
||||
Path = @"/server/Movies/Brave (2007)/Brave (2006).bluray.disc",
|
||||
Container = "disc",
|
||||
Name = "Brave",
|
||||
Year = 2006,
|
||||
IsStub = true,
|
||||
StubType = "bluray",
|
||||
}
|
||||
new VideoFileInfo(
|
||||
path: @"/server/Movies/Brave (2007)/Brave (2006).bluray.disc",
|
||||
container: "disc",
|
||||
name: "Brave",
|
||||
year: 2006,
|
||||
isStub: true,
|
||||
stubType: "bluray")
|
||||
};
|
||||
yield return new object[]
|
||||
{
|
||||
new VideoFileInfo()
|
||||
{
|
||||
Path = @"/server/Movies/300 (2007)/300 (2006).bluray.disc",
|
||||
Container = "disc",
|
||||
Name = "300",
|
||||
Year = 2006,
|
||||
IsStub = true,
|
||||
StubType = "bluray",
|
||||
}
|
||||
new VideoFileInfo(
|
||||
path: @"/server/Movies/300 (2007)/300 (2006).bluray.disc",
|
||||
container: "disc",
|
||||
name: "300",
|
||||
year: 2006,
|
||||
isStub: true,
|
||||
stubType: "bluray")
|
||||
};
|
||||
yield return new object[]
|
||||
{
|
||||
new VideoFileInfo()
|
||||
{
|
||||
Path = @"/server/Movies/300 (2007)/300 (2006)-trailer.mkv",
|
||||
Container = "mkv",
|
||||
Name = "300",
|
||||
Year = 2006,
|
||||
ExtraType = ExtraType.Trailer,
|
||||
}
|
||||
new VideoFileInfo(
|
||||
path: @"/server/Movies/300 (2007)/300 (2006)-trailer.mkv",
|
||||
container: "mkv",
|
||||
name: "300",
|
||||
year: 2006,
|
||||
extraType: ExtraType.Trailer)
|
||||
};
|
||||
yield return new object[]
|
||||
{
|
||||
new VideoFileInfo()
|
||||
{
|
||||
Path = @"/server/Movies/Brave (2007)/Brave (2006)-trailer.mkv",
|
||||
Container = "mkv",
|
||||
Name = "Brave",
|
||||
Year = 2006,
|
||||
ExtraType = ExtraType.Trailer,
|
||||
}
|
||||
new VideoFileInfo(
|
||||
path: @"/server/Movies/Brave (2007)/Brave (2006)-trailer.mkv",
|
||||
container: "mkv",
|
||||
name: "Brave",
|
||||
year: 2006,
|
||||
extraType: ExtraType.Trailer)
|
||||
};
|
||||
yield return new object[]
|
||||
{
|
||||
new VideoFileInfo()
|
||||
{
|
||||
Path = @"/server/Movies/300 (2007)/300 (2006).mkv",
|
||||
Container = "mkv",
|
||||
Name = "300",
|
||||
Year = 2006
|
||||
}
|
||||
new VideoFileInfo(
|
||||
path: @"/server/Movies/300 (2007)/300 (2006).mkv",
|
||||
container: "mkv",
|
||||
name: "300",
|
||||
year: 2006)
|
||||
};
|
||||
yield return new object[]
|
||||
{
|
||||
new VideoFileInfo()
|
||||
{
|
||||
Path = @"/server/Movies/Bad Boys (1995)/Bad Boys (1995).mkv",
|
||||
Container = "mkv",
|
||||
Name = "Bad Boys",
|
||||
Year = 1995,
|
||||
}
|
||||
new VideoFileInfo(
|
||||
path: @"/server/Movies/Bad Boys (1995)/Bad Boys (1995).mkv",
|
||||
container: "mkv",
|
||||
name: "Bad Boys",
|
||||
year: 1995)
|
||||
};
|
||||
yield return new object[]
|
||||
{
|
||||
new VideoFileInfo()
|
||||
{
|
||||
Path = @"/server/Movies/Brave (2007)/Brave (2006).mkv",
|
||||
Container = "mkv",
|
||||
Name = "Brave",
|
||||
Year = 2006,
|
||||
}
|
||||
new VideoFileInfo(
|
||||
path: @"/server/Movies/Brave (2007)/Brave (2006).mkv",
|
||||
container: "mkv",
|
||||
name: "Brave",
|
||||
year: 2006)
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -194,6 +165,34 @@ namespace Jellyfin.Naming.Tests.Video
|
|||
Assert.Equal(result?.StubType, expectedResult.StubType);
|
||||
Assert.Equal(result?.IsDirectory, expectedResult.IsDirectory);
|
||||
Assert.Equal(result?.FileNameWithoutExtension, expectedResult.FileNameWithoutExtension);
|
||||
Assert.Equal(result?.ToString(), expectedResult.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolveFile_EmptyPath()
|
||||
{
|
||||
var result = new VideoResolver(_namingOptions).ResolveFile(string.Empty);
|
||||
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolveDirectoryTest()
|
||||
{
|
||||
var paths = new[]
|
||||
{
|
||||
@"/Server/Iron Man",
|
||||
@"Batman",
|
||||
string.Empty
|
||||
};
|
||||
|
||||
var resolver = new VideoResolver(_namingOptions);
|
||||
var results = paths.Select(path => resolver.ResolveDirectory(path)).ToList();
|
||||
|
||||
Assert.Equal(3, results.Count);
|
||||
Assert.NotNull(results[0]);
|
||||
Assert.NotNull(results[1]);
|
||||
Assert.Null(results[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user