Keyword to work with Amazon

This commit is contained in:
2024-02-04 09:38:40 -07:00
parent 4081a73b9d
commit 1200780eee
38 changed files with 325 additions and 287 deletions

View File

@ -60,10 +60,10 @@ public class DuplicateSearch
File.WriteAllText(Path.Combine(alongSideDirectory, $"{directoryName}-{ticks}.json"), json);
}
private static void Move(ILogger<Program>? logger, long ticks, string destinationRoot, List<(FileHolder ImageFileHolder, string Destination)> collection)
private static void Move(ILogger<Program>? logger, long ticks, string destinationRoot, List<(FilePath FilePath, string Destination)> collection)
{
StringBuilder stringBuilder = new();
foreach ((FileHolder fileHolder, string destination) in collection)
foreach ((FilePath fileHolder, string destination) in collection)
{
_ = stringBuilder.AppendLine(fileHolder.FullName);
_ = stringBuilder.AppendLine(destination);
@ -77,12 +77,12 @@ public class DuplicateSearch
break;
}
logger?.LogInformation(". . .");
foreach ((FileHolder fileHolder, string destination) in collection)
foreach ((FilePath filePath, string destination) in collection)
{
try
{ File.Move(fileHolder.FullName, destination); }
{ File.Move(filePath.FullName, destination); }
catch (Exception exception)
{ logger?.LogError(exception, $"Failed to move <{fileHolder.FullName}>"); }
{ logger?.LogError(exception, $"Failed to move <{filePath.FullName}>"); }
}
logger?.LogInformation($"{collection.Count} file(s) moved");
for (int y = 0; y < int.MaxValue; y++)
@ -91,14 +91,14 @@ public class DuplicateSearch
if (System.Console.ReadKey().Key != ConsoleKey.Y)
continue;
logger?.LogInformation(". . .");
foreach ((FileHolder fileHolder, string destination) in collection)
foreach ((FilePath filePath, string destination) in collection)
{
if (!File.Exists(destination))
continue;
if (File.Exists(fileHolder.FullName))
if (File.Exists(filePath.FullName))
continue;
try
{ File.Move(destination, fileHolder.FullName); }
{ File.Move(destination, filePath.FullName); }
catch (Exception exception)
{ logger?.LogError(exception, $"Failed to move <{destination}>"); }
}
@ -119,7 +119,7 @@ public class DuplicateSearch
if (System.Console.ReadKey().Key != ConsoleKey.Y)
continue;
logger?.LogInformation(". . .");
List<(FileHolder ImageFileHolder, string Destination)> collection = GetCollectionAndCreateDirectories(idToCollection);
List<(FilePath FilePath, string Destination)> collection = GetCollectionAndCreateDirectories(idToCollection);
Move(logger, ticks, destinationRoot, collection);
}
}
@ -170,7 +170,7 @@ public class DuplicateSearch
{
if (item.Property?.Id is null)
{
if (int.TryParse(item.ImageFileHolder.NameWithoutExtension, out int id))
if (int.TryParse(item.FilePath.NameWithoutExtension, out int id))
continue;
continue;
}
@ -188,7 +188,7 @@ public class DuplicateSearch
if (mappingFromItem is not null)
{
resizedFileHolder = Shared.Models.Stateless.Methods.IFileHolder.Get(mappingFromItem.ResizedFileHolder.FullName.Replace($"0{duplicates}", $"1{duplicates}"));
collection[0] = new(mappingFromItem.ContainerDateTimes, item.Property.DateTimeDigitized, item.Property.DateTimeOriginal, mappingFromItem.Id, mappingFromItem.ImageFileHolder, mappingFromItem.IsWrongYear, item.Property.Keywords ?? [], mappingFromItem.MinimumDateTime, item.Property.Model, mappingFromItem.RelativePath, resizedFileHolder);
collection[0] = new(mappingFromItem.ContainerDateTimes, item.Property.DateTimeDigitized, item.Property.DateTimeOriginal, mappingFromItem.Id, mappingFromItem.FilePath, mappingFromItem.IsWrongYear, item.Property.Keywords ?? [], mappingFromItem.MinimumDateTime, item.Property.Model, mappingFromItem.RelativePath, resizedFileHolder);
}
}
resizedFileHolder = Shared.Models.Stateless.Methods.IFileHolder.Get(string.Concat(Path.Combine(destinationRoot, directory), item.RelativePath));
@ -199,9 +199,9 @@ public class DuplicateSearch
return results;
}
private static List<(FileHolder ImageFileHolder, string Destination)> GetCollectionAndCreateDirectories(Dictionary<int, List<MappingFromItem?>> idToCollection)
private static List<(FilePath FilePath, string Destination)> GetCollectionAndCreateDirectories(Dictionary<int, List<MappingFromItem?>> idToCollection)
{
List<(FileHolder ImageFileHolder, string Destination)> results = [];
List<(FilePath FilePath, string Destination)> results = [];
List<string> collection = [];
foreach (KeyValuePair<int, List<MappingFromItem?>> keyValuePair in idToCollection)
{
@ -209,10 +209,10 @@ public class DuplicateSearch
{
if (mappingFromItem?.ResizedFileHolder.DirectoryName is null)
continue;
if (!mappingFromItem.ImageFileHolder.Exists || mappingFromItem.ResizedFileHolder.Exists)
if (mappingFromItem.ResizedFileHolder.Exists)
continue;
collection.Add(mappingFromItem.ResizedFileHolder.DirectoryName);
results.Add(new(mappingFromItem.ImageFileHolder, mappingFromItem.ResizedFileHolder.FullName));
results.Add(new(mappingFromItem.FilePath, mappingFromItem.ResizedFileHolder.FullName));
}
}
foreach (string directory in collection.Distinct())