From b0f10b747847ab5811b0f8f5df5743c0e98ceffa Mon Sep 17 00:00:00 2001 From: Read Stanton Date: Tue, 5 Nov 2024 13:58:42 -0600 Subject: [PATCH] Rdx 1.0.7 --- SmartImage.Lib/SearchConfig.cs | 2 +- SmartImage.Rdx/Icon.ico | Bin 0 -> 270398 bytes SmartImage.Rdx/IntegrationCommand.cs | 3 +- SmartImage.Rdx/Program.cs | 6 +- SmartImage.Rdx/SearchCommand.cs | 370 ++++++++++++++---------- SmartImage.Rdx/SearchCommandSettings.cs | 9 + SmartImage.Rdx/Shell/ConsoleItems.cs | 17 ++ SmartImage.Rdx/SmartImage.Rdx.csproj | 7 +- 8 files changed, 255 insertions(+), 159 deletions(-) create mode 100644 SmartImage.Rdx/Icon.ico create mode 100644 SmartImage.Rdx/Shell/ConsoleItems.cs diff --git a/SmartImage.Lib/SearchConfig.cs b/SmartImage.Lib/SearchConfig.cs index a5c296ee..f3d6d915 100644 --- a/SmartImage.Lib/SearchConfig.cs +++ b/SmartImage.Lib/SearchConfig.cs @@ -202,7 +202,7 @@ public bool ReadCookies /// public bool FlareSolverr { - get { return Configuration.ReadSetting(nameof(FlareSolverr), false); } + get { return Configuration.ReadSetting(nameof(FlareSolverr), FLARESOLVERR_DEFAULT); } set { Configuration.AddUpdateSetting(nameof(FlareSolverr), value.ToString()); diff --git a/SmartImage.Rdx/Icon.ico b/SmartImage.Rdx/Icon.ico new file mode 100644 index 0000000000000000000000000000000000000000..566fb88db613bbdd816dfe8441d7f6b483dd1fa4 GIT binary patch literal 270398 zcmeI5X>b)+cE^Rwp2>%#YUazNl8I|3u1saVq*9gCB$HI7CX-4s6YpcQX<;$Dki=rM zgUw#pzu9NnUmQHcMjQjO3Uyl2k_WQ4&{2?yxr6+%}=|7JP z`~*JZKUe@3fCXRySO6A)1z-VK02Y7+U;$VF7Jvm{0aySQ@Vx~lfA*`Fr_FtJ;p`PZ zt)0K+#~q7yc4CWm#o-4wfCgmJfX1c9=Of~D+Pqg65w~`O*OZ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`mz4&1?ab~OP0 zp&`2(!v5-N2>h$-J8%cz+0_8}hlcEG2>UCmp$?P$--NG~^)=@8*5sy zz4oKBO;C6E&&wJhK8aJ})$~2T&OFwz04x9tzyh!UEC36@0sJ3M+>eq1-A4mWGcQFP<{Q}=dH6ZL0)jV;q59|}o0?%@T{Tz{ep1pGub5BLE;Q3V2iqMAp3e%fQyKi2o)BdP(xM^y93&j<7!)q&7=RP#XJ z;3uj;z)w{3fFJM^RUqIes(HW<_=zeI@DtTM;K%R$#Crc5>-{mC6jfldzdesxzyAkQ C-?1eC literal 0 HcmV?d00001 diff --git a/SmartImage.Rdx/IntegrationCommand.cs b/SmartImage.Rdx/IntegrationCommand.cs index 6e372138..688fbfec 100644 --- a/SmartImage.Rdx/IntegrationCommand.cs +++ b/SmartImage.Rdx/IntegrationCommand.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using SmartImage.Lib.Utilities; +using SmartImage.Rdx.Shell; using Spectre.Console; using Spectre.Console.Cli; @@ -27,7 +28,7 @@ public override int Execute(CommandContext context, IntegrationCommandSettings s AConsole.WriteException(e); } - return SearchCommand.EC_OK; + return ConsoleItems.EC_OK; } } \ No newline at end of file diff --git a/SmartImage.Rdx/Program.cs b/SmartImage.Rdx/Program.cs index 24c10138..50c42353 100644 --- a/SmartImage.Rdx/Program.cs +++ b/SmartImage.Rdx/Program.cs @@ -131,7 +131,7 @@ public static async Task Main(string[] args) .WithDescription("Configure system integration such as context menu"); }); - int x = SearchCommand.EC_OK; + int x = ConsoleItems.EC_OK; try { x = await app.RunAsync(args); @@ -139,11 +139,11 @@ public static async Task Main(string[] args) } catch (Exception e) { AConsole.WriteException(e); - x = SearchCommand.EC_ERROR; + x = ConsoleItems.EC_ERROR; } finally { - if (x != SearchCommand.EC_OK) { + if (x != ConsoleItems.EC_OK) { AConsole.Confirm("Press any key to continue"); } } diff --git a/SmartImage.Rdx/SearchCommand.cs b/SmartImage.Rdx/SearchCommand.cs index a4f999cb..822e65d1 100644 --- a/SmartImage.Rdx/SearchCommand.cs +++ b/SmartImage.Rdx/SearchCommand.cs @@ -60,17 +60,13 @@ public sealed class SearchCommand : AsyncCommand, IDispos private readonly CancellationTokenSource m_cts; - private readonly ConcurrentBag m_results; + private readonly ConcurrentBag m_results; + private readonly ConcurrentDictionary> m_results2; private SearchCommandSettings m_scs; private readonly STable m_table; - private const double COMPLETE = 100.0d; - - public const int EC_ERROR = -1; - public const int EC_OK = 0; - public static readonly Assembly Assembly = Assembly.GetExecutingAssembly(); public static readonly Version Version = Assembly.GetName().Version; @@ -84,10 +80,11 @@ public SearchCommand() // Client.OnSearchComplete += OnSearchComplete; // Client.OnResultComplete += OnResultComplete; - m_cts = new CancellationTokenSource(); - m_results = new ConcurrentBag(); - m_scs = null; - m_table = CreateResultTable(); + m_cts = new CancellationTokenSource(); + m_results = new ConcurrentBag(); + m_results2 = new ConcurrentDictionary>(); + m_scs = null; + m_table = CreateResultTable(); Query = SearchQuery.Null; } @@ -101,16 +98,17 @@ private async Task InitConfigAsync([CBN] object c) Config.SearchEngines = m_scs.SearchEngines; Config.PriorityEngines = m_scs.PriorityEngines; - if (m_scs.AutoSearch.HasValue) - { + if (m_scs.AutoSearch.HasValue) { Config.AutoSearch = m_scs.AutoSearch.Value; } - if (m_scs.ReadCookies.HasValue) - { + if (m_scs.ReadCookies.HasValue) { Config.ReadCookies = m_scs.ReadCookies.Value; } + Config.FlareSolverr = m_scs.FlareSolverr; + Config.FlareSolverrApiUrl = m_scs.FlareSolverrApiUrl; + await Client.LoadEnginesAsync(); } @@ -123,8 +121,7 @@ private async Task SetupSearchAsync(ProgressContext ctx) Query = await SearchQuery.TryCreateAsync(m_scs.Query); - if (Query == SearchQuery.Null) - { + if (Query == SearchQuery.Null) { // throw new SmartImageException($"Could not create query"); //todo ok = false; @@ -132,21 +129,20 @@ private async Task SetupSearchAsync(ProgressContext ctx) } - p.Increment(COMPLETE / 2); + p.Increment(ConsoleItems.COMPLETE / 2); // ctx.Refresh(); p.Description = "Uploading query"; var url = await Query.UploadAsync(); - if (url == null) - { + if (url == null) { // throw new SmartImageException("Could not upload query"); //todo ok = false; goto ret; } - p.Increment(COMPLETE / 2); + p.Increment(ConsoleItems.COMPLETE / 2); ret: return ok; @@ -161,26 +157,27 @@ public override async Task ExecuteAsync(CommandContext context, SearchComma .StartAsync(SetupSearchAsync); - try - { + try { var ok = await task; - if (ok) - { + if (ok) { var ci = GetQueryCanvasImage(); - AConsole.Write(new Panel(ci) { Header = new PanelHeader($"{Query.Uni.ValueString}") }); + + var panel = new Panel(ci) + { + Header = new PanelHeader($"{Query.Uni.ValueString}") + }; + AConsole.Write(panel); await InitConfigAsync(ok); } - else - { + else { throw new SmartImageException("Could not upload query"); } } - catch (Exception e) - { + catch (Exception e) { AConsole.WriteException(e); - return EC_ERROR; + return ConsoleItems.EC_ERROR; } var gr = CreateConfigGrid(); @@ -203,16 +200,13 @@ public override async Task ExecuteAsync(CommandContext context, SearchComma #endif - if (!String.IsNullOrWhiteSpace(m_scs.Command)) - { + if (!String.IsNullOrWhiteSpace(m_scs.Command)) { run = run.ContinueWith(RunCompletionCommandAsync, m_cts.Token, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Default); } - if (!String.IsNullOrWhiteSpace(m_scs.OutputFile)) - { - switch (m_scs.OutputFileFormat) - { + if (!String.IsNullOrWhiteSpace(m_scs.OutputFile)) { + switch (m_scs.OutputFileFormat) { case OutputFileFormat.None: break; @@ -233,64 +227,40 @@ public override async Task ExecuteAsync(CommandContext context, SearchComma Task run2; - if (m_scs.Interactive.HasValue && m_scs.Interactive.Value) - { + if (m_scs.Interactive.HasValue && m_scs.Interactive.Value) { + string cmd = null; - var item = ShowInteractivePromptAsync(); - AConsole.Clear(); + do { + cmd = GetCommandPrompt(); - var gr2 = new Grid(); - gr2.AddColumns(5); - gr2.AddRow(CreateResultItemRows(item, 0, Style.Plain)); - - // AConsole.Write(gr2); - - var tr = new Tree(gr2); - var ld = AConsole.Live(tr); - - run2 = ld.StartAsync(async f => - { - // var ok = await r.ScanAsync(); + if (cmd != ConsoleItems.s_commandChoices[^1]) { + var sr = GetResultPrompt(); + var num = GetNumberPrompt(sr); + var res = sr.Results[num]; - var resOk = await ImageScanner.ScanImagesAsync(item.Url); - - while (resOk.Count != 0) - { - var t = await Task.WhenAny(resOk); - resOk.Remove(t); - - var r = await t; - - if (r == null) - { - continue; + if (cmd == ConsoleItems.s_commandChoices[0]) { + SearchClient.OpenResult(res.Url); } - - if (r is UniImageUri ru) - { - tr.AddNode(new Text(ru.ValueString, new Style(link: ru.Url))); - + else if (cmd == ConsoleItems.s_commandChoices[1]) { + run2 = ShowImageScanResultsAsync(res); + await run2; } - - f.Refresh(); - } + else { } - }); + } while (cmd != ConsoleItems.s_commandChoices[^1]); - - await run2; + // run2 = ShowImageScanResultsAsync(item); + // await run2; } - if (m_scs.KeepOpen.HasValue && m_scs.KeepOpen.Value) - { - while (!AConsole.Confirm("Exit")) - { + if (m_scs.KeepOpen.HasValue && m_scs.KeepOpen.Value) { + while (!AConsole.Confirm("Exit")) { // ... } } - return EC_OK; + return ConsoleItems.EC_OK; } // TODO: Rewrite RunSearch counterparts @@ -304,8 +274,7 @@ private async Task RunSearchLiveAsync(LiveDisplayContext c) #endif var search = Client.RunSearchAsync(Query, token: m_cts.Token); - while (await Client.ResultChannel.Reader.WaitToReadAsync()) - { + while (await Client.ResultChannel.Reader.WaitToReadAsync()) { var result = await Client.ResultChannel.Reader.ReadAsync(); m_results.Add(result); @@ -317,8 +286,7 @@ private async Task RunSearchLiveAsync(LiveDisplayContext c) var rows = CreateResultRows(result); - foreach (IRenderable[] row in rows) - { + foreach (IRenderable[] row in rows) { m_table.AddRow(row); } @@ -329,80 +297,65 @@ private async Task RunSearchLiveAsync(LiveDisplayContext c) } - private async Task RunCompletionCommandAsync([CBN] object o) + private int GetNumberPrompt(SearchResult result) { - Debug.WriteLine($"{nameof(RunCompletionCommandAsync)}"); - var command = Cli.Wrap(m_scs.Command); - - var cmdArgs = m_scs.CommandArguments; - var stdOutBuffer = new StringBuilder(); - var stdErrBuffer = new StringBuilder(); + int input = default; - if (!String.IsNullOrWhiteSpace(cmdArgs)) + var prompt = new TextPrompt("<#>") { - command = command.WithArguments(cmdArgs); - } - - command = command.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdErrBuffer)) - .WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdOutBuffer)); - - var commandTask = command.ExecuteAsync(m_cts.Token); + ShowChoices = false, + ShowDefaultValue = false, + AllowEmpty = false, + Validator = i => + { + if (i < result.Results.Count && i >= 0) { + return ValidationResult.Success(); + } - AConsole.WriteLine($"Process id: {commandTask.ProcessId}"); + return ValidationResult.Error("Out of range"); + } + }; + input = AConsole.Prompt(prompt); - var result = await commandTask; - AConsole.WriteLine($"Process successful: {result.IsSuccess}"); + return input; } - private SearchResultItem ShowInteractivePromptAsync() + private SearchResult GetResultPrompt() { - var prompt = new TextPrompt(" <#>"); - - string input; - - do + var prompt = new TextPrompt("") { - // AConsole.Clear(); - // AConsole.Write(m_table); - input = AConsole.Prompt(prompt); - - if (!String.IsNullOrWhiteSpace(input)) - { - - var sri = GetResultFromName(input); - - if (sri != null) - { - // SearchClient.OpenResult(sri.Url); - - return sri; - } - } + ShowChoices = false, + ShowDefaultValue = false, + AllowEmpty = false, + Converter = s => { return s.Engine.Name; } + }; + prompt = prompt.AddChoices(m_results); - } while (input != "q"); + SearchResult input = default; + input = AConsole.Prompt(prompt); - return null; + return input; } - - private SearchResultItem GetResultFromName(string input) + private string GetCommandPrompt() { - var inputSplit = input.Split(' ', StringSplitOptions.TrimEntries); - var name = inputSplit[0]; + var prompt = new TextPrompt("") + { + ShowChoices = true, + ShowDefaultValue = true, + AllowEmpty = false, + }; - var res = m_results.FirstOrDefault( - sr => sr.Engine.Name.Contains(name, StringComparison.InvariantCultureIgnoreCase)); + prompt = prompt.AddChoices(ConsoleItems.s_commandChoices); - if (res != default && inputSplit.Length > 1 && Int32.TryParse(inputSplit[1], out var idx)) - { - var sri = res.Results[idx]; - return sri; - } + string input = null; - return null; + input = AConsole.Prompt(prompt); + + return input; } private Task WriteOutputFileAsync([CBN] object o) @@ -430,12 +383,10 @@ private Task WriteOutputFileAsync([CBN] object o) sw.WriteLine(String.Join(m_scs.OutputFileDelimiter, names)); - for (int i = 0; i < res.Length; i++) - { + for (int i = 0; i < res.Length; i++) { var sr = res[i]; - for (int j = 0; j < sr.Results.Count; j++) - { + for (int j = 0; j < sr.Results.Count; j++) { var sri = sr.Results[j]; var rg = new List(); @@ -468,10 +419,128 @@ private Task WriteOutputFileAsync([CBN] object o) return Task.CompletedTask; } + private Task ShowImageScanResultsAsync(SearchResultItem item) + { + Task run2; + /*var gr2 = new Grid(); + gr2.AddColumns(5); + gr2.AddRow(CreateResultItemRows(item, 0, Style.Plain)); + + // AConsole.Write(gr2); + + var tr = new Tree(gr2); + var ld = AConsole.Live(tr);*/ + + var table2 = CreateResultTable(); + table2.AddRow(CreateResultItemRows(item, 0, Style.Plain)); + var ld = AConsole.Live(table2); + + run2 = ld.StartAsync(async f => + { + if (m_results2.TryGetValue(item, out IList list)) { + Trace.WriteLine($"{item} cached"); + + var list2 = list.OfType(); + int i = 0; + + foreach (var ui in list2) { + table2.AddRow(CreateUniImageRow(ui, item, i++)); + } + } + else { + // var ok = await r.ScanAsync(); + Trace.WriteLine($"Scanning {item}"); + var resOk = await ImageScanner.ScanImagesAsync(item.Url); + + var buf = new List(); + + while (resOk.Count != 0) { + var t = await Task.WhenAny(resOk); + resOk.Remove(t); + + var r = await t; + + if (r == null) { + continue; + } + + if (r is UniImageUri ru) { + buf.Add(ru); + + // tr.AddNode(new Text(ru.ValueString, new Style(link: ru.Url))); + + table2.AddRow(CreateUniImageRow(ru, item, buf.Count)); + } + + f.Refresh(); + + } + + m_results2.TryAdd(item, buf); + + } + }); + + return run2; + } + + private async Task RunCompletionCommandAsync([CBN] object o) + { + Debug.WriteLine($"{nameof(RunCompletionCommandAsync)}"); + var command = Cli.Wrap(m_scs.Command); + + var cmdArgs = m_scs.CommandArguments; + var stdOutBuffer = new StringBuilder(); + var stdErrBuffer = new StringBuilder(); + + if (!String.IsNullOrWhiteSpace(cmdArgs)) { + command = command.WithArguments(cmdArgs); + } + + command = command.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdErrBuffer)) + .WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdOutBuffer)); + + var commandTask = command.ExecuteAsync(m_cts.Token); + + AConsole.WriteLine($"Process id: {commandTask.ProcessId}"); + + var result = await commandTask; + + AConsole.WriteLine($"Process successful: {result.IsSuccess}"); + } + #endregion #region + private static IRenderable[] CreateUniImageRow(UniImageUri ui, SearchResultItem sri, int idx) + { + return + [ + new Text($"{sri.Root.Engine.Name} {idx}", new Style(link: ui.Url)), + new Text(ui.Url), + new Text($"{0f}"), + new Text("-"), + new Text("-") + ]; + } + + private SearchResultItem ParseResultFromPrompt(string input) + { + var inputSplit = input.Split(' ', StringSplitOptions.TrimEntries); + var name = inputSplit[0]; + + var res = m_results.FirstOrDefault( + sr => sr.Engine.Name.Contains(name, StringComparison.InvariantCultureIgnoreCase)); + + if (res != default && inputSplit.Length > 1 && Int32.TryParse(inputSplit[1], out var idx)) { + var sri = res.Results[idx]; + return sri; + } + + return null; + } + private static STable CreateResultTable() { var col = new TableColumn[] @@ -506,8 +575,7 @@ private static IEnumerable CreateResultRows(SearchResult result) // Debug.WriteLine($"{lr} {lrr} {lrr2}"); - for (int i = 0; i < result.Results.Count; i++) - { + for (int i = 0; i < result.Results.Count; i++) { var res = result.Results[i]; yield return CreateResultItemRows(res, i, style); @@ -522,12 +590,10 @@ private static IRenderable[] CreateResultItemRows(SearchResultItem res, int i, S IRenderable url; var link = res.Url; - if (link != null) - { + if (link != null) { url = new Markup(link.ToString(), new Style(link: link)); } - else - { + else { url = new Text("-"); } @@ -581,8 +647,7 @@ private Grid CreateConfigGrid() ["Upload"] = Query.Upload }; - foreach (var o in kv) - { + foreach (var o in kv) { dt.AddRow(new Text(o.Key, ConsoleFormat.Sty_Grid1), new Text(o.Value.ToString())); } @@ -604,7 +669,7 @@ private void OnCancelKeyPress(object sender, ConsoleCancelEventArgs args) m_cts.Cancel(); args.Cancel = false; - Environment.Exit(EC_ERROR); + Environment.Exit(ConsoleItems.EC_ERROR); } public override ValidationResult Validate(CommandContext context, SearchCommandSettings settings) @@ -616,8 +681,7 @@ public override ValidationResult Validate(CommandContext context, SearchCommandS public void Dispose() { - foreach (var sr in m_results) - { + foreach (var sr in m_results) { sr.Dispose(); } diff --git a/SmartImage.Rdx/SearchCommandSettings.cs b/SmartImage.Rdx/SearchCommandSettings.cs index 948c3f52..873384d4 100644 --- a/SmartImage.Rdx/SearchCommandSettings.cs +++ b/SmartImage.Rdx/SearchCommandSettings.cs @@ -89,6 +89,15 @@ public sealed class SearchCommandSettings : CommandSettings [Description("Waits for input before terminating")] public bool? KeepOpen { get; internal set; } + [CommandOption("--flaresolverr")] + [DefaultValue(SearchConfig.FLARESOLVERR_DEFAULT)] + [Description("Use FlareSolverr")] + public bool FlareSolverr { get; internal set; } + + [CommandOption("--flaresolverr-api")] + [DefaultValue(SearchConfig.FLARE_SOLVERR_API_URL_DEFAULT)] + public string FlareSolverrApiUrl { get; internal set; } + // public bool? Silent { get; internal set; } //todo // public const string PROP_ARG_RESULTS = "$all_results"; diff --git a/SmartImage.Rdx/Shell/ConsoleItems.cs b/SmartImage.Rdx/Shell/ConsoleItems.cs new file mode 100644 index 00000000..bbb9fa49 --- /dev/null +++ b/SmartImage.Rdx/Shell/ConsoleItems.cs @@ -0,0 +1,17 @@ +// Author: Deci | Project: SmartImage.Rdx | Name: ConsoleItems.cs +// Date: 2024/11/05 @ 13:11:34 + +namespace SmartImage.Rdx.Shell; + +internal static class ConsoleItems +{ + + internal const int EC_ERROR = -1; + + internal const int EC_OK = 0; + + internal static readonly string[] s_commandChoices = ["open", "scan", "exit"]; + + internal const double COMPLETE = 100.0d; + +} \ No newline at end of file diff --git a/SmartImage.Rdx/SmartImage.Rdx.csproj b/SmartImage.Rdx/SmartImage.Rdx.csproj index a0521052..b7d08793 100644 --- a/SmartImage.Rdx/SmartImage.Rdx.csproj +++ b/SmartImage.Rdx/SmartImage.Rdx.csproj @@ -17,7 +17,8 @@ en-US;en - 1.0.6 + 1.0.7 + Icon.ico DEBUG;TRACE;JETBRAINS_ANNOTATIONS @@ -37,6 +38,10 @@ DEBUG;TRACE;JETBRAINS_ANNOTATIONS;TEST + + + +