FF-1591 - Video Has Stream now uses math value for channels

This commit is contained in:
John Andrews
2024-06-20 07:54:39 +12:00
parent b03bc504d9
commit 4b8afa0ff9
8 changed files with 102 additions and 47 deletions

View File

@@ -52,19 +52,29 @@ public class DeleteSourceDirectory : Node
.TrimEnd('/')
.TrimEnd('\\');
args.Logger?.ILog("Library File Name: " + args.LibraryFileName);
args.Logger?.ILog("Library Path: " + libraryPath);
args.Logger?.ILog("Relative File: " + args.RelativeFile);
//args.Logger?.ILog("IsRemote: " + args.IsRemote);
int pathIndex = args.RelativeFile.IndexOfAny(new[] { '\\', '/' });
if (pathIndex < 0)
string topdir;
if (args.FileService.DirectoryExists(args.LibraryFileName))
{
args.Logger?.ILog("File is in library root, will not delete");
return base.Execute(args);
args.Logger?.ILog("Library Folder Name: " + args.LibraryFileName);
args.Logger?.ILog("Library Path: " + libraryPath);
args.Logger?.ILog("Relative Folder: " + args.RelativeFile);
topdir = args.RelativeFile;
}
else
{
args.Logger?.ILog("Library File Name: " + args.LibraryFileName);
args.Logger?.ILog("Library Path: " + libraryPath);
args.Logger?.ILog("Relative File: " + args.RelativeFile);
string topdir = args.RelativeFile.Substring(0, pathIndex);
int pathIndex = args.RelativeFile.IndexOfAny(['\\', '/']);
if (pathIndex < 0)
{
args.Logger?.ILog("File is in library root, will not delete");
return 1;
}
topdir = args.RelativeFile[..pathIndex];
}
string pathSeparator = args.FileService.PathSeparator.ToString();
@@ -72,25 +82,6 @@ public class DeleteSourceDirectory : Node
string pathToDelete = libraryPath.EndsWith(pathSeparator) ? libraryPath + topdir : libraryPath + pathSeparator + topdir;
args.Logger?.ILog("Path To Delete: " + pathToDelete);
// if (args.IsRemote)
// {
// if (args.LibraryFileName.StartsWith(pathToDelete))
// {
// args.Logger?.ILog("Deleting original file remotely: " + args.LibraryFileName);
// args.DeleteRemote(args.LibraryFileName, false,
// null); // first delete the source file since its in this directory we are deleting
// }
//
// args.Logger?.ILog("Sending request to delete remote path: " + pathToDelete);
//
// bool deleted = args.DeleteRemote(pathToDelete, IfEmpty, IncludePatterns);
// if (deleted)
// args.Logger?.ILog("Successfully deleted remote path: " + pathToDelete);
// else
// args.Logger?.WLog("Failed to delete remote path: " + pathToDelete);
// return deleted ? 1 : 2;
// }
if (IfEmpty)
{
string libFileDirectory = args.IsDirectory ? args.FileName : FileHelper.GetDirectory(args.LibraryFileName);

View File

@@ -82,9 +82,9 @@ public class Matches : Node
return output;
}
if (MathHelper.IsMathOperation(match.Value))
if (args.MathHelper.IsMathOperation(match.Value))
{
if (MathHelper.IsTrue(match.Value, strValue))
if (args.MathHelper.IsTrue(match.Value, strValue))
{
args.Logger?.ILog($"Match found '{match.Value}' = {strValue}");
return output;

Binary file not shown.

Binary file not shown.

View File

@@ -280,6 +280,8 @@ public class FfmpegBuilderAudioAddTrack : FfmpegBuilderNode
if (totalChannels == 8 && codec == "eac3")
totalChannels = 6;
logger?.ILog("Total Channels: " + totalChannels);
return totalChannels;
}

View File

@@ -72,19 +72,13 @@ public class VideoHasStream : VideoNode
[TextVariable(4)]
public string? Language { get; set; }
/// <summary>
/// Gets or sets the number of channels to look for
/// </summary>
[Obsolete]
public float Channels { get; set; }
/// <summary>
/// Gets or sets the number of channels to look for
/// This is a string so math operations can be done
/// </summary>
[ConditionEquals(nameof(Stream), "Audio")]
[MathValue(5)]
public string ChannelsValue { get; set; }
public string Channels { get; set; }
/// <summary>
/// Gets or sets if deleted tracks should also be checked
@@ -131,8 +125,6 @@ public class VideoHasStream : VideoNode
return -1;
}
var channels = ChannelsValue?.EmptyAsNull() ?? (Channels > 0 ? "=" + Channels : string.Empty);
bool found = false;
string title = args.ReplaceVariables(Title, stripMissing: true);
string codec = args.ReplaceVariables(Codec, stripMissing: true);
@@ -179,7 +171,7 @@ public class VideoHasStream : VideoNode
}
else if (this.Stream == "Audio")
{
args.Logger?.ILog("Channels to match: " + channels);
args.Logger?.ILog("Channels to match: " + Channels);
var streams = ffmpegModel == null
? videoInfo.AudioStreams
: ffmpegModel.AudioStreams.Where(x => x.Deleted == false).Select(x => x.Stream).ToList();
@@ -204,9 +196,9 @@ public class VideoHasStream : VideoNode
return false;
}
if (string.IsNullOrWhiteSpace(channels) == false && MathHelper.IsFalse(channels, x.Channels))
if (string.IsNullOrWhiteSpace(Channels) == false && args.MathHelper.IsFalse(Channels, x.Channels))
{
args.Logger.ILog("Channels does not match: " + x.Channels + ", Diff : " + Math.Abs(x.Channels - this.Channels));
args.Logger.ILog("Channels does not match: " + x.Channels + " vs " + Channels);
return false;
}
args.Logger.ILog("Matching audio found: " + x);

