FF-240 - added recording of metadata info to files

This commit is contained in:
John Andrews
2022-08-05 20:46:20 +12:00
parent bfb2d9f1ab
commit a90045c443
32 changed files with 158 additions and 47 deletions

View File

@@ -5,8 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>FileFlows.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<FileVersion>1.0.0.169</FileVersion>
<ProductVersion>1.0.0.169</ProductVersion>
<FileVersion>1.0.0.170</FileVersion>
<ProductVersion>1.0.0.170</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -13,7 +13,7 @@ namespace FileFlows.AudioNodes
public string[] Genres { get; set; }
public string Encoder { get; set; }
public long Duration { get; set; }
public long BitRate { get; set; }
public long Bitrate { get; set; }
public string Codec { get; set; }
public long Channels { get; set; }
public long Frequency { get; set; }

View File

@@ -163,7 +163,7 @@ namespace FileFlows.AudioNodes
{
br = br.Substring(0, br.IndexOf(" "));
if (long.TryParse(br, out long value))
mi.BitRate = value;
mi.Bitrate = value;
}
}

View File

@@ -6,8 +6,8 @@
<Nullable>enable</Nullable>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<PublishSingleFile>true</PublishSingleFile>
<FileVersion>1.0.0.169</FileVersion>
<ProductVersion>1.0.0.169</ProductVersion>
<FileVersion>1.0.0.170</FileVersion>
<ProductVersion>1.0.0.170</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -18,7 +18,7 @@ namespace FileFlows.AudioNodes
{ "mi.Album", "Album" },
{ "mi.Artist", "Artist" },
{ "mi.ArtistThe", "Artist, The" },
{ "mi.BitRate", 845 },
{ "mi.Bitrate", 845 },
{ "mi.Channels", 2 },
{ "mi.Codec", "flac" },
{ "mi.Date", new DateTime(2020, 05, 23) },

View File

