Moved from Google Photos

This commit is contained in:
Mike Phares 2023-05-08 08:39:04 -07:00
parent 0ca53436e5
commit aec9d0a55d
6 changed files with 42 additions and 23 deletions

View File

@ -59,13 +59,13 @@ public class DateGroup
string aPropertySingletonDirectory = Path.Combine(aResultsFullGroupDirectory, "{}"); string aPropertySingletonDirectory = Path.Combine(aResultsFullGroupDirectory, "{}");
if (!Directory.Exists(aPropertySingletonDirectory)) if (!Directory.Exists(aPropertySingletonDirectory))
_ = Directory.CreateDirectory(aPropertySingletonDirectory); _ = Directory.CreateDirectory(aPropertySingletonDirectory);
(int f, Container[] containers) = Shared.Models.Stateless.Methods.IContainer.GetContainers(propertyConfiguration, aPropertySingletonDirectory); (int t, Container[] containers) = Shared.Models.Stateless.Methods.IContainer.GetContainers(propertyConfiguration, aPropertySingletonDirectory);
A_Property propertyLogic = GetPropertyLogic(reverse, aResultsFullGroupDirectory, aResultsFullGroupDirectory); A_Property propertyLogic = GetPropertyLogic(reverse, aResultsFullGroupDirectory, aResultsFullGroupDirectory);
if (propertyLogic.ExceptionsDirectories.Any()) if (propertyLogic.ExceptionsDirectories.Any())
throw new Exception(); throw new Exception();
if (propertyConfiguration.PopulatePropertyId && (configuration.ByCreateDateShortcut || configuration.ByHash) && Shared.Models.Stateless.Methods.IProperty.Any(containers)) if (propertyConfiguration.PopulatePropertyId && (configuration.ByCreateDateShortcut || configuration.ByHash) && Shared.Models.Stateless.Methods.IProperty.Any(containers))
{ {
propertyLogic.SavePropertyParallelWork(ticks, containers); propertyLogic.SavePropertyParallelWork(ticks, t, containers);
if (appSettings.MaxDegreeOfParallelism < 2) if (appSettings.MaxDegreeOfParallelism < 2)
ticks = LogDelta(ticks, nameof(A_Property.SavePropertyParallelWork)); ticks = LogDelta(ticks, nameof(A_Property.SavePropertyParallelWork));
if (propertyLogic.ExceptionsDirectories.Any()) if (propertyLogic.ExceptionsDirectories.Any())
@ -213,10 +213,10 @@ public class DateGroup
throw new Exception(); throw new Exception();
dateTimes = new() { item.ImageFileHolder.LastWriteTime.Value }; dateTimes = new() { item.ImageFileHolder.LastWriteTime.Value };
} }
if (item.ImageFileHolder.LastWriteTime is not null && item.Property is null) if (item.Property is not null && item.Property.DateTimeOriginal is not null)
dateTime = item.ImageFileHolder.LastWriteTime.Value;
else if (item.Property is not null && item.Property.DateTimeOriginal is not null)
dateTime = item.Property.DateTimeOriginal.Value; dateTime = item.Property.DateTimeOriginal.Value;
else if (item.ImageFileHolder.LastWriteTime is not null && item.Property is null)
dateTime = item.ImageFileHolder.LastWriteTime.Value;
else else
dateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property); dateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
day = dateTime.ToString("MM-dd"); day = dateTime.ToString("MM-dd");

View File

@ -19,7 +19,7 @@
"xxxRootDirectory": "F:/Tmp/Phares/Compare/Not-Copy-Copy-1e85c0ba", "xxxRootDirectory": "F:/Tmp/Phares/Compare/Not-Copy-Copy-1e85c0ba",
"xxxxRootDirectory": "C:/Tmp/Phares/Compare/Not-Copy-Copy-1e85c0ba", "xxxxRootDirectory": "C:/Tmp/Phares/Compare/Not-Copy-Copy-1e85c0ba",
"xxxxxRootDirectory": "F:/Tmp/Phares/2022-11-03-DCIM/DCIM/100D3400 2022", "xxxxxRootDirectory": "F:/Tmp/Phares/2022-11-03-DCIM/DCIM/100D3400 2022",
"RootDirectory": "D:/1) Images A/Images-1e85c0ba/zzz Mackenzie Laptop !9/_" "RootDirectory": "D:/1) Images A/Images-1e85c0ba/_"
} }
} }
} }

View File