View File

@@ -115,7 +115,7 @@ public class VideoHasStreamTests : TestBase
var vii = vi.Read(file);
VideoHasStream node = new();
node.Channels = 5.1f;
node.Channels = "=5.1";
node.Stream = "Audio";
var args = new NodeParameters(file, Logger, false, string.Empty, new LocalFileService());
@@ -132,7 +132,77 @@ public class VideoHasStreamTests : TestBase
}
[TestMethod]
public void VideoHasStream_Audio_Channels_GreaterOrEqual()
{
string file = TestFile_5dot1;
var vi = new VideoInfoHelper(FfmpegPath, Logger);
var vii = vi.Read(file);
VideoHasStream node = new();
node.Channels = ">=4.5";
node.Stream = "Audio";
var args = new NodeParameters(file, Logger, false, string.Empty, new LocalFileService());
args.GetToolPathActual = (string tool) => FfmpegPath;
args.TempPath = TempPath;
var vf = new VideoFile();
vf.PreExecute(args);
Assert.AreEqual(1, vf.Execute(args));
int output = node.Execute(args);
Assert.AreEqual(1, output);
}
[TestMethod]
public void VideoHasStream_Audio_Channels_Between()
{
string file = TestFile_5dot1;
var vi = new VideoInfoHelper(FfmpegPath, Logger);
var vii = vi.Read(file);
VideoHasStream node = new();
node.Channels = "5<>5.1";
node.Stream = "Audio";
var args = new NodeParameters(file, Logger, false, string.Empty, new LocalFileService());
args.GetToolPathActual = (string tool) => FfmpegPath;
args.TempPath = TempPath;
var vf = new VideoFile();
vf.PreExecute(args);
Assert.AreEqual(1, vf.Execute(args));
int output = node.Execute(args);
Assert.AreEqual(1, output);
}
[TestMethod]
public void VideoHasStream_Audio_Channels_NotBetween()
{
string file = TestFile_5dot1;
var vi = new VideoInfoHelper(FfmpegPath, Logger);
var vii = vi.Read(file);
VideoHasStream node = new();
node.Channels = "2><3";
node.Stream = "Audio";
var args = new NodeParameters(file, Logger, false, string.Empty, new LocalFileService());
args.GetToolPathActual = (string tool) => FfmpegPath;
args.TempPath = TempPath;
var vf = new VideoFile();
vf.PreExecute(args);
Assert.AreEqual(1, vf.Execute(args));
int output = node.Execute(args);
Assert.AreEqual(1, output);
}
[TestMethod]
public void VideoHasStream_Audio_Channels_Pass_61()
{
@@ -203,7 +273,7 @@ public class VideoHasStreamTests : TestBase
Stream #0:1(ger): Audio: dts (DTS-ES), 48000 Hz, 6.1, fltp, 1536 kb/s (default)");
VideoHasStream node = new();
node.Channels = 6.1f;
node.Channels = "=6.1";
node.Stream = "Audio";
var args = new NodeParameters(null, Logger, false, string.Empty, new LocalFileService());
@@ -223,7 +293,7 @@ public class VideoHasStreamTests : TestBase
var vii = vi.Read(file);
VideoHasStream node = new();
node.Channels = 2;
node.Channels = "=2";
node.Stream = "Audio";
var args = new NodeParameters(file, new TestLogger(), false, string.Empty, null);;

View File

@@ -887,7 +887,7 @@
"Language": "Language",
"Language-Help": "A regular expression used to test the stream language",
"Channels": "Channels",
"Channels-Help": "The number of channels to test for. Set to 0 to ignore this check",
"Channels-Help": "The number of channels to test for. Leave blank to ignore this check",
"CheckDeleted": "Check Deleted",
"CheckDeleted-Help": "If deleted tracks should also be checked",
"Invert": "Invert",