FF-1020 - added sample rate to add audio track

This commit is contained in:
John Andrews
2023-07-22 00:25:36 +12:00
parent 9a813b5085
commit 68d9ff0521
9 changed files with 6 additions and 368 deletions

View File

@@ -1,42 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<FileVersion>1.1.1.528</FileVersion>
<ProductVersion>1.1.1.528</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>
<Authors>John Andrews</Authors>
<Product>Collection Nodes</Product>
<PackageProjectUrl>https://fileflows.com/</PackageProjectUrl>
<Description>Nodes that provide the ability to read and write from collections.
Allows storing of data to database that persists between flow executions.</Description>
</PropertyGroup>
<ItemGroup Condition=" '$(Configuration)' == 'Debug'">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.4" />
</ItemGroup>
<ItemGroup>
<None Remove="CollectionNodes.en.json" />
</ItemGroup>
<ItemGroup>
<Content Include="CollectionNodes.en.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="NPoco" Version="5.7.1" />
<PackageReference Include="System.Data.SQLite" Version="1.0.117" />
</ItemGroup>
<ItemGroup>
<Reference Include="Plugin">
<HintPath>..\FileFlows.Plugin.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
</ItemGroup>
</Project>

View File

@@ -1,26 +0,0 @@
{
"Flow":{
"Parts": {
"DataCollection": {
"Description": "Checks a database for a key and a matching value. If not in the database, will add it to the database.\n\nOutput 1: Not in database\nOutput 2: In database and the same\nOutput 3: In database but value different.",
"Outputs": {
"1": "Not in database",
"2": "In database and same",
"3": "In database but value different"
},
"Fields": {
"DatabaseFolder": "Database Folder",
"DatabaseFolder-Help": "The location to save the SQLite database file. This folder must be accessible by every processing node.",
"DatabaseFile": "Database File",
"DatabaseFile-Help": "The SQLite database file. This file must be accessible by every processing node.",
"Key": "Key",
"Key-Help": "The key value used to index the collection. If left empty the original filename will be used.",
"Value": "Value",
"Value-Help": "The value to check the collection for. Can be a variable from a previous node.",
"UpdateIfDifferent": "Update If Different",
"UpdateIfDifferent-Help": "If the value in the collection should be updated if the stored value is different."
}
}
}
}
}

View File

@@ -1,6 +0,0 @@
global using System;
global using System.Collections.Generic;
global using System.Linq;
global using System.Text;
global using System.Threading.Tasks;
global using FileFlows.Plugin;

View File

