re-organized configurations - II
This commit is contained in:
@ -7,9 +7,7 @@ namespace View_by_Distance.Rename.Models.Binder;
|
||||
public class RenameConfiguration
|
||||
{
|
||||
|
||||
public int? EpicYear { get; set; }
|
||||
public string[]? IgnoreExtensions { get; set; }
|
||||
public string[]? IgnoreRulesKeyWords { get; set; }
|
||||
public string[]? ValidImageFormatExtensions { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
@ -20,7 +18,7 @@ public class RenameConfiguration
|
||||
|
||||
private static void PreVerify(IConfigurationRoot configurationRoot, RenameConfiguration? configuration)
|
||||
{
|
||||
if (configuration?.EpicYear is null)
|
||||
if (configuration?.IgnoreExtensions is null)
|
||||
{
|
||||
foreach (IConfigurationProvider configurationProvider in configurationRoot.Providers)
|
||||
{
|
||||
@ -38,7 +36,6 @@ public class RenameConfiguration
|
||||
private static void Verify(RenameConfiguration configuration)
|
||||
{
|
||||
if (configuration.IgnoreExtensions is null || configuration.IgnoreExtensions.Length == 0) throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
|
||||
if (configuration.IgnoreRulesKeyWords is null || configuration.IgnoreRulesKeyWords.Length == 0) throw new NullReferenceException(nameof(configuration.IgnoreRulesKeyWords));
|
||||
if (configuration.ValidImageFormatExtensions is null || configuration.ValidImageFormatExtensions.Length == 0) throw new NullReferenceException(nameof(configuration.ValidImageFormatExtensions));
|
||||
}
|
||||
|
||||
@ -46,15 +43,11 @@ public class RenameConfiguration
|
||||
{
|
||||
Models.RenameConfiguration result;
|
||||
if (configuration is null) throw new NullReferenceException(nameof(configuration));
|
||||
if (configuration.EpicYear is null) throw new NullReferenceException(nameof(configuration.EpicYear));
|
||||
if (configuration.IgnoreExtensions is null) throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
|
||||
if (configuration.IgnoreRulesKeyWords is null) throw new NullReferenceException(nameof(configuration.IgnoreRulesKeyWords));
|
||||
if (configuration.ValidImageFormatExtensions is null) throw new NullReferenceException(nameof(configuration.ValidImageFormatExtensions));
|
||||
Verify(configuration);
|
||||
result = new(metadataConfiguration,
|
||||
configuration.EpicYear.Value,
|
||||
configuration.IgnoreExtensions,
|
||||
configuration.IgnoreRulesKeyWords,
|
||||
configuration.ValidImageFormatExtensions);
|
||||
return result;
|
||||
}
|
||||
|
@ -5,9 +5,7 @@ using System.Text.Json.Serialization;
|
||||
namespace View_by_Distance.Rename.Models;
|
||||
|
||||
public record RenameConfiguration(Shared.Models.MetadataConfiguration MetadataConfiguration,
|
||||
int EpicYear,
|
||||
string[] IgnoreExtensions,
|
||||
string[] IgnoreRulesKeyWords,
|
||||
string[] ValidImageFormatExtensions)
|
||||
{
|
||||
|
||||
|
@ -7,6 +7,7 @@ using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Runtime.InteropServices;
|
||||
using View_by_Distance.Metadata.Models;
|
||||
using View_by_Distance.Metadata.Models.Stateless.Methods;
|
||||
using View_by_Distance.Rename.Models;
|
||||
using View_by_Distance.Shared.Models;
|
||||
using View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
@ -60,8 +61,8 @@ public class Rename : IRename
|
||||
else
|
||||
{
|
||||
CommandTask<CommandResult> commandTask = Cli.Wrap("ffmpeg.exe")
|
||||
// .WithArguments(new[] { "-ss", "00:00:00", "-t", "00:00:00", "-i", files[i], "-qscale:v", "2", "-r", "0.01", $"{fileHolder.Name}-%4d.jpg" })
|
||||
.WithArguments(new[] { "-i", filePath.FullName, "-vframes", "1", $"{filePath.Name}-%4d.jpg" })
|
||||
// .WithArguments(new[] { "-ss", "00:00:00", "-t", "00:00:00", "-i", files[i], "-qScale:v", "2", "-r", "0.01", $"{fileHolder.Name}-%4d.jpg" })
|
||||
.WithArguments(new[] { "-i", filePath.FullName, "-vFrames", "1", $"{filePath.Name}-%4d.jpg" })
|
||||
.WithWorkingDirectory(filePath.DirectoryName)
|
||||
.ExecuteAsync();
|
||||
commandTask.Task.Wait();
|
||||
@ -136,12 +137,11 @@ public class Rename : IRename
|
||||
(ffmpegFiles, ffmpegFilePath) = rename.ConvertAndGetFfmpegFiles(filePath);
|
||||
if (ffmpegFilePath is not null)
|
||||
filePath = ffmpegFilePath;
|
||||
fileInfo = metadata.GetFileInfo(filePath);
|
||||
if (filePath.Id is not null)
|
||||
deterministicHashCode = new(null, filePath.Id, null);
|
||||
else
|
||||
deterministicHashCode = rename.GetDeterministicHashCode(filePath);
|
||||
exifDirectory = metadata.GetMetadataCollection(_RenameConfiguration.MetadataConfiguration, filePath, fileInfo, deterministicHashCode);
|
||||
(fileInfo, exifDirectory) = metadata.GetMetadataCollection(_RenameConfiguration.MetadataConfiguration, filePath, deterministicHashCode);
|
||||
exifDirectories.Add(new(file, fileInfo, exifDirectory));
|
||||
foreach (string ffmpegFile in ffmpegFiles)
|
||||
File.Delete(ffmpegFile);
|
||||
@ -198,17 +198,20 @@ public class Rename : IRename
|
||||
{
|
||||
List<ToDo> results = [];
|
||||
int season;
|
||||
string maker;
|
||||
Record record;
|
||||
string jsonFile;
|
||||
string paddedId;
|
||||
string checkFile;
|
||||
string seasonName;
|
||||
string directoryName;
|
||||
FileHolder fileHolder;
|
||||
string? seasonDirectory;
|
||||
string jsonFileDirectory;
|
||||
string? checkDirectory;
|
||||
const string jpg = ".jpg";
|
||||
string checkFileExtension;
|
||||
List<string> distinct = [];
|
||||
const string jpeg = ".jpeg";
|
||||
string jsonFileSubDirectory;
|
||||
int intMinValueLength = int.MinValue.ToString().Length;
|
||||
VerifyIntMinValueLength(exifDirectories, intMinValueLength);
|
||||
ReadOnlyCollection<Record> records = new((from l in exifDirectories orderby l.DateTime select l).ToArray());
|
||||
@ -220,12 +223,13 @@ public class Rename : IRename
|
||||
fileHolder = new(record.File);
|
||||
if (fileHolder.DirectoryName is null)
|
||||
continue;
|
||||
maker = IMetadata.GetMaker(record.ExifDirectory.ExifDirectoryBase);
|
||||
(season, seasonName) = IDate.GetSeason(record.DateTime.DayOfYear);
|
||||
jsonFileDirectory = Path.GetDirectoryName(record.JsonFile) ?? throw new Exception();
|
||||
checkFileExtension = fileHolder.ExtensionLowered == jpeg ? jpg : fileHolder.ExtensionLowered;
|
||||
seasonDirectory = Path.Combine(fileHolder.DirectoryName, $"{record.DateTime.Year}.{season} {seasonName}");
|
||||
checkDirectory = Path.Combine(fileHolder.DirectoryName, $"{record.DateTime.Year}.{season} {seasonName}{maker}");
|
||||
jsonFileSubDirectory = Path.GetDirectoryName(Path.GetDirectoryName(record.JsonFile)) ?? throw new Exception();
|
||||
paddedId = IId.GetPaddedId(intMinValueLength, _RenameConfiguration.MetadataConfiguration.Offset + i, record.ExifDirectory.Id.Value);
|
||||
checkFile = Path.Combine(seasonDirectory, $"{paddedId}{checkFileExtension}");
|
||||
checkFile = Path.Combine(checkDirectory, $"{paddedId}{checkFileExtension}");
|
||||
if (checkFile == fileHolder.FullName)
|
||||
continue;
|
||||
if (File.Exists(checkFile))
|
||||
@ -234,11 +238,14 @@ public class Rename : IRename
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
}
|
||||
results.Add(new(null, new(record.JsonFile), Path.Combine(jsonFileDirectory, $"{record.ExifDirectory.Id.Value}{checkFileExtension}.json"), JsonFile: true));
|
||||
(directoryName, _) = IPath.GetDirectoryNameAndIndex(_RenameConfiguration.MetadataConfiguration.ResultConfiguration, record.ExifDirectory.Id.Value);
|
||||
jsonFile = Path.Combine(jsonFileSubDirectory, directoryName, $"{record.ExifDirectory.Id.Value}{checkFileExtension}.json");
|
||||
if (record.JsonFile != jsonFile)
|
||||
results.Add(new(null, new(record.JsonFile), jsonFile, JsonFile: true));
|
||||
if (distinct.Contains(checkFile))
|
||||
continue;
|
||||
distinct.Add(checkFile);
|
||||
results.Add(new(seasonDirectory, fileHolder, checkFile, JsonFile: false));
|
||||
results.Add(new(checkDirectory, fileHolder, checkFile, JsonFile: false));
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
@ -263,11 +270,17 @@ public class Rename : IRename
|
||||
foreach (ToDo toDo in toDoCollection)
|
||||
{
|
||||
if (toDo.JsonFile)
|
||||
{
|
||||
if (File.Exists(toDo.File))
|
||||
File.Delete(toDo.File);
|
||||
File.Move(toDo.FileHolder.FullName, toDo.File);
|
||||
}
|
||||
else if (toDo.Directory is null)
|
||||
throw new NotSupportedException();
|
||||
else
|
||||
{
|
||||
if (File.Exists(toDo.File))
|
||||
File.Delete(toDo.File);
|
||||
File.Move(toDo.FileHolder.FullName, toDo.File);
|
||||
results.Add($"{toDo.FileHolder.FullName}\t{toDo.File}");
|
||||
}
|
||||
|
Reference in New Issue
Block a user