@ -652,7 +652,7 @@ public partial class DlibDotNet
sourceDirectoryChanges.Clear(); sourceDirectoryChanges.Clear();
anyNullOrNoIsUniqueFileName = filteredItems.Any(l => !l.IsUniqueFileName); anyNullOrNoIsUniqueFileName = filteredItems.Any(l => !l.IsUniqueFileName);
totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds); totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
message = $"{i + 1:000} [{filteredItems.Length:000} collectionB] / {containersLength:000} - {total} / {t} total collectionB - {totalSeconds} total second(s) - {outputResolution} - {container.SourceDirectory}"; message = $"{i + 1:000} [{filteredItems.Length:000}] / {containersLength:000} - {total} / {t} total - {totalSeconds} total second(s) - {outputResolution} - {container.SourceDirectory}";
if (_Configuration.LoadOrCreateThenSaveImageFacesResultsForOutputResolutions.Contains(outputResolution)) if (_Configuration.LoadOrCreateThenSaveImageFacesResultsForOutputResolutions.Contains(outputResolution))
_Faces.SetAngleBracketCollection(dResultsFullGroupDirectory, container.SourceDirectory); _Faces.SetAngleBracketCollection(dResultsFullGroupDirectory, container.SourceDirectory);
if (_Configuration.SaveFaceLandmarkForOutputResolutions.Contains(outputResolution)) if (_Configuration.SaveFaceLandmarkForOutputResolutions.Contains(outputResolution))

View File

@ -284,7 +284,7 @@ public class A_Property
fileInfo = new(Path.Combine(angleBracket.Replace("<>", "{}"), $"{item.ImageFileHolder.NameWithoutExtension}{item.ImageFileHolder.ExtensionLowered}.json")); fileInfo = new(Path.Combine(angleBracket.Replace("<>", "{}"), $"{item.ImageFileHolder.NameWithoutExtension}{item.ImageFileHolder.ExtensionLowered}.json"));
else else
fileInfo = new(Path.Combine(_JsonGroups["{}"][directoryIndex], $"{item.ImageFileHolder.NameWithoutExtension}{item.ImageFileHolder.ExtensionLowered}.json")); fileInfo = new(Path.Combine(_JsonGroups["{}"][directoryIndex], $"{item.ImageFileHolder.NameWithoutExtension}{item.ImageFileHolder.ExtensionLowered}.json"));
List<DateTime> dateTimes = (from l in sourceDirectoryFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList(); List<DateTime> dateTimes = (from l in sourceDirectoryFileTuples where l is not null && changesFrom.Contains(l.Item1) select l.Item2).ToList();
if (_Configuration.ForcePropertyLastWriteTimeToCreationTime && !fileInfo.Exists && File.Exists(Path.ChangeExtension(fileInfo.FullName, ".delete"))) if (_Configuration.ForcePropertyLastWriteTimeToCreationTime && !fileInfo.Exists && File.Exists(Path.ChangeExtension(fileInfo.FullName, ".delete")))
{ {
File.Move(Path.ChangeExtension(fileInfo.FullName, ".delete"), fileInfo.FullName); File.Move(Path.ChangeExtension(fileInfo.FullName, ".delete"), fileInfo.FullName);
@ -463,16 +463,18 @@ public class A_Property
SetAngleBracketCollection(aResultsFullGroupDirectory, sourceDirectory, anyNullOrNoIsUniqueFileName); SetAngleBracketCollection(aResultsFullGroupDirectory, sourceDirectory, anyNullOrNoIsUniqueFileName);
} }
public void SavePropertyParallelWork(long ticks, Container[] containers) public void SavePropertyParallelWork(long ticks, int t, Container[] containers)
{ {
if (_Log is null) if (_Log is null)
throw new NullReferenceException(nameof(_Log)); throw new NullReferenceException(nameof(_Log));
int total = 0;
string message; string message;
int totalSeconds; int totalSeconds;
Container container; Container container;
bool anyNullOrNoIsUniqueFileName; bool anyNullOrNoIsUniqueFileName;
List<Exception> exceptions = new(); List<Exception> exceptions = new();
int containersCount = containers.Length; int containersLength = containers.Length;
const string outputResolution = "Original";
List<Tuple<string, DateTime>> sourceDirectoryChanges = new(); List<Tuple<string, DateTime>> sourceDirectoryChanges = new();
string propertyRoot = IResult.GetResultsGroupDirectory(_Configuration, nameof(A_Property)); string propertyRoot = IResult.GetResultsGroupDirectory(_Configuration, nameof(A_Property));
for (int i = 0; i < containers.Length; i++) for (int i = 0; i < containers.Length; i++)
@ -486,7 +488,7 @@ public class A_Property
anyNullOrNoIsUniqueFileName = container.Items.Any(l => !l.IsUniqueFileName); anyNullOrNoIsUniqueFileName = container.Items.Any(l => !l.IsUniqueFileName);
SetAngleBracketCollection(container.SourceDirectory, anyNullOrNoIsUniqueFileName); SetAngleBracketCollection(container.SourceDirectory, anyNullOrNoIsUniqueFileName);
totalSeconds = (int)Math.Truncate(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds); totalSeconds = (int)Math.Truncate(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
message = $"{i + 1:000} / {containersCount:000}) {container.Items.Count:000} file(s) - {totalSeconds} total second(s) - {container.SourceDirectory}"; message = $"{i + 1:000} [{container.Items.Count:000}] / {containersLength:000} - {total} / {t} total - {totalSeconds} total second(s) - {outputResolution} - {container.SourceDirectory}";
SavePropertyParallelWork(exceptions, sourceDirectoryChanges, container, container.Items, message); SavePropertyParallelWork(exceptions, sourceDirectoryChanges, container, container.Items, message);
foreach (Exception exception in exceptions) foreach (Exception exception in exceptions)
_Log.Error(string.Concat(container.SourceDirectory, Environment.NewLine, exception.Message, Environment.NewLine, exception.StackTrace), exception); _Log.Error(string.Concat(container.SourceDirectory, Environment.NewLine, exception.Message, Environment.NewLine, exception.StackTrace), exception);
@ -504,6 +506,7 @@ public class A_Property
} }
_Log.Information(". . ."); _Log.Information(". . .");
} }
total += container.Items.Count;
} }
} }

