diff --git a/src/AudioTagger.Console/OperationLibrary.cs b/src/AudioTagger.Console/OperationLibrary.cs index 7e21d68..54e28c3 100644 --- a/src/AudioTagger.Console/OperationLibrary.cs +++ b/src/AudioTagger.Console/OperationLibrary.cs @@ -86,15 +86,14 @@ internal static class OperationLibrary ["-p", "--parse"], "Get a single tag value by parsing the data of another (generally Comments).", new TagParser()), + new( + ["--cache-tags"], + "Cache files' tag data to a local JSON file whose path is specified in the settings.", + new TagCacher()), new( ["--scan"], "Ad-hoc maintenance scanning work. (Not intended for normal use.)", new TagScanner(), - isHidden: true), - new( - ["--cache-tags"], - "Cache files' tag data locally to a JSON file whose path is specified in the settings. (Eventually, this will be helpful in speeding up certain operations.)", - new TagCacher(), isHidden: true) ]; diff --git a/src/AudioTagger.Console/Operations/TagCacher.cs b/src/AudioTagger.Console/Operations/TagCacher.cs index d68d52a..5fbdbdf 100644 --- a/src/AudioTagger.Console/Operations/TagCacher.cs +++ b/src/AudioTagger.Console/Operations/TagCacher.cs @@ -7,16 +7,6 @@ namespace AudioTagger.Console.Operations; public sealed class TagCacher : IPathOperation { - private record TagSummary( - string[] Artists, - string Album, - uint TrackNo, - string Title, - uint Year, - string[] Genres, - TimeSpan Duration - ); - public void Start( IReadOnlyCollection mediaFiles, DirectoryInfo workingDirectory, @@ -25,35 +15,38 @@ public void Start( { if (settings.TagCacheFilePath is null) { - printer.Error("You must specify the save file path in the settings file."); + printer.Error("You must specify the save file path in the settings."); return; } Watch watch = new(); - var summaries = mediaFiles.Select(m => { - return new TagSummary( - m.Artists, - m.Album, - m.TrackNo, - m.Title, - m.Year, - m.Genres, - m.Duration - ); + var summaries = + mediaFiles.Select(m => new + { + m.FileNameOnly, + m.FileInfo.DirectoryName, + m.Artists, + m.AlbumArtists, + m.Album, + m.TrackNo, + m.Title, + m.Year, + m.Genres, + m.Duration, + m.FileInfo.LastWriteTime, }); - printer.Print("Serializing the tags to JSON..."); + printer.Print("Serializing tag data to JSON..."); JsonSerializerOptions options = new() { WriteIndented = true, Encoder = JavaScriptEncoder.Create(UnicodeRanges.All) }; var json = JsonSerializer.Serialize(summaries, options); - var unescapedJson = System.Text.RegularExpressions.Regex.Unescape(json); // Avoids `\0027`, etc. printer.Print($"Saving cached tag data to \"{settings.TagCacheFilePath}\"..."); - File.WriteAllText(settings.TagCacheFilePath, unescapedJson); + File.WriteAllText(settings.TagCacheFilePath, json); printer.Print($"Saved in {watch.ElapsedFriendly}."); } } diff --git a/src/AudioTagger.Library/UpdatableFields.cs b/src/AudioTagger.Library/UpdatableFields.cs index 96838fd..856aee0 100644 --- a/src/AudioTagger.Library/UpdatableFields.cs +++ b/src/AudioTagger.Library/UpdatableFields.cs @@ -131,6 +131,11 @@ public Dictionary GetUpdateKeyValuePairs(MediaFile fileData) { var updateOutput = new Dictionary(); + if (Title != null && Title != fileData.Title) + { + updateOutput.Add("Title", Title); + } + if (AlbumArtists?.All(a => fileData.AlbumArtists.Contains(a)) == false) { updateOutput.Add("Album Artists", string.Join("; ", AlbumArtists)); @@ -141,11 +146,6 @@ public Dictionary GetUpdateKeyValuePairs(MediaFile fileData) updateOutput.Add("Artists", string.Join("; ", Artists)); } - if (Title != null && Title != fileData.Title) - { - updateOutput.Add("Title", Title); - } - if (Album != null && Album != fileData.Album) { updateOutput.Add("Album", Album);