Skip to content

Commit cca59f2

Browse files
committed
*
1 parent db93662 commit cca59f2

File tree

7 files changed

+48
-27
lines changed

7 files changed

+48
-27
lines changed

SmartImage.Lib 3/Engines/BaseSearchEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public abstract class BaseSearchEngine : IDisposable
3535

3636
public bool IsAdvanced { get; protected set; }
3737

38-
public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(20);
38+
public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(15);
3939

4040
public string? EndpointUrl { get; }
4141

SmartImage.Lib 3/Engines/Impl/Search/FluffleEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public SearchResultItem Convert(SearchResult sr, out SearchResultItem[] children
152152
{
153153
Artist = Credits.FirstOrDefault()?.Name,
154154
Url = Location,
155-
Similarity = Score * 100.0d,
155+
Similarity = Math.Round(Score * 100.0d, 2),
156156
Metadata = this,
157157
Thumbnail = Thumbnail?.Location,
158158
Site = Platform

SmartImage.Lib 3/SearchClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public List<Task<SearchResult>> GetSearchTasks(SearchQuery query, TaskScheduler
279279
{
280280

281281
// Debug.Assert(r.IsCompleted);
282-
Debug.WriteLine($"{r.Id} :: {r.Status}");
282+
// Debug.WriteLine($"{r.Id} :: {r.Status}");
283283
ProcessResult(r.Result);
284284
return r.Result;
285285

SmartImage.Rdx/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace SmartImage.Rdx;
1717
* dotnet run -c Test --project SmartImage.Rdx -- "/home/neorenegade/0c4c80957134d4304538c27499d84dbe.jpeg" -e All -p Auto
1818
* ./SmartImage.Rdx/bin/Release/net8.0/publish/linux-x64/SmartImage "/home/neorenegade/0c4c80957134d4304538c27499d84dbe.jpeg"
1919
* dotnet run --project SmartImage.Rdx -- --help
20+
* dotnet run --project SmartImage.Rdx/ "C:\Users\Deci\Pictures\Epic anime\Kallen_FINAL_1-3.png" --search-engines All --output-format "Delimited" --output-file "output.csv" --read-cookies
2021
*/
2122

2223
public static class Program

SmartImage.Rdx/SearchCommand.cs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ internal sealed class SearchCommand : AsyncCommand<SearchCommandSettings>, IDisp
6565
public SearchCommand()
6666
{
6767
Config = new SearchConfig();
68+
6869
// Config = (SearchConfig) cfg;
6970
Client = new SearchClient(Config);
7071

@@ -78,7 +79,7 @@ public SearchCommand()
7879
Query = SearchQuery.Null;
7980
}
8081

81-
#region
82+
#region
8283

8384
private async Task SetupSearchAsync(ProgressContext ctx)
8485
{
@@ -96,8 +97,6 @@ private async Task SetupSearchAsync(ProgressContext ctx)
9697
if (url == null) {
9798
throw new SmartImageException(); //todo
9899
}
99-
100-
AConsole.WriteLine($"{url}");
101100

102101
p.Increment(COMPLETE / 2);
103102
}
@@ -141,7 +140,8 @@ private async Task RunSearchAsync(ProgressContext c)
141140
}
142141

143142
await search;
144-
Debug.WriteLine($"{nameof(RunSearchAsync)} complete");
143+
144+
// Debug.WriteLine($"{nameof(RunSearchAsync)} complete");
145145

146146
return;
147147

@@ -183,7 +183,8 @@ public override async Task<int> ExecuteAsync(CommandContext context, SearchComma
183183
break;
184184

185185
case OutputFileFormat.Delimited:
186-
run = run.ContinueWith(WriteOutputFileAsync, m_cts.Token, TaskContinuationOptions.OnlyOnRanToCompletion,
186+
run = run.ContinueWith(WriteOutputFileAsync, m_cts.Token,
187+
TaskContinuationOptions.OnlyOnRanToCompletion,
187188
TaskScheduler.Default);
188189
break;
189190

@@ -193,12 +194,7 @@ public override async Task<int> ExecuteAsync(CommandContext context, SearchComma
193194

194195
}
195196

196-
try {
197-
await run;
198-
}
199-
catch (TaskCanceledException e) {
200-
Debugger.Break();
201-
}
197+
await run;
202198

203199
return EC_OK;
204200
}
@@ -216,6 +212,18 @@ private async Task WriteOutputFileAsync([CBN] object o)
216212
var res = m_results.ToArray();
217213
var fields = m_scs.OutputFields;
218214

215+
bool fName = fields.HasFlag(OutputFields.Name);
216+
var fUrl = fields.HasFlag(OutputFields.Url);
217+
var fSim = fields.HasFlag(OutputFields.Similarity);
218+
var fArtist = fields.HasFlag(OutputFields.Artist);
219+
var fSite = fields.HasFlag(OutputFields.Site);
220+
221+
var names = Enum.GetValues<OutputFields>()
222+
.Where(f => fields.HasFlag(f) && !f.Equals(default(OutputFields)))
223+
.Select(f => Enum.GetName(f));
224+
225+
sw.WriteLine(String.Join(m_scs.OutputFileDelimiter, names));
226+
219227
for (int i = 0; i < res.Length; i++) {
220228
var sr = res[i];
221229

@@ -224,18 +232,26 @@ private async Task WriteOutputFileAsync([CBN] object o)
224232

225233
var rg = new List<string>();
226234

227-
if (fields.HasFlag(OutputFields.Name)) {
235+
if (fName) {
228236
rg.Add($"{sr.Engine.Name} #{j + 1}");
229237
}
230238

231-
if (fields.HasFlag(OutputFields.Url)) {
239+
if (fUrl) {
232240
rg.Add(sri.Url);
233241
}
234242

235-
if (fields.HasFlag(OutputFields.Similarity)) {
243+
if (fSim) {
236244
rg.Add($"{sri.Similarity}");
237245
}
238246

247+
if (fArtist) {
248+
rg.Add($"{sri.Artist}");
249+
}
250+
251+
if (fSite) {
252+
rg.Add($"{sri.Site}");
253+
}
254+
239255
// string[] items = [$"{sr.Engine.Name} #{j + 1}", sri.Url?.ToString()];
240256
sw.WriteLine(String.Join(m_scs.OutputFileDelimiter, rg));
241257
}
@@ -317,7 +333,8 @@ private Grid CreateInfoGrid()
317333
[R1.S_AutoSearch] = Config.AutoSearch,
318334
[R1.S_ReadCookies] = Config.ReadCookies,
319335

320-
["Input"] = Query
336+
["Input"] = Query,
337+
["Upload"] = Query.Upload
321338
};
322339

323340
foreach (var o in kv) {

SmartImage.Rdx/SearchCommandSettings.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// $File.CreatedYear-$File.CreatedMonth-26 @ 0:56
33

44
using System.ComponentModel;
5-
using System.ComponentModel.DataAnnotations;
6-
using System.Globalization;
75
using SmartImage.Lib;
86
using SmartImage.Lib.Engines;
97
using SmartImage.Rdx.Shell;
@@ -56,10 +54,13 @@ internal sealed class SearchCommandSettings : CommandSettings
5654
public string? OutputFileDelimiter { get; internal set; }
5755

5856
[CommandOption("--output-fields")]
59-
[DefaultValue(OutputFields.Default)]
57+
[DefaultValue(OUTPUT_FIELDS_DEFAULT)]
6058
[Description("Output fields")]
6159
public OutputFields OutputFields { get; internal set; }
6260

61+
public const OutputFields OUTPUT_FIELDS_DEFAULT =
62+
OutputFields.Name | OutputFields.Similarity | OutputFields.Url;
63+
6364
#endregion
6465

6566
#region
@@ -79,15 +80,15 @@ public override ValidationResult Validate()
7980
var result = base.Validate();
8081

8182
if (!SearchQuery.IsValidSourceType(Query)) {
82-
return ValidationResult.Error($"Invalid query");
83+
return ValidationResult.Error("Invalid query");
8384
}
8485

8586
var hasOutputFile = !String.IsNullOrWhiteSpace(OutputFile);
8687
var hasOutputFileDelim = !String.IsNullOrEmpty(OutputFileDelimiter);
8788
bool isOutputFormatDelim = OutputFileFormat == OutputFileFormat.Delimited;
8889

8990
if (!isOutputFormatDelim && hasOutputFile) {
90-
OutputFileFormat = OutputFileFormat.Delimited;
91+
OutputFileFormat = OutputFileFormat.Delimited;
9192
isOutputFormatDelim = true;
9293
}
9394

@@ -106,5 +107,4 @@ public override ValidationResult Validate()
106107
return result;
107108
}
108109

109-
}
110-
110+
}

SmartImage.Rdx/Shell/CliFormat.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ namespace SmartImage.Rdx.Shell;
1515
[Flags]
1616
public enum OutputFields
1717
{
18-
None = 0,
18+
19+
None = 0,
1920

2021
Name = 1 << 0,
2122
Url = 1 << 1,
2223
Similarity = 1 << 2,
24+
Artist = 1 << 3,
25+
Site = 1 << 4,
2326

24-
Default = Name | Url | Similarity
27+
// Default = Name | Url | Similarity
2528

2629
}
2730

0 commit comments

Comments
 (0)