From 7ec50dd56e2e860c56af54c8062853feaa5dde89 Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Mon, 25 Dec 2023 20:41:10 -0700 Subject: [PATCH] RenameUrl --- Rename/Rename.cs | 23 +++++++++++++++++++++++ Shared/Models/Stateless/Methods/IId.cs | 18 ++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/Rename/Rename.cs b/Rename/Rename.cs index a095fd0..47a9224 100644 --- a/Rename/Rename.cs +++ b/Rename/Rename.cs @@ -108,6 +108,24 @@ public class Rename : IRename #pragma warning restore CA1416 + private static void RenameUrl(FilePath filePath) + { + string[] lines = File.ReadAllLines(filePath.FullName); + if (lines.Length == 1) + { + FileHolder fileHolder = new(lines[0]); + if (fileHolder.Exists) + { + string checkFile; + checkFile = IId.GetIgnoreFullPath(filePath, fileHolder); + if (lines[0] == checkFile || lines[0].Length != checkFile.Length) + throw new NotSupportedException(); + File.Move(lines[0], checkFile); + } + File.Delete(filePath.FullName); + } + } + private static void GetExifDirectoryCollection(IRename rename, RenameConfiguration renameConfiguration, List<(string, FileInfo, ExifDirectory)> exifDirectories, IEnumerable files, A_Metadata metadata) { int index = -1; @@ -124,6 +142,11 @@ public class Rename : IRename rename.Tick(); fileHolder = new(file); filePath = FilePath.Get(renameConfiguration.MetadataConfiguration, fileHolder, index); + if (filePath.ExtensionLowered == ".url" && filePath.Id is not null) + { + RenameUrl(filePath); + continue; + } if (renameConfiguration.SkipIdFiles && filePath.Id is not null && (filePath.IsIntelligentIdFormat || filePath.SortOrder is not null)) continue; (ffmpegFiles, ffmpegFilePath) = rename.ConvertAndGetFfmpegFiles(renameConfiguration, filePath); diff --git a/Shared/Models/Stateless/Methods/IId.cs b/Shared/Models/Stateless/Methods/IId.cs index f26d18c..6d1e506 100644 --- a/Shared/Models/Stateless/Methods/IId.cs +++ b/Shared/Models/Stateless/Methods/IId.cs @@ -18,6 +18,24 @@ public interface IId static string GetPaddedId(MetadataConfiguration metadataConfiguration, int index, int id) => Id.GetPaddedId(metadataConfiguration, index, id); + bool TestStatic_IsIgnore(FilePath filePath) => + IsIgnore(filePath); + static bool IsIgnore(FilePath filePath) => + filePath.FileNameFirstSegment[^1] is '2' or '8'; + + string TestStatic_GetIgnoreFullPath(FilePath filePath, FileHolder fileHolder) => + GetIgnoreFullPath(filePath, fileHolder); + static string GetIgnoreFullPath(FilePath filePath, FileHolder fileHolder) => + fileHolder.DirectoryName is null ? + throw new NotSupportedException() : + filePath.Id > -1 ? + fileHolder.NameWithoutExtension[^1] == '9' ? + Path.Combine(fileHolder.DirectoryName, $"{fileHolder.NameWithoutExtension[..^1]}8{fileHolder.ExtensionLowered}") : + throw new NotSupportedException("High") : + fileHolder.NameWithoutExtension[^1] == '1' ? + Path.Combine(fileHolder.DirectoryName, $"{fileHolder.NameWithoutExtension[..^1]}2{fileHolder.ExtensionLowered}") : + throw new NotSupportedException("Low"); + bool TestStatic_NameWithoutExtensionIsIntelligentIdFormat(MetadataConfiguration metadataConfiguration, string fileNameFirstSegment) => NameWithoutExtensionIsIntelligentIdFormat(metadataConfiguration, fileNameFirstSegment); static bool NameWithoutExtensionIsIntelligentIdFormat(MetadataConfiguration metadataConfiguration, string fileNameFirstSegment) =>