@@ -59,7 +59,7 @@ namespace FileFlows.AudioNodes
variables.AddOrUpdate("audio.ArtistThe", AudioInfo.Artist);
variables.AddOrUpdate("audio.Album", AudioInfo.Album);
variables.AddOrUpdate("audio.BitRate", AudioInfo.BitRate);
variables.AddOrUpdate("audio.Bitrate", AudioInfo.Bitrate);
variables.AddOrUpdate("audio.Channels", AudioInfo.Channels);
variables.AddOrUpdate("audio.Codec", AudioInfo.Codec);
variables.AddOrUpdate("audio.Date", AudioInfo.Date);
@@ -74,9 +74,45 @@ namespace FileFlows.AudioNodes
variables.AddOrUpdate("audio.Disc", AudioInfo.Disc < 1 ? 1 : AudioInfo.Disc);
variables.AddOrUpdate("audio.TotalDiscs", AudioInfo.TotalDiscs < 1 ? 1 : AudioInfo.TotalDiscs);
if (args.OriginalMetadata == null)
{
args.OriginalMetadata = new Dictionary<string, object>();
args.OriginalMetadata.Add("Duration", AudioInfo.Duration);
args.OriginalMetadata.Add("Codec", AudioInfo.Codec);
args.OriginalMetadata.Add("Bitrate", AudioInfo.Bitrate);
args.OriginalMetadata.Add("Channels", AudioInfo.Channels);
AddIfSet(args.OriginalMetadata, "Date", AudioInfo.Date);
AddIfSet(args.OriginalMetadata, "Frequency", AudioInfo.Frequency);
AddIfSet(args.OriginalMetadata, "Encoder", AudioInfo.Encoder);
AddIfSet(args.OriginalMetadata, "Genres", AudioInfo.Genres);
AddIfSet(args.OriginalMetadata, "Language", AudioInfo.Language);
AddIfSet(args.OriginalMetadata, "Title", AudioInfo.Title);
AddIfSet(args.OriginalMetadata, "Track", AudioInfo.Track);
AddIfSet(args.OriginalMetadata, "Disc", AudioInfo.Disc);
AddIfSet(args.OriginalMetadata, "TotalDiscs", AudioInfo.TotalDiscs);
}
args.UpdateVariables(variables);
}
private void AddIfSet(Dictionary<string, object> dict, string name, object value)
{
if (value == null)
return;
if (value is string sValue && string.IsNullOrWhiteSpace(sValue))
return;
if (value is int iValue && iValue < 1)
return;
if (value is TimeSpan tsValue && tsValue.TotalSeconds < 1)
return;
if (value is DateTime dtValue && dtValue.Year <= 1900)
return;
if (value is IEnumerable<string> strList && strList.Any() == false)
return;
dict.Add(name, value);
}
protected AudioInfo GetAudioInfo(NodeParameters args)
{
if (args.Parameters.ContainsKey(Audio_INFO) == false)

View File

@@ -156,13 +156,13 @@ namespace FileFlows.AudioNodes
{
if (SkipIfCodecMatches)
{
args.Logger?.ILog($"Audio file already '{Codec}' at bitrate '{AudioInfo.BitRate}', and set to skip if codec matches");
args.Logger?.ILog($"Audio file already '{Codec}' at bitrate '{AudioInfo.Bitrate}', and set to skip if codec matches");
return 2;
}
if(AudioInfo.BitRate <= Bitrate)
if(AudioInfo.Bitrate <= Bitrate)
{
args.Logger?.ILog($"Audio file already '{Codec}' at bitrate '{AudioInfo.BitRate}'");
args.Logger?.ILog($"Audio file already '{Codec}' at bitrate '{AudioInfo.Bitrate}'");
return 2;
}
}

View File

@@ -4,8 +4,8 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<FileVersion>1.0.0.169</FileVersion>
<ProductVersion>1.0.0.169</ProductVersion>
<FileVersion>1.0.0.170</FileVersion>
<ProductVersion>1.0.0.170</ProductVersion>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>
<Authors>John Andrews</Authors>

View File

@@ -5,8 +5,8 @@
<Nullable>enable</Nullable>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<PublishSingleFile>true</PublishSingleFile>
<FileVersion>1.0.0.169</FileVersion>
<ProductVersion>1.0.0.169</ProductVersion>
<FileVersion>1.0.0.170</FileVersion>
<ProductVersion>1.0.0.170</ProductVersion>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>
<Authors>John Andrews</Authors>

View File

@@ -4,8 +4,8 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<FileVersion>1.0.0.169</FileVersion>
<ProductVersion>1.0.0.169</ProductVersion>
<FileVersion>1.0.0.170</FileVersion>
<ProductVersion>1.0.0.170</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -5,8 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>FileFlows.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<FileVersion>1.0.0.169</FileVersion>
<ProductVersion>1.0.0.169</ProductVersion>
<FileVersion>1.0.0.170</FileVersion>
<ProductVersion>1.0.0.170</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -45,7 +45,15 @@ public class ComicConverter: Node
currentFormat = currentFormat[1..]; // remove the dot
currentFormat = currentFormat.ToLower();
if(currentFormat == Format)
if (args.OriginalMetadata == null)
{
args.OriginalMetadata = new Dictionary<string, object>();
args.OriginalMetadata.Add("Format", currentFormat);
args.OriginalMetadata.Add("Pages", GetPageCount(currentFormat, args.WorkingFile));
}
if (currentFormat == Format)
{
args.Logger?.ILog($"Already in the target format of '{Format}'");
return 2;
@@ -63,6 +71,20 @@ public class ComicConverter: Node
return 1;
}
private int GetPageCount(string format, string workingFile)
{
if (format == null)
return 0;
format = format.ToLower().Trim();
switch (format)
{
case "pdf":
return Helpers.PdfHelper.GetPageCount(workingFile);
default:
return Helpers.GenericExtractor.GetImageCount(workingFile);
}
}
private string CreateComic(NodeParameters args, string directory, string format)
{
string file = Path.Combine(args.TempPath, Guid.NewGuid().ToString() + "." + format);

View File

@@ -25,4 +25,10 @@ internal class GenericExtractor
if (args?.PartPercentageUpdate != null)
args?.PartPercentageUpdate(halfProgress ? 50 : 100);
}
internal static int GetImageCount(string workingFile)
{
var rgxImages = new Regex(@"\.(jpeg|jpg|jpe|png|bmp|tiff|webp|gif)$");
return ArchiveFactory.GetFileParts(workingFile).Where(x => rgxImages.IsMatch(x)).Count();
}
}

View File