@@ -1,142 +0,0 @@
using FileFlows.Plugin.Attributes;
using NPoco;
using System.ComponentModel.DataAnnotations;
using System.Data.SQLite;
namespace CollectionNodes
{
public class DataCollection : Node
{
public override int Inputs => 1;
public override int Outputs => 3;
public override FlowElementType Type => FlowElementType.Logic;
public override string Icon => "fas fa-database";
private Dictionary<string, object> _Variables;
public override Dictionary<string, object> Variables => _Variables;
public DataCollection()
{
_Variables = new Dictionary<string, object>()
{
{ "dc.Value", "ValueFromDataCollection" }
};
}
[Required]
[Folder(1)]
public string DatabaseFolder { get; set; }
[Required]
[Text(2)]
public string DatabaseFile { get; set; }
[TextVariable(3)]
public string Key { get; set; }
[Required]
[TextVariable(4)]
public string Value { get; set; }
[Boolean(5)]
public bool UpdateIfDifferent { get; set; }
public override int Execute(NodeParameters args)
{
string key = args.ReplaceVariables(Key ?? string.Empty, true);
string value = args.ReplaceVariables(Value ?? string.Empty, true);
if (string.IsNullOrEmpty(key))
{
args.Logger?.ELog("Key not set using filename");
key = args.FileName;
}
if (string.IsNullOrEmpty(value))
{
args.Logger?.ELog("Value not set");
return -1;
}
if (args.Variables.ContainsKey(value))
{
value = args.Variables[value]?.ToString() ?? string.Empty;
}
string dbFile = Path.Combine(
args.ReplaceVariables(this.DatabaseFolder, stripMissing: true),
args.ReplaceVariables(this.DatabaseFile, stripMissing: true)
);
CreateDatabaseIfNotExists(dbFile);
var db = new Database($"Data Source={dbFile};Version=3;", null, SQLiteFactory.Instance);
string result = db.ExecuteScalar<string>($"select {nameof(DbObject.Value)} from {nameof(DbObject)} where {nameof(DbObject.Key)} = @0", key);
if(result == null)
{
args.Logger?.ILog("Key not in database");
db.Execute($"insert into {nameof(DbObject)} values (@0, @1)", key, value);
args.UpdateVariables(new Dictionary<string, object>
{
{ "dc.Value", value },
});
return 1;
}
if (result == value)
{
args.Logger?.ILog("Value matches what was already in database");
args.UpdateVariables(new Dictionary<string, object>
{
{ "dc.Value", value },
});
return 2;
}
args.UpdateVariables(new Dictionary<string, object>
{
{ "dc.Value", result },
});
args.Logger?.ILog("Key value did not match what was in database");
if (UpdateIfDifferent)
{
db.Execute($"update {nameof(DbObject)} set {nameof(DbObject.Value)} = @1 where {nameof(DbObject.Key)} = @0", key, value);
}
return 3;
}
private void CreateDatabaseIfNotExists(string dbFile)
{
if (System.IO.File.Exists(dbFile) == false)
SQLiteConnection.CreateFile(dbFile);
else
{
// create backup
File.Copy(dbFile, dbFile + ".backup", true);
}
using (var con = new SQLiteConnection($"Data Source={dbFile};Version=3;"))
{
con.Open();
using (var cmd = new SQLiteCommand($"SELECT name FROM sqlite_master WHERE type='table' AND name='{nameof(DbObject)}'", con))
{
if (cmd.ExecuteScalar() != null)
return;// tables exist, all good
}
using (var cmd = new SQLiteCommand(CreateDbScript, con))
{
cmd.ExecuteNonQuery();
}
con.Close();
}
}
private const string CreateDbScript = @$"CREATE TABLE {nameof(DbObject)}(
Key VARCHAR(1024) NOT NULL PRIMARY KEY,
Value TEXT NOT NULL
);";
private class DbObject
{
public string Key { get; set; }
public string Value { get; set; }
}
}
}

View File

@@ -1,19 +0,0 @@
using FileFlows.Plugin.Attributes;
using System.ComponentModel.DataAnnotations;
namespace CollectionNodes;
public class Plugin : IPlugin
{
public Guid Uid => new Guid("e62e3b2e-5147-4732-92df-f6fbbdb3bb08");
public string Name => "Collection Nodes";
public string MinimumVersion => "1.0.4.2019";
[Folder(1)]
[Required]
public string DataDirectory { get; set; }
public void Init()
{
}
}

View File

@@ -1,68 +0,0 @@
#if(DEBUG)
namespace CollectionNodes.Tests
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class DataCollectionTests
{
[TestMethod]
public void DataCollection_NotIn()
{
var logger =new TestLogger();
var args = new NodeParameters(@"D:\videos\injustice.mkv", logger, false, "");
string dbFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".sqlite");
var dc = new DataCollection()
{
Value = "Checksum",
DatabaseFile = dbFile,
UpdateIfDifferent = true,
};
args.Variables.Add("Checksum", "batman");
var output = dc.Execute(args);
Assert.AreEqual(1, output);
}
[TestMethod]
public void DataCollection_InAndSame()
{
var logger = new TestLogger();
var args = new NodeParameters(@"D:\videos\injustice.mkv", logger, false, "");
string dbFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".sqlite");
var dc = new DataCollection()
{
Value = "Checksum",
DatabaseFile = dbFile,
UpdateIfDifferent = true,
};
args.Variables.Add("Checksum", "batman");
var output = dc.Execute(args);
Assert.AreEqual(1, output);
var output2 = dc.Execute(args);
Assert.AreEqual(2, output2);
}
[TestMethod]
public void DataCollection_InAndNotSame()
{
var logger = new TestLogger();
var args = new NodeParameters(@"D:\videos\injustice.mkv", logger, false, "");
string dbFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".sqlite");
var dc = new DataCollection()
{
Value = "Checksum",
DatabaseFile = dbFile,
UpdateIfDifferent = true,
};
args.Variables.Add("Checksum", "batman");
var output = dc.Execute(args);
Assert.AreEqual(1, output);
args.Variables["Checksum"] = "joker";
var output3 = dc.Execute(args);
Assert.AreEqual(3, output3);
}
}
}
#endif

