deez nuts

This commit is contained in:
2025-09-29 18:44:48 -04:00
parent e6b6289aea
commit 5fb096b6e2
2 changed files with 93 additions and 14 deletions

View File

@@ -19,6 +19,7 @@
<PackageReference Include="Microsoft.WSMan.Runtime" Version="7.4.7" />
<PackageReference Include="MySql.Data" Version="9.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Spectre.Console" Version="0.50.1-preview.0.5" />
<PackageReference Include="System.Data.Odbc" Version="8.0.0" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="8.0.1" />
<PackageReference Include="System.Management" Version="10.0.0-preview.1.25080.5" />

View File

@@ -7,6 +7,8 @@ using System.Text;
using System.Management.Automation;
using System.IO;
using Microsoft.PowerShell.Commands;
using Mysqlx.Crud;
using Spectre.Console;
namespace PhotosImporter
{
public class Program
@@ -23,7 +25,7 @@ namespace PhotosImporter
return ConsoleCommandDispatcher.FindCommandsInSameAssemblyAs(typeof(Program));
}
}
public class ImportCommand : ConsoleCommand
public class ImportCommand : ConsoleCommand // deez nuts
{
private const int Success = 0;
private const int Failure = 2;
@@ -156,15 +158,15 @@ namespace PhotosImporter
// p.WaitForExit();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
Console.WriteLine(output);
//Console.WriteLine(output); //dep 5/3/25
dynamic tmp = JsonConvert.DeserializeObject(output);
p.WaitForExit();
if (tmp[0].ContainsKey("TagsList")) {
return JsonConvert.SerializeObject(tmp[0]["TagsList"]);
return string.Join(":", tmp[0]["TagsList"]);
} else
{
return "{}";
return null;
}
//Console.WriteLine("Line 100: Tags (none)");
@@ -253,31 +255,51 @@ namespace PhotosImporter
string[] videoExtensions = GetVideoExtensions(videoExtensionsPath);
List<string> badFileNotifications = new List<string>();
Console.WriteLine("Deleting and re-indexing in 10 seconds...");
// Console.WriteLine("Deleting and re-indexing in 10 seconds...");
// System.Threading.Thread.Sleep(10000);
if (LiveUpdate) {
DeleteRecords(PhotosTable);
ReIndexRecords(PhotosTable);
}
//new ProgressBarColumn { IndeterminateStyle}.
AnsiConsole.Progress()
.AutoRefresh(true) // Turn off auto refresh
.AutoClear(false) // Do not remove the task list when done
.HideCompleted(false) // Hide tasks as they are completed
.Columns(new ProgressColumn[]
{
new SpinnerColumn(Spinner.Known.BoxBounce), // Task description
new ProgressBarColumn(), // Progress bar
new PercentageColumn(), // Percentage
new RemainingTimeColumn(), // Remaining time
}).Start(ctx =>
{
var tsk = new ProgressTaskSettings { MaxValue = Directory.GetFiles(PhotosPath).Length, AutoStart = true };
var task1 = ctx.AddTask("Photos Processed", tsk);
foreach (string filename in Directory.GetFiles(PhotosPath))
{
FileInfo file = new(filename);
if (!file.Name.StartsWith('.') && !IsBannedExtension(file.Name, bannedExtensions))
{
Console.WriteLine($"{file.Name}");
//Console.WriteLine($"{file.Name}");
//Path.GetFileName(filename);
if (IsBadFilename(file.Name))
{
badFileNotifications.Add($"Bad Filename: {file}");
Console.WriteLine($"Bad Filename: {file.Name}");
//Console.WriteLine($"Bad Filename: {file.Name}");
sqlFile.WriteLine(FixBadFilenameAndUpdateRecord(file, videoExtensions, PhotosTable));
} else {;
}
else
{
;
sqlFile.WriteLine(UpdateRecord(file, videoExtensions, PhotosTable));
}
Console.WriteLine("Processed: " + file.Name);
//Console.WriteLine("Processed: " + file.Name);
}
task1.Increment(1.0);
}
});
foreach (var item in badFileNotifications)
{
@@ -290,4 +312,60 @@ namespace PhotosImporter
}
}
public class CreateLibraryCommand: ConsoleCommand
{
private const int Success = 0;
private const int Failure = 2;
public string PhotosPath { get; set; }
public string PhotosTable { get; set; }
public bool Force { get; set; }
public CreateLibraryCommand()
{
// Register the actual command with a simple (optional) description.
IsCommand("create", "Create Library");
// Add a longer description for the help on that specific command.
HasLongDescription("This can be used to quickly read a file's contents " +
"while optionally stripping out the ',' character.");
// Required options/flags, append '=' to obtain the required value.
HasRequiredOption("p|path=", "Path", p => PhotosPath = p);
HasRequiredOption("t|table=", "Table", t => PhotosTable = t);
HasRequiredOption("f|force=", "Force", f => Force = false);
// Optional options/flags, append ':' to obtain an optional value, or null if not specified.
//HasOption("s|strip:", "Strips ',' from the file before writing to output.",
// t => StripCommaCharacter = t == null ? true : Convert.ToBoolean(t));
}
public override int Run(string[] remainingArguments)
{
using (OdbcConnection connection = new OdbcConnection("DSN=photos"))
{
connection.Open();
string query = $"SHOW TABLES like \"{PhotosTable}\";";
OdbcCommand command = new OdbcCommand(query, connection);
int exists = command.ExecuteNonQuery();
if ( exists > 0)
{
Console.WriteLine("Library already exists!");
return Failure;
} else
{
var ggg = new DirectoryInfo(PhotosPath).FullName;
new OdbcCommand($"CREATE TABLE {PhotosTable} LIKE template;", connection).ExecuteNonQuery();
new OdbcCommand($"INSERT INTO meta (db, path) VALUES (\"{PhotosTable}\", \"{ggg}\");",connection).ExecuteNonQuery();
Console.WriteLine($"Created Library \"{PhotosTable}\"");
return Success;
}
}
}
}
}