@@ -115,4 +115,16 @@ internal class PdfHelper
if (args?.PartPercentageUpdate != null)
args?.PartPercentageUpdate(100);
}
/// <summary>
/// Gets the number of pages in a PDF
/// </summary>
/// <param name="pdfFile">the PDF file</param>
/// <returns>the number of pages in the PDF</returns>
internal static int GetPageCount(string pdfFile)
{
using var library = DocLib.Instance;
using var docReader = library.GetDocReader(pdfFile, new PageDimensions(1080, 1920));
return docReader.GetPageCount();
}
}

View File

@@ -5,8 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>FileFlows.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<FileVersion>1.0.0.169</FileVersion>
<ProductVersion>1.0.0.169</ProductVersion>
<FileVersion>1.0.0.170</FileVersion>
<ProductVersion>1.0.0.170</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -9,8 +9,8 @@
<PublishTrimmed>true</PublishTrimmed>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<PublishSingleFile>true</PublishSingleFile>
<FileVersion>1.0.0.169</FileVersion>
<ProductVersion>1.0.0.169</ProductVersion>
<FileVersion>1.0.0.170</FileVersion>
<ProductVersion>1.0.0.170</ProductVersion>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>
<Authors>John Andrews</Authors>

View File

@@ -5,8 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>FileFlows.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<FileVersion>1.0.0.169</FileVersion>
<ProductVersion>1.0.0.169</ProductVersion>
<FileVersion>1.0.0.170</FileVersion>
<ProductVersion>1.0.0.170</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

Binary file not shown.

Binary file not shown.

View File

@@ -5,8 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>FileFlows.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<FileVersion>1.0.0.169</FileVersion>
<ProductVersion>1.0.0.169</ProductVersion>
<FileVersion>1.0.0.170</FileVersion>
<ProductVersion>1.0.0.170</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -5,8 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>FileFlows.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<FileVersion>1.0.0.169</FileVersion>
<ProductVersion>1.0.0.169</ProductVersion>
<FileVersion>1.0.0.170</FileVersion>
<ProductVersion>1.0.0.170</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -6,8 +6,8 @@
<Nullable>enable</Nullable>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<PublishSingleFile>true</PublishSingleFile>
<FileVersion>1.0.0.169</FileVersion>
<ProductVersion>1.0.0.169</ProductVersion>
<FileVersion>1.0.0.170</FileVersion>
<ProductVersion>1.0.0.170</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -19,7 +19,7 @@ namespace FileFlows.MusicNodes
{ "mi.Album", "Album" },
{ "mi.Artist", "Artist" },
{ "mi.ArtistThe", "Artist, The" },
{ "mi.BitRate", 845 },
{ "mi.Bitrate", 845 },
{ "mi.Channels", 2 },
{ "mi.Codec", "flac" },
{ "mi.Date", new DateTime(2020, 05, 23) },

View File

@@ -13,7 +13,7 @@ namespace FileFlows.MusicNodes
public string[] Genres { get; set; }
public string Encoder { get; set; }
public long Duration { get; set; }
public long BitRate { get; set; }
public long Bitrate { get; set; }
public string Codec { get; set; }
public long Channels { get; set; }
public long Frequency { get; set; }

View File

@@ -163,7 +163,7 @@ namespace FileFlows.MusicNodes
{
br = br.Substring(0, br.IndexOf(" "));
if (long.TryParse(br, out long value))
mi.BitRate = value;
mi.Bitrate = value;
}
}

View File

@@ -6,8 +6,8 @@
<Nullable>enable</Nullable>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<PublishSingleFile>true</PublishSingleFile>
<FileVersion>1.0.0.169</FileVersion>
<ProductVersion>1.0.0.169</ProductVersion>
<FileVersion>1.0.0.170</FileVersion>
<ProductVersion>1.0.0.170</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -152,13 +152,13 @@ namespace FileFlows.MusicNodes
{
if (SkipIfCodecMatches)
{
args.Logger?.ILog($"Music file already '{Codec}' at bitrate '{musicInfo.BitRate}', and set to skip if codec matches");
args.Logger?.ILog($"Music file already '{Codec}' at bitrate '{musicInfo.Bitrate}', and set to skip if codec matches");
return 2;
}
if(musicInfo.BitRate <= Bitrate)
if(musicInfo.Bitrate <= Bitrate)
{
args.Logger?.ILog($"Music file already '{Codec}' at bitrate '{musicInfo.BitRate}'");
args.Logger?.ILog($"Music file already '{Codec}' at bitrate '{musicInfo.Bitrate}'");
return 2;
}
}

