Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

WIP #48

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

WIP #48

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Inspector/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class Program
[Required]
public string Folder { get; }

[Option("-g", "Only generate Roadie data files", CommandOptionType.NoValue)]
public bool OnlyCreateRoadieFiles { get; }

[Option("-r", "Only show what would be done, don't modify any files", CommandOptionType.NoValue)]
public bool IsReadOnly { get; }

Expand All @@ -44,7 +47,14 @@ private void OnExecute()

var host = builder.Build();
var inspector = new Roadie.Library.Inspect.Inspector(host.Services.GetRequiredService<IHttpClientFactory>());
inspector.Inspect(DoCopy, IsReadOnly, Folder, Destination ?? Folder, DontAppendSubFolder, IsReadOnly ? true : DontDeleteEmptyFolders, DontRunPreScript);
if (OnlyCreateRoadieFiles)
{
inspector.GenerateRoadieDataFiles(Folder);
}
else
{
inspector.Inspect(DoCopy, IsReadOnly, Folder, Destination ?? Folder, DontAppendSubFolder, IsReadOnly ? true : DontDeleteEmptyFolders, DontRunPreScript);
}
}
}
}
2 changes: 1 addition & 1 deletion Inspector/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"Inspector": {
"commandName": "Project",
"commandLineArgs": "-f \"G:\\complete\\_\" -d \"M:\\inbound\""
"commandLineArgs": "-g -f \"G:\\complete\\_\""
}
}
}
32 changes: 16 additions & 16 deletions Roadie.Api.Library.Tests/ExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void ShuffleUniqueOrder()
{
Artist = new Models.DataToken { Value = "A1", Text = "A1" }
},
Release = new Models.Releases.ReleaseList
Release = new Models.Releases.ReleaseList<Models.TrackList>
{
Release = new Models.DataToken { Value = "R1", Text = "R1" }
}
Expand All @@ -32,7 +32,7 @@ public void ShuffleUniqueOrder()
{
Artist = new Models.DataToken { Value = "A2", Text = "A2" }
},
Release = new Models.Releases.ReleaseList
Release = new Models.Releases.ReleaseList<Models.TrackList>
{
Release = new Models.DataToken { Value = "R4", Text = "R4" }
}
Expand All @@ -44,7 +44,7 @@ public void ShuffleUniqueOrder()
{
Artist = new Models.DataToken { Value = "A1", Text = "A1" }
},
Release = new Models.Releases.ReleaseList
Release = new Models.Releases.ReleaseList<Models.TrackList>
{
Release = new Models.DataToken { Value = "R5", Text = "R5" }
}
Expand All @@ -56,7 +56,7 @@ public void ShuffleUniqueOrder()
{
Artist = new Models.DataToken { Value = "A1", Text = "A1" }
},
Release = new Models.Releases.ReleaseList
Release = new Models.Releases.ReleaseList<Models.TrackList>
{
Release = new Models.DataToken { Value = "R1", Text = "R1" }
}
Expand All @@ -68,7 +68,7 @@ public void ShuffleUniqueOrder()
{
Artist = new Models.DataToken { Value = "A3", Text = "A3" }
},
Release = new Models.Releases.ReleaseList
Release = new Models.Releases.ReleaseList<Models.TrackList>
{
Release = new Models.DataToken { Value = "R6", Text = "R6" }
}
Expand All @@ -80,7 +80,7 @@ public void ShuffleUniqueOrder()
{
Artist = new Models.DataToken { Value = "A2", Text = "A2" }
},
Release = new Models.Releases.ReleaseList
Release = new Models.Releases.ReleaseList<Models.TrackList>
{
Release = new Models.DataToken { Value = "R5", Text = "R5" }
}
Expand All @@ -92,7 +92,7 @@ public void ShuffleUniqueOrder()
{
Artist = new Models.DataToken { Value = "A2", Text = "A2" }
},
Release = new Models.Releases.ReleaseList
Release = new Models.Releases.ReleaseList<Models.TrackList>
{
Release = new Models.DataToken { Value = "R5", Text = "R5" }
}
Expand All @@ -104,7 +104,7 @@ public void ShuffleUniqueOrder()
{
Artist = new Models.DataToken { Value = "A2", Text = "A2" }
},
Release = new Models.Releases.ReleaseList
Release = new Models.Releases.ReleaseList<Models.TrackList>
{
Release = new Models.DataToken { Value = "R5", Text = "R5" }
}
Expand All @@ -116,7 +116,7 @@ public void ShuffleUniqueOrder()
{
Artist = new Models.DataToken { Value = "A2", Text = "A2" }
},
Release = new Models.Releases.ReleaseList
Release = new Models.Releases.ReleaseList<Models.TrackList>
{
Release = new Models.DataToken { Value = "R6", Text = "R6" }
}
Expand All @@ -128,7 +128,7 @@ public void ShuffleUniqueOrder()
{
Artist = new Models.DataToken { Value = "A4", Text = "A4" }
},
Release = new Models.Releases.ReleaseList
Release = new Models.Releases.ReleaseList<Models.TrackList>
{
Release = new Models.DataToken { Value = "R7", Text = "R7" }
}
Expand All @@ -140,7 +140,7 @@ public void ShuffleUniqueOrder()
{
Artist = new Models.DataToken { Value = "A5", Text = "A5" }
},
Release = new Models.Releases.ReleaseList
Release = new Models.Releases.ReleaseList<Models.TrackList>
{
Release = new Models.DataToken { Value = "R8", Text = "R8" }
}
Expand All @@ -152,7 +152,7 @@ public void ShuffleUniqueOrder()
{
Artist = new Models.DataToken { Value = "A6", Text = "A6" }
},
Release = new Models.Releases.ReleaseList
Release = new Models.Releases.ReleaseList<Models.TrackList>
{
Release = new Models.DataToken { Value = "R9", Text = "R9" }
}
Expand All @@ -164,7 +164,7 @@ public void ShuffleUniqueOrder()
{
Artist = new Models.DataToken { Value = "A7", Text = "A7" }
},
Release = new Models.Releases.ReleaseList
Release = new Models.Releases.ReleaseList<Models.TrackList>
{
Release = new Models.DataToken { Value = "R10", Text = "R10" }
}
Expand All @@ -176,7 +176,7 @@ public void ShuffleUniqueOrder()
{
Artist = new Models.DataToken { Value = "A8", Text = "A8" }
},
Release = new Models.Releases.ReleaseList
Release = new Models.Releases.ReleaseList<Models.TrackList>
{
Release = new Models.DataToken { Value = "R11", Text = "R11" }
}
Expand All @@ -188,7 +188,7 @@ public void ShuffleUniqueOrder()
{
Artist = new Models.DataToken { Value = "A9", Text = "A9" }
},
Release = new Models.Releases.ReleaseList
Release = new Models.Releases.ReleaseList<Models.TrackList>
{
Release = new Models.DataToken { Value = "R12", Text = "R12" }
}
Expand All @@ -200,7 +200,7 @@ public void ShuffleUniqueOrder()
{
Artist = new Models.DataToken { Value = "A10", Text = "A10" }
},
Release = new Models.Releases.ReleaseList
Release = new Models.Releases.ReleaseList<Models.TrackList>
{
Release = new Models.DataToken { Value = "R13", Text = "R13" }
}
Expand Down
4 changes: 2 additions & 2 deletions Roadie.Api.Library.Tests/LastFmHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task LastFMReleaseSearch()