View File

@@ -1,53 +0,0 @@
#if(DEBUG)
namespace CollectionNodes.Tests
{
using FileFlows.Plugin;
using System;
using System.Collections.Generic;
using System.Linq;
internal class TestLogger : ILogger
{
private List<string> Messages = new List<string>();
public void DLog(params object[] args) => Log("DBUG", args);
public void ELog(params object[] args) => Log("ERRR", args);
public void ILog(params object[] args) => Log("INFO", args);
public void WLog(params object[] args) => Log("WARN", args);
private void Log(string type, object[] args)
{
if (args == null || args.Length == 0)
return;
string message = type + " -> " +
string.Join(", ", args.Select(x =>
x == null ? "null" :
x.GetType().IsPrimitive || x is string ? x.ToString() :
System.Text.Json.JsonSerializer.Serialize(x)));
Messages.Add(message);
}
public bool Contains(string message)
{
if (string.IsNullOrWhiteSpace(message))
return false;
string log = string.Join(Environment.NewLine, Messages);
return log.Contains(message);
}
public string GetTail(int length = 50)
{
if (length <= 0)
length = 50;
if (Messages.Count <= length)
return string.Join(Environment.NewLine, Messages);
return string.Join(Environment.NewLine, Messages.TakeLast(length));
}
}
}
#endif

View File

@@ -11,8 +11,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MetaNodes", "MetaNodes\Meta
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChecksumNodes", "ChecksumNodes\ChecksumNodes.csproj", "{910B0A24-0E5C-4E1D-9C52-D537F896DE02}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CollectionNodes", "CollectionNodes\CollectionNodes.csproj", "{4211AAE9-0764-4626-B0F2-089A466E002A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmailNodes", "EmailNodes\EmailNodes.csproj", "{8F2739B8-2BD6-4AAC-A54B-2EE1B4AAF559}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gotify", "Gotify\Gotify.csproj", "{18E7013A-BF85-47FA-806C-934267C7BCA5}"
@@ -53,10 +51,6 @@ Global
{910B0A24-0E5C-4E1D-9C52-D537F896DE02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{910B0A24-0E5C-4E1D-9C52-D537F896DE02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{910B0A24-0E5C-4E1D-9C52-D537F896DE02}.Release|Any CPU.Build.0 = Release|Any CPU
{4211AAE9-0764-4626-B0F2-089A466E002A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4211AAE9-0764-4626-B0F2-089A466E002A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4211AAE9-0764-4626-B0F2-089A466E002A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4211AAE9-0764-4626-B0F2-089A466E002A}.Release|Any CPU.Build.0 = Release|Any CPU
{8F2739B8-2BD6-4AAC-A54B-2EE1B4AAF559}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8F2739B8-2BD6-4AAC-A54B-2EE1B4AAF559}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F2739B8-2BD6-4AAC-A54B-2EE1B4AAF559}.Release|Any CPU.ActiveCfg = Release|Any CPU

View File

@@ -131,12 +131,12 @@ public class FfmpegBuilderAudioAddTrack : FfmpegBuilderNode
{
new () { Label = "Automatic", Value = 0},
new () { Label = "Same as source", Value = 1},
new () { Label = "44.1Khz", Value = 44100 },
new () { Label = "48Khz", Value = 48000 },
new () { Label = "88.2Khz", Value = 88200 },
new () { Label = "96Khz", Value = 96000 },
new () { Label = "176.4Khz", Value = 176400 },
new () { Label = "192Khz", Value = 192000 }
new () { Label = "44100", Value = 44100 },
new () { Label = "48000", Value = 48000 },
new () { Label = "88200", Value = 88200 },
new () { Label = "96000", Value = 96000 },
new () { Label = "176400", Value = 176400 },
new () { Label = "192000", Value = 192000 }
};
}
return _SampleRateOptions;