View File

@ -25,6 +25,7 @@ public class Rename
{ } { }
if (console is null) if (console is null)
{ } { }
bool any = false;
_AppSettings = appSettings; _AppSettings = appSettings;
_IsEnvironment = isEnvironment; _IsEnvironment = isEnvironment;
long ticks = DateTime.Now.Ticks; long ticks = DateTime.Now.Ticks;
@ -46,10 +47,22 @@ public class Rename
MatchNginx[]? matchNginxCollection = JsonSerializer.Deserialize<MatchNginx[]>(json); MatchNginx[]? matchNginxCollection = JsonSerializer.Deserialize<MatchNginx[]>(json);
if (matchNginxCollection is null) if (matchNginxCollection is null)
throw new NullReferenceException(nameof(matchNginxCollection)); throw new NullReferenceException(nameof(matchNginxCollection));
if (matchNginxCollection.Any())
{
bool deleted;
for (int i = 1; i < 5; i++)
{
deleted = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(matchNginxCollection.First().ConvertedPath);
if (deleted && !any)
any = true;
}
}
if (!any)
{
if (matchNginxCollection.Length == 0 && matchNginxCollection[0].ConvertedPath.Contains("~~~")) if (matchNginxCollection.Length == 0 && matchNginxCollection[0].ConvertedPath.Contains("~~~"))
MoveMatches(matchNginxCollection[0]); MoveMatches(matchNginxCollection[0]);
else if (matchNginxCollection.All(l => l.Name.StartsWith("#")) || matchNginxCollection.All(l => l.Name.StartsWith(" #")) || matchNginxCollection.All(l => l.Name.StartsWith("=20")) || matchNginxCollection.All(l => l.Name.StartsWith("#20"))) else if (matchNginxCollection.All(l => l.Name.StartsWith("#")) || matchNginxCollection.All(l => l.Name.StartsWith(" #")) || matchNginxCollection.All(l => l.Name.StartsWith("=20")) || matchNginxCollection.All(l => l.Name.StartsWith("#20")))
Rename2000(matchNginxCollection); Rename2000(log, matchNginxCollection);
else if (matchNginxCollection.Any()) else if (matchNginxCollection.Any())
{ {
List<string> lines = RenameFilesInDirectories(log, matchNginxCollection); List<string> lines = RenameFilesInDirectories(log, matchNginxCollection);
@ -58,6 +71,7 @@ public class Rename
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(comparePathRoot); _ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(comparePathRoot);
} }
} }
}
private void Verify() private void Verify()
{ {
@ -262,11 +276,13 @@ public class Rename
return results; return results;
} }
private static void Rename2000(MatchNginx[] matchNginxCollection) private static void Rename2000(ILogger log, MatchNginx[] matchNginxCollection)
{ {
string name; string name;
string check; string check;
string? directoryName; string? directoryName;
log.Information("Enter a suffix if any");
string? suffix = System.Console.ReadLine();
foreach (MatchNginx matchNginx in matchNginxCollection) foreach (MatchNginx matchNginx in matchNginxCollection)
{ {
name = matchNginx.Name.Trim(); name = matchNginx.Name.Trim();
@ -276,7 +292,7 @@ public class Rename
if (directoryName is null) if (directoryName is null)
continue; continue;
if (name.StartsWith("=20") || name.StartsWith("#20")) if (name.StartsWith("=20") || name.StartsWith("#20"))
check = Path.Combine(directoryName, name[1..]); check = Path.Combine(directoryName, $"{name[1..]}{suffix}");
else else
check = Path.Combine(directoryName, $"zzz {name[5..]}"); check = Path.Combine(directoryName, $"zzz {name[5..]}");
if (Directory.Exists(check) || File.Exists(check)) if (Directory.Exists(check) || File.Exists(check))

View File

@ -106,7 +106,7 @@ internal abstract class Property
if (result is not null) if (result is not null)
break; break;
} }
if (result is not null && result.Value) if (result is not null && !result.Value)
break; break;
} }
return new(result, results); return new(result, results);