var logger = new EventMessageLogger<LastFmHelper>();
logger.Messages += MessageLogger_Messages;
var lfmHelper = new LastFmHelper(Configuration, CacheManager, new EventMessageLogger<LastFmHelper>(), RoadieDbContext, HttpEncoder, _httpClientFactory);
var lfmHelper = new LastFmHelper(Configuration, CacheManager, new EventMessageLogger<LastFmHelper>(), HttpEncoder, _httpClientFactory);

var artistName = "Billy Joel";
var title = "Piano Man";
Expand Down Expand Up @@ -103,7 +103,7 @@ public async Task LastFMArtistSearch()
}
var logger = new EventMessageLogger<LastFmHelper>();
logger.Messages += MessageLogger_Messages;
var lfmHelper = new LastFmHelper(Configuration, CacheManager, new EventMessageLogger<LastFmHelper>(), RoadieDbContext, HttpEncoder, _httpClientFactory);
var lfmHelper = new LastFmHelper(Configuration, CacheManager, new EventMessageLogger<LastFmHelper>(), HttpEncoder, _httpClientFactory);

var artistName = "Billy Joel";
var sw = Stopwatch.StartNew();
Expand Down
3 changes: 2 additions & 1 deletion Roadie.Api.Library/Caching/NewtonsoftCacheSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public NewtonsoftCacheSerializer(ILogger logger)
{
ContractResolver = new IgnoreJsonAttributesResolver(),
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
Formatting = Formatting.Indented
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
};
}