View File

@@ -59,7 +59,7 @@ namespace FileFlows.MusicNodes
variables.AddOrUpdate("mi.ArtistThe", musicInfo.Artist);
variables.AddOrUpdate("mi.Album", musicInfo.Album);
variables.AddOrUpdate("mi.BitRate", musicInfo.BitRate);
variables.AddOrUpdate("mi.Bitrate", musicInfo.Bitrate);
variables.AddOrUpdate("mi.Channels", musicInfo.Channels);
variables.AddOrUpdate("mi.Codec", musicInfo.Codec);
variables.AddOrUpdate("mi.Date", musicInfo.Date);

View File

@@ -5,8 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>FileFlows.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<FileVersion>1.0.0.169</FileVersion>
<ProductVersion>1.0.0.169</ProductVersion>
<FileVersion>1.0.0.170</FileVersion>
<ProductVersion>1.0.0.170</ProductVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>

View File

@@ -6,8 +6,8 @@
<Nullable>enable</Nullable>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<PublishSingleFile>true</PublishSingleFile>
<FileVersion>1.0.0.169</FileVersion>
<ProductVersion>1.0.0.169</ProductVersion>
<FileVersion>1.0.0.170</FileVersion>
<ProductVersion>1.0.0.170</ProductVersion>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>
<Authors>John Andrews</Authors>

View File

@@ -6,8 +6,8 @@
<Nullable>enable</Nullable>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<PublishSingleFile>true</PublishSingleFile>
<FileVersion>1.0.0.169</FileVersion>
<ProductVersion>1.0.0.169</ProductVersion>
<FileVersion>1.0.0.170</FileVersion>
<ProductVersion>1.0.0.170</ProductVersion>
<PublishTrimmed>true</PublishTrimmed>
<Company>FileFlows</Company>
<Authors>John Andrews</Authors>

View File

@@ -113,6 +113,41 @@ namespace FileFlows.VideoNodes
variables.AddOrUpdate("vi.Resolution", videoInfo.VideoStreams[0].Width + "x" + videoInfo.VideoStreams[0].Height);
args.UpdateVariables(variables);
if(args.OriginalMetadata == null)
{
args.OriginalMetadata = new Dictionary<string, object>();
args.OriginalMetadata.Add("Duration", videoInfo.VideoStreams[0].Duration);
foreach (var (stream, i) in videoInfo.VideoStreams.Select((value, i) => (value, i)))
{
string prefix = "Video" + (i == 0 ? "" : " " + (i + 1)) + " ";
args.OriginalMetadata.Add(prefix + "Codec", stream.Codec);
args.OriginalMetadata.Add(prefix + "Resolution", stream.Width + "x" + stream.Height + (stream.HDR ? " (HDR)" : string.Empty));
if(stream.Bitrate > 0)
args.OriginalMetadata.Add(prefix + "Bitrate", stream.Bitrate);
}
foreach (var (stream, i) in videoInfo.AudioStreams.Select((value, i) => (value, i)))
{
string prefix = "Audio" + (i == 0 ? "" : " " + (i + 1)) + " ";
args.OriginalMetadata.Add(prefix + "Codec", stream.Codec);
args.OriginalMetadata.Add(prefix + "Channels", stream.Channels);
if (string.IsNullOrEmpty(stream.Title) == false)
args.OriginalMetadata.Add(prefix + "Title", stream.Title);
if(string.IsNullOrEmpty(stream.Language) == false)
args.OriginalMetadata.Add(prefix + "Language", stream.Language);
if (stream.Bitrate > 0)
args.OriginalMetadata.Add(prefix + "Bitrate", stream.Bitrate);
}
foreach (var (strream, i) in videoInfo.SubtitleStreams.Select((value, i) => (value, i)))
{
string prefix = "Audio" + (i == 0 ? "" : " " + (i + 1)) + " ";
args.OriginalMetadata.Add(prefix + "Codec", strream.Codec);
if (string.IsNullOrEmpty(strream.Title) == false)
args.OriginalMetadata.Add(prefix + "Title", strream.Title);
if (string.IsNullOrEmpty(strream.Language) == false)
args.OriginalMetadata.Add(prefix + "Language", strream.Language);
}
}
}
protected VideoInfo GetVideoInfo(NodeParameters args, bool refreshIfFileChanged = true)