mirror of
https://github.com/sphildreth/roadie
synced 2024-11-10 06:44:12 +00:00
Inspector and file regex changes/additions.
This commit is contained in:
parent
c2035d8d21
commit
f8e97a5880
6 changed files with 95 additions and 52 deletions
|
@ -18,7 +18,7 @@
|
|||
"Width": 320
|
||||
},
|
||||
"DontDoMetaDataProvidersSearchArtists": [ "Various Artists", "Sound Tracks" ],
|
||||
"FileExtensionsToDelete": [ ".cue", ".db", ".gif", ".html", ".ini", ".jpg", ".jpeg", ".log", ".mpg", ".m3u", ".png", ".nfo", ".nzb", ".sfv", ".srr", ".txt", ".url" ],
|
||||
"FileExtensionsToDelete": [ ".accurip", ".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" ],
|
||||
|
|
|
@ -18,6 +18,7 @@ namespace Roadie.Library.Tests
|
|||
[InlineData("group.jpg")]
|
||||
[InlineData("ARTIST.JPG")]
|
||||
[InlineData("GrOup.jpg")]
|
||||
[InlineData("photo.jpg")]
|
||||
[InlineData("aRtist.jpg")]
|
||||
public void Test_Should_Be_Artist_Images(string input)
|
||||
{
|
||||
|
@ -29,12 +30,18 @@ namespace Roadie.Library.Tests
|
|||
[InlineData("logo.jpg")]
|
||||
[InlineData("logo.png")]
|
||||
[InlineData("Logo.Jpg")]
|
||||
[InlineData("logo.gif")]
|
||||
[InlineData("artist_logo.jpg")]
|
||||
[InlineData("Artist_logo.jpg")]
|
||||
[InlineData("ARTIST_LOGO.JPG")]
|
||||
[InlineData("artist 1.jpg")]
|
||||
[InlineData("artist_01.jpg")]
|
||||
[InlineData("artist 03.jpg")]
|
||||
[InlineData("band 01.jpg")]
|
||||
[InlineData("band_01.jpg")]
|
||||
[InlineData("band 1.jpg")]
|
||||
[InlineData("photo 1.jpg")]
|
||||
[InlineData("photo1.jpg")]
|
||||
public void Test_Should_Be_Artist_Secondary_Images(string input)
|
||||
{
|
||||
Assert.True(ImageHelper.IsArtistSecondaryImage(new FileInfo(input)));
|
||||
|
@ -215,6 +222,7 @@ namespace Roadie.Library.Tests
|
|||
[InlineData("Jewel Case.jpg")]
|
||||
[InlineData("Matrix-1.jpg")]
|
||||
[InlineData("Matrix 1.jpg")]
|
||||
[InlineData("IMG_20160921_0004.jpg")]
|
||||
public void Test_Should_Be_Release_Secondary_Images(string input)
|
||||
{
|
||||
Assert.True(ImageHelper.IsReleaseSecondaryImage(new FileInfo(input)));
|
||||
|
|
|
@ -138,7 +138,7 @@ namespace Roadie.Library.Imaging
|
|||
{
|
||||
return false;
|
||||
}
|
||||
return Regex.IsMatch(fileinfo.Name, @"(band|artist|group)\.(jpg|jpeg|png|bmp|gif)", RegexOptions.IgnoreCase);
|
||||
return Regex.IsMatch(fileinfo.Name, @"(band|artist|group|photo)\.(jpg|jpeg|png|bmp|gif)", RegexOptions.IgnoreCase);
|
||||
}
|
||||
|
||||
public static bool IsArtistSecondaryImage(FileInfo fileinfo)
|
||||
|
@ -147,7 +147,7 @@ namespace Roadie.Library.Imaging
|
|||
{
|
||||
return false;
|
||||
}
|
||||
return Regex.IsMatch(fileinfo.Name, @"(artist_logo|logo|(artist[\s_-]+[0-9]+))\.(jpg|jpeg|png|bmp|gif)", RegexOptions.IgnoreCase);
|
||||
return Regex.IsMatch(fileinfo.Name, @"(artist_logo|logo|photo[-_\s]*[0-9]+|(artist[\s_-]+[0-9]+)|(band[\s_-]+[0-9]+))\.(jpg|jpeg|png|bmp|gif)", RegexOptions.IgnoreCase);
|
||||
}
|
||||
|
||||
public static bool IsReleaseImage(FileInfo fileinfo, string releaseName = null)
|
||||
|
@ -165,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, @"((img[\s-_]*[0-9]*[\s-_]*[0-9]*)|(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)
|
||||
|
@ -177,6 +177,32 @@ namespace Roadie.Library.Imaging
|
|||
return Regex.IsMatch(fileinfo.Name, @"(label|recordlabel|record_label)\.(jpg|jpeg|png|bmp|gif)", RegexOptions.IgnoreCase);
|
||||
}
|
||||
|
||||
public static IEnumerable<FileInfo> FindImagesByName(DirectoryInfo directory, string name, SearchOption folderSearchOptions = SearchOption.AllDirectories)
|
||||
{
|
||||
var result = new List<FileInfo>();
|
||||
if (directory == null || !directory.Exists || string.IsNullOrEmpty(name))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
var imageFilesInFolder = ImageFilesInFolder(directory.FullName, folderSearchOptions);
|
||||
if (imageFilesInFolder == null || !imageFilesInFolder.Any())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
if (imageFilesInFolder.Any())
|
||||
{
|
||||
foreach (var imageFileInFolder in imageFilesInFolder)
|
||||
{
|
||||
var image = new FileInfo(imageFileInFolder);
|
||||
if(image.Name.Equals(name, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
result.Add(image);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static IEnumerable<FileInfo> FindImageTypeInDirectory(DirectoryInfo directory, ImageType type, SearchOption folderSearchOptions = SearchOption.AllDirectories)
|
||||
{
|
||||
var result = new List<FileInfo>();
|
||||
|
|
|
@ -18,7 +18,6 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Roadie.Library.Inspect
|
||||
{
|
||||
|
@ -328,6 +327,33 @@ namespace Roadie.Library.Inspect
|
|||
{
|
||||
Directory.CreateDirectory(subDirectory);
|
||||
}
|
||||
// Inspect images
|
||||
if (!inspectedImagesInDirectories.Contains(directoryInfo.FullName))
|
||||
{
|
||||
// Get all artist images and move to artist folder
|
||||
var foundArtistImages = new List<FileInfo>();
|
||||
foundArtistImages.AddRange(ImageHelper.FindImagesByName(directoryInfo.Parent, tagLib.Data.Artist, SearchOption.TopDirectoryOnly));
|
||||
foundArtistImages.AddRange(ImageHelper.FindImageTypeInDirectory(directoryInfo.Parent, Enums.ImageType.Artist, SearchOption.TopDirectoryOnly));
|
||||
foundArtistImages.AddRange(ImageHelper.FindImageTypeInDirectory(directoryInfo.Parent, Enums.ImageType.ArtistSecondary, SearchOption.TopDirectoryOnly));
|
||||
foundArtistImages.AddRange(ImageHelper.FindImageTypeInDirectory(directoryInfo, Enums.ImageType.Artist, SearchOption.TopDirectoryOnly));
|
||||
foundArtistImages.AddRange(ImageHelper.FindImageTypeInDirectory(directoryInfo, Enums.ImageType.ArtistSecondary, SearchOption.TopDirectoryOnly));
|
||||
|
||||
foreach (var artistImage in foundArtistImages)
|
||||
{
|
||||
InspectImage(isReadOnly, doCopy, dest, artistSubDirectory, artistImage);
|
||||
}
|
||||
|
||||
// Get all release images and move to release folder
|
||||
var foundReleaseImages = new List<FileInfo>();
|
||||
foundReleaseImages.AddRange(ImageHelper.FindImagesByName(directoryInfo, tagLib.Data.Release, SearchOption.AllDirectories));
|
||||
foundReleaseImages.AddRange(ImageHelper.FindImageTypeInDirectory(directoryInfo, Enums.ImageType.Release, SearchOption.AllDirectories));
|
||||
foundReleaseImages.AddRange(ImageHelper.FindImageTypeInDirectory(directoryInfo, Enums.ImageType.ReleaseSecondary, SearchOption.AllDirectories));
|
||||
foreach (var foundReleaseImage in foundReleaseImages)
|
||||
{
|
||||
InspectImage(isReadOnly, doCopy, dest, subDirectory, foundReleaseImage);
|
||||
}
|
||||
inspectedImagesInDirectories.Add(directoryInfo.FullName);
|
||||
}
|
||||
// If enabled move MP3 to new folder
|
||||
var newPath = Path.Combine(dest, subDirectory, newFileName.ToFileNameFriendly());
|
||||
if (isReadOnly)
|
||||
|
@ -355,30 +381,6 @@ namespace Roadie.Library.Inspect
|
|||
Console.WriteLine($"╠═» { (doCopy ? "Copied" : "Moved")} MP3 File to [{ newPath }]");
|
||||
Console.ResetColor();
|
||||
}
|
||||
if (!inspectedImagesInDirectories.Contains(directoryInfo.FullName))
|
||||
{
|
||||
// Get all artist images and move to artist folder
|
||||
var foundArtistImages = new List<FileInfo>();
|
||||
foundArtistImages.AddRange(ImageHelper.FindImageTypeInDirectory(directoryInfo.Parent, Enums.ImageType.Artist, SearchOption.TopDirectoryOnly));
|
||||
foundArtistImages.AddRange(ImageHelper.FindImageTypeInDirectory(directoryInfo.Parent, Enums.ImageType.ArtistSecondary, SearchOption.TopDirectoryOnly));
|
||||
foundArtistImages.AddRange(ImageHelper.FindImageTypeInDirectory(directoryInfo, Enums.ImageType.Artist, SearchOption.TopDirectoryOnly));
|
||||
foundArtistImages.AddRange(ImageHelper.FindImageTypeInDirectory(directoryInfo, Enums.ImageType.ArtistSecondary, SearchOption.TopDirectoryOnly));
|
||||
|
||||
foreach (var artistImage in foundArtistImages)
|
||||
{
|
||||
InspectImage(isReadOnly, doCopy, dest, artistSubDirectory, artistImage);
|
||||
}
|
||||
|
||||
// Get all release images and move to release folder
|
||||
var foundReleaseImages = new List<FileInfo>();
|
||||
foundReleaseImages.AddRange(ImageHelper.FindImageTypeInDirectory(directoryInfo, Enums.ImageType.Release, SearchOption.AllDirectories));
|
||||
foundReleaseImages.AddRange(ImageHelper.FindImageTypeInDirectory(directoryInfo, Enums.ImageType.ReleaseSecondary, SearchOption.AllDirectories));
|
||||
foreach (var foundReleaseImage in foundReleaseImages)
|
||||
{
|
||||
InspectImage(isReadOnly, doCopy, dest, subDirectory, foundReleaseImage);
|
||||
}
|
||||
inspectedImagesInDirectories.Add(directoryInfo.FullName);
|
||||
}
|
||||
Console.WriteLine("╠════════════════════════╣");
|
||||
}
|
||||
}
|
||||
|
@ -423,33 +425,42 @@ namespace Roadie.Library.Inspect
|
|||
|
||||
private void InspectImage(bool isReadOnly, bool doCopy, string dest, string subdirectory, FileInfo image)
|
||||
{
|
||||
if (!image.Exists)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"╟ ■ InspectImage: Image Not Found [{ image.FullName }]");
|
||||
Console.ResetColor();
|
||||
return;
|
||||
}
|
||||
Console.WriteLine($"╟─ Inspecting Image [{ image.FullName }]");
|
||||
var newImagePath = Path.Combine(dest, subdirectory, image.Name);
|
||||
if (isReadOnly)
|
||||
if (image.FullName != newImagePath)
|
||||
{
|
||||
Console.WriteLine($"╟ ■ Read Only Mode: Would be [{ (doCopy ? "Copied" : "Moved") }] to [{ newImagePath }]");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!doCopy)
|
||||
var looper = 0;
|
||||
while (File.Exists(newImagePath))
|
||||
{
|
||||
if (image.FullName != newImagePath)
|
||||
{
|
||||
if (File.Exists(newImagePath))
|
||||
{
|
||||
File.Delete(newImagePath);
|
||||
}
|
||||
image.MoveTo(newImagePath);
|
||||
}
|
||||
looper++;
|
||||
newImagePath = Path.Combine(dest, subdirectory, looper.ToString("00"), image.Name);
|
||||
}
|
||||
if (isReadOnly)
|
||||
{
|
||||
Console.WriteLine($"╟ ■ Read Only Mode: Would be [{ (doCopy ? "Copied" : "Moved") }] to [{ newImagePath }]");
|
||||
}
|
||||
else
|
||||
{
|
||||
image.CopyTo(newImagePath, true);
|
||||
if (!doCopy)
|
||||
{
|
||||
image.MoveTo(newImagePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
image.CopyTo(newImagePath, true);
|
||||
}
|
||||
Console.ForegroundColor = ConsoleColor.DarkYellow;
|
||||
Console.WriteLine($"╠═» { (doCopy ? "Copied" : "Moved")} Image File to [{ newImagePath }]");
|
||||
}
|
||||
Console.ForegroundColor = ConsoleColor.DarkYellow;
|
||||
Console.WriteLine($"╠═» { (doCopy ? "Copied" : "Moved")} Image File to [{ newImagePath }]");
|
||||
Console.ResetColor();
|
||||
}
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
private void MessageLogger_Messages(object sender, EventMessage e) => Console.WriteLine($"Log Level [{ e.Level }] Log Message [{ e.Message }] ");
|
||||
|
|
|
@ -12,10 +12,9 @@ namespace Roadie.Api
|
|||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var dbFilename = $"logs\\errors.db";
|
||||
var dbFilename = Path.Combine("logs", "errors.db");
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(Configuration)
|
||||
.WriteTo.SQLite(sqliteDbPath: dbFilename, storeTimestampInUtc: true, restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Error)
|
||||
.CreateLogger();
|
||||
|
||||
try
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BCrypt-Core" Version="2.0.0" />
|
||||
<PackageReference Include="Mapster" Version="4.0.0" />
|
||||
<PackageReference Include="Mapster" Version="4.1.0" />
|
||||
<PackageReference Include="Microsoft.AspNet.SignalR" Version="2.4.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OData" Version="7.1.0" />
|
||||
|
@ -33,9 +33,8 @@
|
|||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
|
||||
<PackageReference Include="Serilog.Sinks.RollingFileAlternate" Version="2.0.9" />
|
||||
<PackageReference Include="Serilog.Sinks.SQLite" Version="4.5.0" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.4.0" />
|
||||
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.16" />
|
||||
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.17" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
Loading…
Reference in a new issue