From 308f80669e95033de0d13c8ef7399467474bb8a4 Mon Sep 17 00:00:00 2001 From: Steven Hildreth Date: Sat, 15 Jun 2019 17:33:24 -0500 Subject: [PATCH] Fixed some Inspector related bugs. Fixed typo ('FileExtensionsToDelete') in configuration. --- Inspector/Program.cs | 25 ++++---- Inspector/appsettings.json | 2 +- Roadie.Api.Library.Tests/ImageHelperTests.cs | 5 +- .../appsettings.test.json | 2 +- Roadie.Api.Library/Data/CollectionPartial.cs | 16 ++--- .../Engines/ArtistLookupEngine.cs | 2 +- .../Engines/ReleaseLookupEngine.cs | 4 +- Roadie.Api.Library/Factories/ArtistFactory.cs | 5 ++ .../Factories/ReleaseFactory.cs | 5 ++ Roadie.Api.Library/FilePlugins/Audio.cs | 6 +- Roadie.Api.Library/Imaging/ImageHelper.cs | 4 +- Roadie.Api.Library/Inspect/Inspector.cs | 20 ++++++- .../Plugins/Directory/DeleteUnwantedFiles.cs | 58 +++++++++++++++++++ .../Directory/EnsureArtistConsistent.cs | 2 +- .../Plugins/Directory/FolderPluginBase.cs | 2 + .../Directory/IInspectorDirectoryPlugin.cs | 1 + .../Inspect/Plugins/File/CleanUpArtists.cs | 2 +- .../Inspect/Plugins/File/CleanUpComments.cs | 2 +- .../Plugins/File/CleanUpReleaseTitle.cs | 2 +- .../Inspect/Plugins/File/CleanUpTrackTitle.cs | 2 +- .../Plugins/File/EnsureFileWriteable.cs | 44 ++++++++++++++ .../Inspect/Plugins/File/Renumber.cs | 2 +- Roadie.Api.Services/AdminService.cs | 4 +- Roadie.Api.Services/ArtistService.cs | 8 +-- Roadie.Api/appsettings.Development.json | 2 +- Roadie.Api/appsettings.json | 2 +- 26 files changed, 180 insertions(+), 49 deletions(-) create mode 100644 Roadie.Api.Library/Inspect/Plugins/Directory/DeleteUnwantedFiles.cs create mode 100644 Roadie.Api.Library/Inspect/Plugins/File/EnsureFileWriteable.cs diff --git a/Inspector/Program.cs b/Inspector/Program.cs index 3ecb3b4..ab39b04 100644 --- a/Inspector/Program.cs +++ b/Inspector/Program.cs @@ -1,40 +1,35 @@ -using System; +using McMaster.Extensions.CommandLineUtils; using System.ComponentModel.DataAnnotations; -using System.IO; -using McMaster.Extensions.CommandLineUtils; namespace Inspector { public class Program { - public static int Main(string[] args) - => CommandLineApplication.Execute(args); - - [Option(ShortName = "f", Description = "Folder To Inspect")] - [Required] - public string Folder { get; } - [Option(ShortName = "d", Description = "Destination Folder")] public string Destination { get; } [Option("-c", "Copy Dont Move Originals", CommandOptionType.NoValue)] public bool DoCopy { get; } - [Option("-r", "Only show what would be done, don't modify any files", CommandOptionType.NoValue)] - public bool IsReadOnly { get; } - [Option("-s", "Don't append a subfolder to the Destination folder", CommandOptionType.NoValue)] public bool DontAppendSubFolder { get; } [Option("-x", "Don't delete empty folders after inspection, if moving", CommandOptionType.NoValue)] public bool DontDeleteEmptyFolders { get; } + [Option(ShortName = "f", Description = "Folder To Inspect")] + [Required] + public string Folder { get; } + + [Option("-r", "Only show what would be done, don't modify any files", CommandOptionType.NoValue)] + public bool IsReadOnly { get; } + + public static int Main(string[] args) => CommandLineApplication.Execute(args); private void OnExecute() { var inspector = new Roadie.Library.Inspect.Inspector(); inspector.Inspect(DoCopy, IsReadOnly, Folder, Destination ?? Folder, DontAppendSubFolder, IsReadOnly ? true : DontDeleteEmptyFolders); - } } -} +} \ No newline at end of file diff --git a/Inspector/appsettings.json b/Inspector/appsettings.json index fceed60..624cfd3 100644 --- a/Inspector/appsettings.json +++ b/Inspector/appsettings.json @@ -18,7 +18,7 @@ "Width": 320 }, "DontDoMetaDataProvidersSearchArtists": [ "Various Artists", "Sound Tracks" ], - "FileExtenionsToDelete": [ ".cue", ".db", ".gif", ".html", ".ini", ".jpg", ".jpeg", ".log", ".mpg", ".m3u", ".png", ".nfo", ".nzb", ".sfv", ".srr", ".txt", ".url" ], + "FileExtensionsToDelete": [ ".cue", ".db", ".gif", ".html", ".ini", ".jpg", ".jpeg", ".log", ".mpg", ".m3u", ".png", ".nfo", ".nzb", ".sfv", ".srr", ".txt", ".url" ], "RecordNoResultSearches": true, "ArtistNameReplace": { "AC/DC": [ "AC; DC", "AC;DC", "AC/ DC", "AC DC" ], diff --git a/Roadie.Api.Library.Tests/ImageHelperTests.cs b/Roadie.Api.Library.Tests/ImageHelperTests.cs index 4745cfa..1892f0e 100644 --- a/Roadie.Api.Library.Tests/ImageHelperTests.cs +++ b/Roadie.Api.Library.Tests/ImageHelperTests.cs @@ -47,7 +47,7 @@ namespace Roadie.Library.Tests [InlineData("cover.png")] [InlineData("Cover.Jpg")] [InlineData("Cover.JPG")] - [InlineData("Cover.PNG")] + [InlineData("Cover.PNG")] [InlineData("CvR.Jpg")] [InlineData("Release.JPG")] [InlineData("folder.JPG")] @@ -71,6 +71,8 @@ namespace Roadie.Library.Tests [Theory] [InlineData("cover.png")] + [InlineData("cover1.jpg")] + [InlineData("cover 1.jpg")] [InlineData("Cover.jpg")] [InlineData("batman.txt")] [InlineData("Song.mp3")] @@ -185,6 +187,7 @@ namespace Roadie.Library.Tests [InlineData("cover_01.jpg")] [InlineData("cover 03.jpg")] [InlineData("cover 1.jpg")] + [InlineData("cover1.jpg")] [InlineData("Encartes (11).jpg")] [InlineData("Encartes (1).png")] [InlineData("Encartes.jpg")] diff --git a/Roadie.Api.Library.Tests/appsettings.test.json b/Roadie.Api.Library.Tests/appsettings.test.json index 1ac44d4..9c4aa2b 100644 --- a/Roadie.Api.Library.Tests/appsettings.test.json +++ b/Roadie.Api.Library.Tests/appsettings.test.json @@ -18,7 +18,7 @@ "Width": 320 }, "DontDoMetaDataProvidersSearchArtists": [ "Various Artists", "Sound Tracks" ], - "FileExtenionsToDelete": [ ".cue", ".db", ".gif", ".html", ".ini", ".jpg", ".jpeg", ".log", ".mpg", ".m3u", ".png", ".nfo", ".nzb", ".sfv", ".srr", ".txt", ".url" ], + "FileExtensionsToDelete": [ ".cue", ".db", ".gif", ".html", ".ini", ".jpg", ".jpeg", ".log", ".mpg", ".m3u", ".png", ".nfo", ".nzb", ".sfv", ".srr", ".txt", ".url" ], "RecordNoResultSearches": true, "ArtistNameReplace": { "AC/DC": [ "AC; DC", "AC;DC", "AC/ DC", "AC DC" ], diff --git a/Roadie.Api.Library/Data/CollectionPartial.cs b/Roadie.Api.Library/Data/CollectionPartial.cs index 98a775e..06ca5ba 100644 --- a/Roadie.Api.Library/Data/CollectionPartial.cs +++ b/Roadie.Api.Library/Data/CollectionPartial.cs @@ -102,13 +102,13 @@ namespace Roadie.Library.Data } - private IEnumerable _positionAristReleases = null; + private IEnumerable _positionArtistReleases = null; - public IEnumerable PositionArtistReleases() + public IEnumerable PositionArtistReleases() { - if (this._positionAristReleases == null) + if (this._positionArtistReleases == null) { - var rows = new List(); + var rows = new List(); using (var sr = new StringReader(this.ListInCSV)) { var index = 0; @@ -125,7 +125,7 @@ namespace Roadie.Library.Data while (csv.Read()) { index++; - rows.Add(new PositionAristRelease + rows.Add(new PositionArtistRelease { Index = index, Position = csv.GetField(this.PositionColumn), @@ -134,9 +134,9 @@ namespace Roadie.Library.Data }); } } - this._positionAristReleases = rows; + this._positionArtistReleases = rows; } - return this._positionAristReleases; + return this._positionArtistReleases; } public Collection() @@ -152,7 +152,7 @@ namespace Roadie.Library.Data } [Serializable] - public class PositionAristRelease + public class PositionArtistRelease { [JsonIgnore] public Statuses Status { get; set; } diff --git a/Roadie.Api.Library/Engines/ArtistLookupEngine.cs b/Roadie.Api.Library/Engines/ArtistLookupEngine.cs index a545df9..7ac5818 100644 --- a/Roadie.Api.Library/Engines/ArtistLookupEngine.cs +++ b/Roadie.Api.Library/Engines/ArtistLookupEngine.cs @@ -80,7 +80,7 @@ namespace Roadie.Library.Engines { artist.Thumbnail = ImageHelper.ResizeImage(artist.Thumbnail, this.Configuration.ThumbnailImageSize.Width, this.Configuration.ThumbnailImageSize.Height); artist.Thumbnail = ImageHelper.ConvertToJpegFormat(artist.Thumbnail); - if (artist.Thumbnail.Length >= 65535) + if (artist.Thumbnail.Length >= ImageHelper.MaximumThumbnailByteSize) { Logger.LogWarning($"Artist Thumbnail larger than maximum size after resizing to [{ this.Configuration.ThumbnailImageSize.Width }x{ this.Configuration.ThumbnailImageSize.Height}] Thumbnail Size [{ artist.Thumbnail.Length }]"); artist.Thumbnail = null; diff --git a/Roadie.Api.Library/Engines/ReleaseLookupEngine.cs b/Roadie.Api.Library/Engines/ReleaseLookupEngine.cs index daf1fa9..2600b82 100644 --- a/Roadie.Api.Library/Engines/ReleaseLookupEngine.cs +++ b/Roadie.Api.Library/Engines/ReleaseLookupEngine.cs @@ -62,7 +62,7 @@ namespace Roadie.Library.Engines public IReleaseSearchEngine WikipediaReleaseSearchEngine { get; } public ReleaseLookupEngine(IRoadieSettings configuration, IHttpEncoder httpEncoder, IRoadieDbContext context, - ICacheManager cacheManager, ILogger logger, IArtistLookupEngine aristLookupEngine, + ICacheManager cacheManager, ILogger logger, IArtistLookupEngine artistLookupEngine, ILabelLookupEngine labelLookupEngine) : base(configuration, httpEncoder, context, cacheManager, logger) { @@ -916,7 +916,7 @@ namespace Roadie.Library.Engines { result.Thumbnail = ImageHelper.ResizeImage(result.Thumbnail, this.Configuration.ThumbnailImageSize.Width, this.Configuration.ThumbnailImageSize.Height); result.Thumbnail = ImageHelper.ConvertToJpegFormat(result.Thumbnail); - if(result.Thumbnail.Length >= 65535) + if(result.Thumbnail.Length >= ImageHelper.MaximumThumbnailByteSize) { Logger.LogWarning($"Release Thumbnail larger than maximum size after resizing to [{ this.Configuration.ThumbnailImageSize.Width }x{ this.Configuration.ThumbnailImageSize.Height}] Thumbnail Size [{ result.Thumbnail.Length }]"); result.Thumbnail = null; diff --git a/Roadie.Api.Library/Factories/ArtistFactory.cs b/Roadie.Api.Library/Factories/ArtistFactory.cs index 4239ef6..fe31dad 100644 --- a/Roadie.Api.Library/Factories/ArtistFactory.cs +++ b/Roadie.Api.Library/Factories/ArtistFactory.cs @@ -335,6 +335,11 @@ namespace Roadie.Library.Factories artist.Thumbnail = File.ReadAllBytes(i.FullName); artist.Thumbnail = ImageHelper.ResizeImage(artist.Thumbnail, this.Configuration.MediumImageSize.Width, this.Configuration.MediumImageSize.Height); artist.Thumbnail = ImageHelper.ConvertToJpegFormat(artist.Thumbnail); + if (artist.Thumbnail.Length >= ImageHelper.MaximumThumbnailByteSize) + { + Logger.LogWarning($"Artist Thumbnail larger than maximum size after resizing to [{ this.Configuration.ThumbnailImageSize.Width }x{ this.Configuration.ThumbnailImageSize.Height}] Thumbnail Size [{ artist.Thumbnail.Length }]"); + artist.Thumbnail = null; + } artist.LastUpdated = DateTime.UtcNow; await this.DbContext.SaveChangesAsync(); this.CacheManager.ClearRegion(artist.CacheRegion); diff --git a/Roadie.Api.Library/Factories/ReleaseFactory.cs b/Roadie.Api.Library/Factories/ReleaseFactory.cs index a3b1de3..35ea3cc 100644 --- a/Roadie.Api.Library/Factories/ReleaseFactory.cs +++ b/Roadie.Api.Library/Factories/ReleaseFactory.cs @@ -798,6 +798,11 @@ namespace Roadie.Library.Factories release.Thumbnail = File.ReadAllBytes(i.FullName); release.Thumbnail = ImageHelper.ResizeImage(release.Thumbnail, this.Configuration.MediumImageSize.Width, this.Configuration.MediumImageSize.Height); release.Thumbnail = ImageHelper.ConvertToJpegFormat(release.Thumbnail); + if (release.Thumbnail.Length >= ImageHelper.MaximumThumbnailByteSize) + { + Logger.LogWarning($"Release Thumbnail larger than maximum size after resizing to [{ this.Configuration.ThumbnailImageSize.Width }x{ this.Configuration.ThumbnailImageSize.Height}] Thumbnail Size [{ release.Thumbnail.Length }]"); + release.Thumbnail = null; + } release.LastUpdated = now; await this.DbContext.SaveChangesAsync(); this.CacheManager.ClearRegion(release.Artist.CacheRegion); diff --git a/Roadie.Api.Library/FilePlugins/Audio.cs b/Roadie.Api.Library/FilePlugins/Audio.cs index c9f7ccf..ea9ec04 100644 --- a/Roadie.Api.Library/FilePlugins/Audio.cs +++ b/Roadie.Api.Library/FilePlugins/Audio.cs @@ -122,8 +122,8 @@ namespace Roadie.Library.FilePlugins if (artistImages.Any()) { var artistImage = artistImages.First(); - var aristImageFilename = Path.Combine(artistFolder, ImageHelper.ArtistImageFilename); - if (aristImageFilename != artistImage.FullName) + var artistImageFilename = Path.Combine(artistFolder, ImageHelper.ArtistImageFilename); + if (artistImageFilename != artistImage.FullName) { // Read image and convert to jpeg var imageBytes = File.ReadAllBytes(artistImage.FullName); @@ -132,7 +132,7 @@ namespace Roadie.Library.FilePlugins // Move artist image to artist folder if (!doJustInfo) { - File.WriteAllBytes(aristImageFilename, imageBytes); + File.WriteAllBytes(artistImageFilename, imageBytes); artistImage.Delete(); } this.Logger.LogDebug("Found Artist Image File [{0}], Moved to artist folder.", artistImage.Name); diff --git a/Roadie.Api.Library/Imaging/ImageHelper.cs b/Roadie.Api.Library/Imaging/ImageHelper.cs index a22c510..4ae2140 100644 --- a/Roadie.Api.Library/Imaging/ImageHelper.cs +++ b/Roadie.Api.Library/Imaging/ImageHelper.cs @@ -16,6 +16,8 @@ namespace Roadie.Library.Imaging { public static class ImageHelper { + public static int MaximumThumbnailByteSize = 65535; + public static string ArtistImageFilename = "artist.jpg"; public static string ArtistSecondaryImageFilename = "artist {0}.jpg"; // Replace with counter of image public static string ReleaseCoverFilename = "cover.jpg"; @@ -163,7 +165,7 @@ namespace Roadie.Library.Imaging { return false; } - return Regex.IsMatch(fileinfo.Name, @"((book[let]*[#-_\s(]*[0-9]*-*[0-9]*(\))*)|(encartes[-_\s]*[(]*[0-9]*[)]*)|scan(.)?[0-9]*|matrix(.)?[0-9]*|(cover[\s_-]+[0-9]+)|back|traycard|jewel case|disc|(.*)[in]*side(.*)|in([side|lay|let|site])*[0-9]*|cd(.)?[0-9]*|(release[\s_-]+[0-9]+))\.(jpg|jpeg|png|bmp|gif)", RegexOptions.IgnoreCase); + return Regex.IsMatch(fileinfo.Name, @"((book[let]*[#-_\s(]*[0-9]*-*[0-9]*(\))*)|(encartes[-_\s]*[(]*[0-9]*[)]*)|scan(.)?[0-9]*|matrix(.)?[0-9]*|(cover[\s_-]*[0-9]+)|back|traycard|jewel case|disc|(.*)[in]*side(.*)|in([side|lay|let|site])*[0-9]*|cd(.)?[0-9]*|(release[\s_-]+[0-9]+))\.(jpg|jpeg|png|bmp|gif)", RegexOptions.IgnoreCase); } public static bool IsLabelImage(FileInfo fileinfo) diff --git a/Roadie.Api.Library/Inspect/Inspector.cs b/Roadie.Api.Library/Inspect/Inspector.cs index 8f9e99c..2f5caf2 100644 --- a/Roadie.Api.Library/Inspect/Inspector.cs +++ b/Roadie.Api.Library/Inspect/Inspector.cs @@ -131,7 +131,7 @@ namespace Roadie.Library.Inspect var settings = new RoadieSettings(); IConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); - configurationBuilder.AddJsonFile("appsettings.json"); + configurationBuilder.AddJsonFile("appsettings.json", false); IConfiguration configuration = configurationBuilder.Build(); configuration.GetSection("RoadieSettings").Bind(settings); settings.ConnectionString = configuration.GetConnectionString("RoadieDatabaseConnection"); @@ -208,7 +208,7 @@ namespace Roadie.Library.Inspect continue; } // Run directory plugins against current directory - foreach (var plugin in DirectoryPlugins.OrderBy(x => x.Order)) + foreach (var plugin in DirectoryPlugins.Where(x => !x.IsPostProcessingPlugin).OrderBy(x => x.Order)) { Console.WriteLine($"╠╬═ Running Directory Plugin { plugin.Description }"); var pluginResult = plugin.Process(directoryInfo); @@ -382,6 +382,22 @@ namespace Roadie.Library.Inspect Console.WriteLine("╠════════════════════════╣"); } } + // Run post-processing directory plugins against current directory + foreach (var plugin in DirectoryPlugins.Where(x => x.IsPostProcessingPlugin).OrderBy(x => x.Order)) + { + Console.WriteLine($"╠╬═ Running Post-Processing Directory Plugin { plugin.Description }"); + var pluginResult = plugin.Process(directoryInfo); + if (!pluginResult.IsSuccess) + { + Console.WriteLine($"Plugin Failed: Error [{ JsonConvert.SerializeObject(pluginResult)}]"); + return; + } + else if (!string.IsNullOrEmpty(pluginResult.Data)) + { + Console.WriteLine($"╠╣ Directory Plugin Message: { pluginResult.Data }"); + } + } + Console.WriteLine($"╠╝"); sw.Stop(); Console.WriteLine($"╚═ Elapsed Time { sw.ElapsedMilliseconds.ToString("0000000") }, Artists { artistsFound.Count() }, Releases { releasesFound.Count() }, MP3s { mp3FilesFoundCount } ═╝"); } diff --git a/Roadie.Api.Library/Inspect/Plugins/Directory/DeleteUnwantedFiles.cs b/Roadie.Api.Library/Inspect/Plugins/Directory/DeleteUnwantedFiles.cs new file mode 100644 index 0000000..2c4e94e --- /dev/null +++ b/Roadie.Api.Library/Inspect/Plugins/Directory/DeleteUnwantedFiles.cs @@ -0,0 +1,58 @@ +using Microsoft.Extensions.Logging; +using Roadie.Library.Caching; +using Roadie.Library.Configuration; +using Roadie.Library.MetaData.ID3Tags; +using Roadie.Library.Utility; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace Roadie.Library.Inspect.Plugins.Directory +{ + public class DeleteUnwantedFiles : FolderPluginBase + { + public override bool IsEnabled => true; + + public override bool IsPostProcessingPlugin => true; + + public override string Description + { + get + { + return "Cleanup: Delete unwanted files"; + } + } + + public override int Order { get; } = 99; + + public DeleteUnwantedFiles(IRoadieSettings configuration, ICacheManager cacheManager, ILogger logger, IID3TagsHelper tagsHelper) + : base(configuration, cacheManager, logger, tagsHelper) + { + } + + public override OperationResult Process(DirectoryInfo directory) + { + var result = new OperationResult(); + var data = string.Empty; + + var deletedFiles = new List(); + var fileExtensionsToDelete = this.Configuration.FileExtensionsToDelete ?? new string[0]; + foreach (var file in directory.GetFiles("*.*", SearchOption.AllDirectories)) + { + if (fileExtensionsToDelete.Any(x => x.Equals(file.Extension, StringComparison.OrdinalIgnoreCase))) + { + if (!Configuration.Inspector.IsInReadOnlyMode) + { + file.Delete(); + } + deletedFiles.Add(file.Name); + Console.WriteLine($" X Deleted File [{file}], Was foud in in FileExtensionsToDelete"); + } + } + result.Data = $"Deleted [{ deletedFiles.Count() }] unwanted files"; ; + result.IsSuccess = true; + return result; + } + } +} diff --git a/Roadie.Api.Library/Inspect/Plugins/Directory/EnsureArtistConsistent.cs b/Roadie.Api.Library/Inspect/Plugins/Directory/EnsureArtistConsistent.cs index 9fa6c23..e3220b8 100644 --- a/Roadie.Api.Library/Inspect/Plugins/Directory/EnsureArtistConsistent.cs +++ b/Roadie.Api.Library/Inspect/Plugins/Directory/EnsureArtistConsistent.cs @@ -50,7 +50,7 @@ namespace Roadie.Library.Inspect.Plugins.Directory foreach (var metaData in metaDatasForFilesInFolder.Where(x => x.Artist != artist)) { modified++; - Console.WriteLine($"╟ Setting Arist to [{ artist }], was [{ metaData.Artist }] on file [{ metaData.FileInfo.Name}"); + Console.WriteLine($"╟ Setting Artist to [{ artist }], was [{ metaData.Artist }] on file [{ metaData.FileInfo.Name}"); metaData.Artist = artist; if (!Configuration.Inspector.IsInReadOnlyMode) { diff --git a/Roadie.Api.Library/Inspect/Plugins/Directory/FolderPluginBase.cs b/Roadie.Api.Library/Inspect/Plugins/Directory/FolderPluginBase.cs index 690857b..a9af645 100644 --- a/Roadie.Api.Library/Inspect/Plugins/Directory/FolderPluginBase.cs +++ b/Roadie.Api.Library/Inspect/Plugins/Directory/FolderPluginBase.cs @@ -10,6 +10,8 @@ namespace Roadie.Library.Inspect.Plugins.Directory { public virtual bool IsEnabled => true; + public virtual bool IsPostProcessingPlugin => false; + public FolderPluginBase(IRoadieSettings configuration, ICacheManager cacheManager, ILogger logger, IID3TagsHelper tagsHelper) : base(configuration, cacheManager, logger, tagsHelper) { diff --git a/Roadie.Api.Library/Inspect/Plugins/Directory/IInspectorDirectoryPlugin.cs b/Roadie.Api.Library/Inspect/Plugins/Directory/IInspectorDirectoryPlugin.cs index 9047e47..0a029c9 100644 --- a/Roadie.Api.Library/Inspect/Plugins/Directory/IInspectorDirectoryPlugin.cs +++ b/Roadie.Api.Library/Inspect/Plugins/Directory/IInspectorDirectoryPlugin.cs @@ -5,6 +5,7 @@ namespace Roadie.Library.Inspect.Plugins.Directory public interface IInspectorDirectoryPlugin { bool IsEnabled { get; } + bool IsPostProcessingPlugin { get; } string Description { get; } int Order { get; } diff --git a/Roadie.Api.Library/Inspect/Plugins/File/CleanUpArtists.cs b/Roadie.Api.Library/Inspect/Plugins/File/CleanUpArtists.cs index 515eb3a..ec52b72 100644 --- a/Roadie.Api.Library/Inspect/Plugins/File/CleanUpArtists.cs +++ b/Roadie.Api.Library/Inspect/Plugins/File/CleanUpArtists.cs @@ -11,7 +11,7 @@ namespace Roadie.Library.Inspect.Plugins.File public class CleanUpArtists : FilePluginBase { public override string Description => "Clean: Artist (TPE1) and TrackArtist (TOPE)"; - public override int Order => 2; + public override int Order => 5; public CleanUpArtists(IRoadieSettings configuration, ICacheManager cacheManager, ILogger logger, IID3TagsHelper tagsHelper) : base(configuration, cacheManager, logger, tagsHelper) diff --git a/Roadie.Api.Library/Inspect/Plugins/File/CleanUpComments.cs b/Roadie.Api.Library/Inspect/Plugins/File/CleanUpComments.cs index 68c38b6..f9c9e81 100644 --- a/Roadie.Api.Library/Inspect/Plugins/File/CleanUpComments.cs +++ b/Roadie.Api.Library/Inspect/Plugins/File/CleanUpComments.cs @@ -9,7 +9,7 @@ namespace Roadie.Library.Inspect.Plugins.File public class CleanUpComments : FilePluginBase { public override string Description => "Clean: Clear Comments (COMM)"; - public override int Order => 2; + public override int Order => 5; public CleanUpComments(IRoadieSettings configuration, ICacheManager cacheManager, ILogger logger, IID3TagsHelper tagsHelper) : base(configuration, cacheManager, logger, tagsHelper) diff --git a/Roadie.Api.Library/Inspect/Plugins/File/CleanUpReleaseTitle.cs b/Roadie.Api.Library/Inspect/Plugins/File/CleanUpReleaseTitle.cs index 565d8cd..7c99f55 100644 --- a/Roadie.Api.Library/Inspect/Plugins/File/CleanUpReleaseTitle.cs +++ b/Roadie.Api.Library/Inspect/Plugins/File/CleanUpReleaseTitle.cs @@ -10,7 +10,7 @@ namespace Roadie.Library.Inspect.Plugins.File public class CleanUpReleaseTitle : FilePluginBase { public override string Description => "Clean: Release Title (TALB)"; - public override int Order => 2; + public override int Order => 5; public CleanUpReleaseTitle(IRoadieSettings configuration, ICacheManager cacheManager, ILogger logger, IID3TagsHelper tagsHelper) : base(configuration, cacheManager, logger, tagsHelper) diff --git a/Roadie.Api.Library/Inspect/Plugins/File/CleanUpTrackTitle.cs b/Roadie.Api.Library/Inspect/Plugins/File/CleanUpTrackTitle.cs index 032bc00..ce465cb 100644 --- a/Roadie.Api.Library/Inspect/Plugins/File/CleanUpTrackTitle.cs +++ b/Roadie.Api.Library/Inspect/Plugins/File/CleanUpTrackTitle.cs @@ -10,7 +10,7 @@ namespace Roadie.Library.Inspect.Plugins.File public class CleanUpTrackTitle : FilePluginBase { public override string Description => "Clean: Clean Track Title (TIT2) "; - public override int Order => 2; + public override int Order => 5; public CleanUpTrackTitle(IRoadieSettings configuration, ICacheManager cacheManager, ILogger logger, IID3TagsHelper tagsHelper) : base(configuration, cacheManager, logger, tagsHelper) diff --git a/Roadie.Api.Library/Inspect/Plugins/File/EnsureFileWriteable.cs b/Roadie.Api.Library/Inspect/Plugins/File/EnsureFileWriteable.cs new file mode 100644 index 0000000..545b2ce --- /dev/null +++ b/Roadie.Api.Library/Inspect/Plugins/File/EnsureFileWriteable.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Microsoft.Extensions.Logging; +using Roadie.Library.Caching; +using Roadie.Library.Configuration; +using Roadie.Library.Extensions; +using Roadie.Library.MetaData.Audio; +using Roadie.Library.MetaData.ID3Tags; + +namespace Roadie.Library.Inspect.Plugins.File +{ + public class EnsureFileWriteable : FilePluginBase + { + public override string Description => "Ensure: Ensure file is writable "; + public override int Order => 1; + + public EnsureFileWriteable(IRoadieSettings configuration, ICacheManager cacheManager, ILogger logger, IID3TagsHelper tagsHelper) + : base(configuration, cacheManager, logger, tagsHelper) + { + } + + public override OperationResult Process(AudioMetaData metaData) + { + var result = new OperationResult(); + if (this.Configuration.Processing.DoAudioCleanup) + { + if (metaData.FileInfo.IsReadOnly) + { + metaData.FileInfo.Attributes = RemoveAttribute(metaData.FileInfo.Attributes, FileAttributes.ReadOnly); + Console.WriteLine($"╟ Removed read only attribute on file file [{ metaData.FileInfo.Name}"); + } + } + result.Data = metaData; + result.IsSuccess = true; + return result; + } + + private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove) + { + return attributes & ~attributesToRemove; + } + } +} diff --git a/Roadie.Api.Library/Inspect/Plugins/File/Renumber.cs b/Roadie.Api.Library/Inspect/Plugins/File/Renumber.cs index 64ec4cd..6f62a0c 100644 --- a/Roadie.Api.Library/Inspect/Plugins/File/Renumber.cs +++ b/Roadie.Api.Library/Inspect/Plugins/File/Renumber.cs @@ -17,7 +17,7 @@ namespace Roadie.Library.Inspect.Plugins.File } } - public override int Order { get; } = 1; + public override int Order { get; } = 2; public Renumber(IRoadieSettings configuration, ICacheManager cacheManager, ILogger logger, IID3TagsHelper tagsHelper) : base(configuration, cacheManager, logger, tagsHelper) diff --git a/Roadie.Api.Services/AdminService.cs b/Roadie.Api.Services/AdminService.cs index 4becc92..961f1f4 100644 --- a/Roadie.Api.Services/AdminService.cs +++ b/Roadie.Api.Services/AdminService.cs @@ -449,7 +449,7 @@ namespace Roadie.Api.Services var collectionReleases = (from cr in this.DbContext.CollectionReleases where cr.CollectionId == collection.Id select cr); - PositionAristRelease[] pars = null; + PositionArtistRelease[] pars = null; try { @@ -567,7 +567,7 @@ namespace Roadie.Api.Services sw.Start(); CollectionRelease[] crs = new CollectionRelease[0]; - var result = new List(); + var result = new List(); var errors = new List(); var collection = this.DbContext.Collections.FirstOrDefault(x => x.RoadieId == collectionId); if (collection == null) diff --git a/Roadie.Api.Services/ArtistService.cs b/Roadie.Api.Services/ArtistService.cs index a256134..8ec71d9 100644 --- a/Roadie.Api.Services/ArtistService.cs +++ b/Roadie.Api.Services/ArtistService.cs @@ -523,13 +523,13 @@ namespace Roadie.Api.Services // Ensure is jpeg first artistSecondaryImage = ImageHelper.ConvertToJpegFormat(artistSecondaryImage); - var aristImageFilename = Path.Combine(newArtistFolder, string.Format(ImageHelper.ArtistSecondaryImageFilename, looper.ToString("00"))); - while (File.Exists(aristImageFilename)) + var artistImageFilename = Path.Combine(newArtistFolder, string.Format(ImageHelper.ArtistSecondaryImageFilename, looper.ToString("00"))); + while (File.Exists(artistImageFilename)) { looper++; - aristImageFilename = Path.Combine(newArtistFolder, string.Format(ImageHelper.ArtistSecondaryImageFilename, looper.ToString("00"))); + artistImageFilename = Path.Combine(newArtistFolder, string.Format(ImageHelper.ArtistSecondaryImageFilename, looper.ToString("00"))); } - File.WriteAllBytes(aristImageFilename, artistSecondaryImage); + File.WriteAllBytes(artistImageFilename, artistSecondaryImage); } looper++; } diff --git a/Roadie.Api/appsettings.Development.json b/Roadie.Api/appsettings.Development.json index ad87520..4766935 100644 --- a/Roadie.Api/appsettings.Development.json +++ b/Roadie.Api/appsettings.Development.json @@ -70,7 +70,7 @@ "Width": 320 }, "DontDoMetaDataProvidersSearchArtists": [ "Various Artists", "Sound Tracks" ], - "FileExtenionsToDelete": [ ".cue", ".db", ".gif", ".html", ".ini", ".jpg", ".jpeg", ".log", ".mpg", ".m3u", ".png", ".nfo", ".nzb", ".sfv", ".srr", ".txt", ".url" ], + "FileExtensionsToDelete": [ ".cue", ".db", ".gif", ".html", ".ini", ".jpg", ".jpeg", ".log", ".mpg", ".m3u", ".png", ".nfo", ".nzb", ".sfv", ".srr", ".txt", ".url" ], "RecordNoResultSearches": true, "ArtistNameReplace": { "AC/DC": [ "AC; DC", "AC;DC", "AC/ DC", "AC DC" ], diff --git a/Roadie.Api/appsettings.json b/Roadie.Api/appsettings.json index eefaa9c..b97079b 100644 --- a/Roadie.Api/appsettings.json +++ b/Roadie.Api/appsettings.json @@ -70,7 +70,7 @@ "Width": 320 }, "DontDoMetaDataProvidersSearchArtists": [ "Various Artists", "Sound Tracks" ], - "FileExtenionsToDelete": [ ".cue", ".db", ".gif", ".html", ".ini", ".jpg", ".jpeg", ".log", ".mpg", ".m3u", ".png", ".nfo", ".nzb", ".sfv", ".srr", ".txt", ".url" ], + "FileExtensionsToDelete": [ ".cue", ".db", ".gif", ".html", ".ini", ".jpg", ".jpeg", ".log", ".mpg", ".m3u", ".png", ".nfo", ".nzb", ".sfv", ".srr", ".txt", ".url" ], "RecordNoResultSearches": true, "ArtistNameReplace": { "AC/DC": [ "AC; DC", "AC;DC", "AC/ DC", "AC DC" ],