CliWrap and ffmpeg
This commit is contained in:
@ -119,7 +119,7 @@ public class MoveById
|
|||||||
if (allFiles.Contains($"{fileHolder.FullName}.id"))
|
if (allFiles.Contains($"{fileHolder.FullName}.id"))
|
||||||
continue;
|
continue;
|
||||||
isValidImageFormatExtension = _PropertyConfiguration.ValidImageFormatExtensions.Contains(fileHolder.ExtensionLowered);
|
isValidImageFormatExtension = _PropertyConfiguration.ValidImageFormatExtensions.Contains(fileHolder.ExtensionLowered);
|
||||||
isIgnoreExtension = isValidImageFormatExtension && _Configuration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered);
|
isIgnoreExtension = isValidImageFormatExtension && _PropertyConfiguration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered);
|
||||||
nameWithoutExtensionIsIdFormat = Shared.Models.Stateless.Methods.IProperty.NameWithoutExtensionIsIdFormat(fileHolder);
|
nameWithoutExtensionIsIdFormat = Shared.Models.Stateless.Methods.IProperty.NameWithoutExtensionIsIdFormat(fileHolder);
|
||||||
if (!isIgnoreExtension && isValidImageFormatExtension)
|
if (!isIgnoreExtension && isValidImageFormatExtension)
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using CliWrap;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using ShellProgressBar;
|
using ShellProgressBar;
|
||||||
@ -149,6 +150,7 @@ public class Rename
|
|||||||
DateTime? dateTime;
|
DateTime? dateTime;
|
||||||
DateTime?[] dateTimes;
|
DateTime?[] dateTimes;
|
||||||
FileHolder fileHolder;
|
FileHolder fileHolder;
|
||||||
|
string[]? ffmpegFiles;
|
||||||
bool isIgnoreExtension;
|
bool isIgnoreExtension;
|
||||||
string checkFileExtension;
|
string checkFileExtension;
|
||||||
DateTime? minimumDateTime;
|
DateTime? minimumDateTime;
|
||||||
@ -187,13 +189,41 @@ public class Rename
|
|||||||
results.Add(new(fileHolder, checkFile));
|
results.Add(new(fileHolder, checkFile));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (fileHolder.ExtensionLowered == ".id" || fileHolder.DirectoryName is null)
|
if (fileHolder.ExtensionLowered == ".id" || fileHolder.ExtensionLowered == ".lsv" || fileHolder.DirectoryName is null)
|
||||||
continue;
|
continue;
|
||||||
if (files.Contains($"{fileHolder.FullName}.id"))
|
if (files.Contains($"{fileHolder.FullName}.id"))
|
||||||
continue;
|
continue;
|
||||||
isValidImageFormatExtension = _PropertyConfiguration.ValidImageFormatExtensions.Contains(fileHolder.ExtensionLowered);
|
|
||||||
isIgnoreExtension = isValidImageFormatExtension && _Configuration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered);
|
|
||||||
nameWithoutExtensionIsIdFormat = Shared.Models.Stateless.Methods.IProperty.NameWithoutExtensionIsIdFormat(fileHolder);
|
nameWithoutExtensionIsIdFormat = Shared.Models.Stateless.Methods.IProperty.NameWithoutExtensionIsIdFormat(fileHolder);
|
||||||
|
if (nameWithoutExtensionIsIdFormat)
|
||||||
|
continue;
|
||||||
|
isValidImageFormatExtension = _PropertyConfiguration.ValidImageFormatExtensions.Contains(fileHolder.ExtensionLowered);
|
||||||
|
isIgnoreExtension = isValidImageFormatExtension && _PropertyConfiguration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered);
|
||||||
|
if (!isIgnoreExtension && isValidImageFormatExtension)
|
||||||
|
ffmpegFiles = null;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{ directories = MetadataExtractor.ImageMetadataReader.ReadMetadata(file); }
|
||||||
|
catch (Exception) { continue; }
|
||||||
|
CommandTask<CommandResult> result = Cli.Wrap("ffmpeg.exe")
|
||||||
|
// .WithArguments(new[] { "-ss", "00:00:00", "-t", "00:00:00", "-i", file, "-qscale:v", "2", "-r", "0.01", $"{fileHolder.Name}-%4d.jpg" })
|
||||||
|
.WithArguments(new[] { "-i", file, "-vframes", "1", $"{fileHolder.Name}-%4d.jpg" })
|
||||||
|
.WithWorkingDirectory(fileHolder.DirectoryName)
|
||||||
|
.ExecuteAsync();
|
||||||
|
result.Task.Wait();
|
||||||
|
ffmpegFiles = Directory.GetFiles(fileHolder.DirectoryName, $"{fileHolder.Name}-*.jpg", SearchOption.TopDirectoryOnly);
|
||||||
|
if (!ffmpegFiles.Any())
|
||||||
|
continue;
|
||||||
|
fileHolder = new(ffmpegFiles.First());
|
||||||
|
if (!fileHolder.Name.EndsWith("-0001.jpg"))
|
||||||
|
throw new Exception();
|
||||||
|
isValidImageFormatExtension = _PropertyConfiguration.ValidImageFormatExtensions.Contains(fileHolder.ExtensionLowered);
|
||||||
|
isIgnoreExtension = isValidImageFormatExtension && _PropertyConfiguration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered);
|
||||||
|
if (isIgnoreExtension || !isValidImageFormatExtension)
|
||||||
|
continue;
|
||||||
|
if (fileHolder.DirectoryName is null)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!isIgnoreExtension && isValidImageFormatExtension)
|
if (!isIgnoreExtension && isValidImageFormatExtension)
|
||||||
{
|
{
|
||||||
if (fileHolder.ExtensionLowered == jpeg)
|
if (fileHolder.ExtensionLowered == jpeg)
|
||||||
@ -222,8 +252,6 @@ public class Rename
|
|||||||
if (fileHolder.DirectoryName is null)
|
if (fileHolder.DirectoryName is null)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (nameWithoutExtensionIsIdFormat)
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
(dateTimes, id, message) = Shared.Models.Stateless.Methods.IProperty.Get(fileHolder, isIgnoreExtension, isValidImageFormatExtension);
|
(dateTimes, id, message) = Shared.Models.Stateless.Methods.IProperty.Get(fileHolder, isIgnoreExtension, isValidImageFormatExtension);
|
||||||
minimumDateTime = dateTimes.Min();
|
minimumDateTime = dateTimes.Min();
|
||||||
@ -240,7 +268,7 @@ public class Rename
|
|||||||
fileName = Path.GetFileName(fileHolder.DirectoryName);
|
fileName = Path.GetFileName(fileHolder.DirectoryName);
|
||||||
if (fileName.Length < 4 || !int.TryParse(fileName[..4], out int year))
|
if (fileName.Length < 4 || !int.TryParse(fileName[..4], out int year))
|
||||||
year = minimumDateTime.Value.Year;
|
year = minimumDateTime.Value.Year;
|
||||||
if (_Configuration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered))
|
if (_PropertyConfiguration.IgnoreExtensions.Contains(fileHolder.ExtensionLowered))
|
||||||
continue;
|
continue;
|
||||||
try
|
try
|
||||||
{ directories = MetadataExtractor.ImageMetadataReader.ReadMetadata(file); }
|
{ directories = MetadataExtractor.ImageMetadataReader.ReadMetadata(file); }
|
||||||
@ -262,6 +290,14 @@ public class Rename
|
|||||||
}
|
}
|
||||||
if (id is null)
|
if (id is null)
|
||||||
continue;
|
continue;
|
||||||
|
if (ffmpegFiles is not null)
|
||||||
|
{
|
||||||
|
foreach (string ffmpegFile in ffmpegFiles)
|
||||||
|
File.Delete(ffmpegFile);
|
||||||
|
fileHolder = new(file);
|
||||||
|
if (fileHolder.DirectoryName is null)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
checkFileExtension = fileHolder.ExtensionLowered == jpeg ? jpg : fileHolder.ExtensionLowered;
|
checkFileExtension = fileHolder.ExtensionLowered == jpeg ? jpg : fileHolder.ExtensionLowered;
|
||||||
checkFile = Path.Combine(fileHolder.DirectoryName, $"{id.Value}{checkFileExtension}");
|
checkFile = Path.Combine(fileHolder.DirectoryName, $"{id.Value}{checkFileExtension}");
|
||||||
if (checkFile == fileHolder.FullName)
|
if (checkFile == fileHolder.FullName)
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
<SupportedPlatform Include="browser" />
|
<SupportedPlatform Include="browser" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="CliWrap" Version="3.6.3" />
|
||||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
||||||
|
Reference in New Issue
Block a user