Expand Down
6 changes: 3 additions & 3 deletions Roadie.Api.Library/Configuration/Inspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
public class Inspector : IInspector
{
/// <summary>
/// When true then make a copy of files to new destination versus moving files to destination.
/// When true then make a copy of files to new destination versus moving files to destination.
/// </summary>
public bool DoCopyFiles { get; set; }

/// <summary>
/// When true then don't modify any files only report what would be done.
/// When true then don't modify any files only report what would be done.
/// </summary>
public bool IsInReadOnlyMode { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion Roadie.Api.Library/Engines/ArtistLookupEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public async Task<OperationResult<Artist>> GetByName(AudioMetaData metaData, boo
};
}

// See if roadie.json file exists in the metadata files folder, if so then use artist data from that
// See if roadie.artist.json file exists in the metadata files folder, if so then use artist data from that
string releaseRoadieDataFilename = null;
try
{
Expand Down
80 changes: 61 additions & 19 deletions Roadie.Api.Library/Inspect/Inspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
using System.Linq;
using System.Management.Automation;
using System.Net.Http;
using System.Text.Json;

namespace Roadie.Library.Inspect
{
Expand All @@ -30,8 +29,11 @@ public class Inspector
private const string Salt = "6856F2EE-5965-4345-884B-2CCA457AAF59";

private IRoadieSettings Configuration { get; }

private ILogger Logger => MessageLogger as ILogger;

private IEventMessageLogger MessageLogger { get; }

private ID3TagsHelper TagsHelper { get; }

private IEnumerable<IInspectorDirectoryPlugin> _directoryPlugins;
Expand Down Expand Up @@ -139,6 +141,7 @@ public Inspector(IHttpClientFactory httpClientFactory)
var tagHelperLooper = new EventMessageLogger<ID3TagsHelper>();
tagHelperLooper.Messages += MessageLogger_Messages;
TagsHelper = new ID3TagsHelper(Configuration, CacheManager, tagHelperLooper, httpClientFactory);

}

private void InspectImage(bool isReadOnly, bool doCopy, string dest, string subdirectory, FileInfo image)
Expand Down Expand Up @@ -238,11 +241,11 @@ private string RunScript(string scriptFilename, bool doCopy, bool isReadOnly, st
{
if (!File.Exists(scriptFilename))
{
Console.WriteLine($"Script Not Found: [{ scriptFilename }]");
Console.WriteLine($"Script Not Found: [{scriptFilename}]");
return null;
}

Console.WriteLine($"Running Script: [{ scriptFilename }]");
Console.WriteLine($"Running Script: [{scriptFilename}]");
var script = File.ReadAllText(scriptFilename);
using (var ps = PowerShell.Create())
{
Expand All @@ -269,17 +272,8 @@ private string RunScript(string scriptFilename, bool doCopy, bool isReadOnly, st

public static string ArtistInspectorToken(AudioMetaData metaData) => ToToken(metaData.Artist);

public void Inspect(bool doCopy, bool isReadOnly, string directoryToInspect, string destination, bool dontAppendSubFolder, bool dontDeleteEmptyFolders, bool dontRunPreScripts)
void PrintInspectorBanner(string directory)
{
Configuration.Inspector.IsInReadOnlyMode = isReadOnly;
Configuration.Inspector.DoCopyFiles = doCopy;

var artistsFound = new List<string>();
var releasesFound = new List<string>();
var mp3FilesFoundCount = 0;

Trace.Listeners.Add(new LoggingTraceListener());

Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("");
Console.WriteLine(" ▄▄▄ ▄▄▄· ·▄▄▄▄ ▪ ▄▄▄ . • ▌ ▄ ·. ▄▄▄ .·▄▄▄▄ ▪ ▄▄▄· ▪ ▐ ▄ .▄▄ · ▄▄▄·▄▄▄ . ▄▄· ▄▄▄▄▄ ▄▄▄ ");
Expand All @@ -295,14 +289,62 @@ public void Inspect(bool doCopy, bool isReadOnly, string directoryToInspect, str
Console.WriteLine($"✨ Inspector Start, UTC [{DateTime.UtcNow.ToString("s")}]");
Console.ResetColor();

if (!Directory.Exists(directoryToInspect))
if (!Directory.Exists(directory))
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"📛 Folder [{directory}] is not found.");
Console.ResetColor();
return;
}
}

public void GenerateRoadieDataFiles(string directory)
{
PrintInspectorBanner(directory);

var roadieDataFilePlugin = DirectoryPlugins.FirstOrDefault(x => x.Description == RoadieDataFileCreator.RoadieDataFileCreatorDescription);
if(roadieDataFilePlugin == null)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"📛 Folder To Inspect [{ directoryToInspect }] is not found.");
Console.WriteLine($"📛 Unable to find Roadie Data File Creator Plugin.");
Console.ResetColor();
return;
}

Console.WriteLine($"╠╬═ Running Directory Plugin: {roadieDataFilePlugin.Description}");

// Get all the top level directorys in the directory
var directoryDirectories = Directory.GetDirectories(directory, "*.*", SearchOption.TopDirectoryOnly);
foreach(var directoryDirectory in directoryDirectories)
{
var directoryInfo = new DirectoryInfo(directoryDirectory);

var pluginResult = roadieDataFilePlugin.Process(directoryInfo);
if (!pluginResult.IsSuccess)
{
Console.WriteLine($"📛 Plugin Failed: Error [{CacheManager.CacheSerializer.Serialize(pluginResult)}]");
return;
}
if (!string.IsNullOrEmpty(pluginResult.Data))
{
Console.WriteLine($"╠╣ Directory Plugin Message: {pluginResult.Data}");
}
}
}

public void Inspect(bool doCopy, bool isReadOnly, string directoryToInspect, string destination, bool dontAppendSubFolder, bool dontDeleteEmptyFolders, bool dontRunPreScripts)
{
Configuration.Inspector.IsInReadOnlyMode = isReadOnly;
Configuration.Inspector.DoCopyFiles = doCopy;

var artistsFound = new List<string>();
var releasesFound = new List<string>();
var mp3FilesFoundCount = 0;

Trace.Listeners.Add(new LoggingTraceListener());

PrintInspectorBanner(directoryToInspect);

string scriptResult = null;
// Run PreInspect script
dontRunPreScripts = File.Exists(Configuration.Processing.PreInspectScript) && dontRunPreScripts;
Expand Down Expand Up @@ -366,7 +408,7 @@ public void Inspect(bool doCopy, bool isReadOnly, string directoryToInspect, str
// Run directory plugins against current directory
foreach (var plugin in DirectoryPlugins.Where(x => !x.IsPostProcessingPlugin).OrderBy(x => x.Order))
{
Console.WriteLine($"╠╬═ Running Directory Plugin {plugin.Description}");
Console.WriteLine($"╠╬═ Running Directory Plugin: {plugin.Description}");
var pluginResult = plugin.Process(directoryInfo);
if (!pluginResult.IsSuccess)
{
Expand Down Expand Up @@ -662,12 +704,12 @@ public class LoggingTraceListener : TraceListener
{
public override void Write(string message)
{
Console.WriteLine($"╠╬═ { message }");
Console.WriteLine($"╠╬═ {message}");
}

public override void WriteLine(string message)
{
Console.WriteLine($"╠╬═ { message }");
Console.WriteLine($"╠╬═ {message}");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ public override OperationResult<string> Process(DirectoryInfo directory)
return result;
}
}
}
}
Loading