Skip to content

Commit 3cc3375

Browse files
committed
Organize namespaces
1 parent fdea60d commit 3cc3375

File tree

11 files changed

+522
-536
lines changed

11 files changed

+522
-536
lines changed

SmartImage.Lib/Engines/Search/Base/WebClientSearchEngine.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using AngleSharp.Html.Parser;
1+
using System.Diagnostics;
2+
using AngleSharp.Html.Parser;
23
using SmartImage.Lib.Searching;
34

45
namespace SmartImage.Lib.Engines.Search.Base;
@@ -16,10 +17,11 @@ protected WebClientSearchEngine(string baseUrl) : base(baseUrl) { }
1617

1718
protected override object GetProcessingObject(SearchResult sr) => ParseContent(sr.Origin);
1819

19-
protected virtual object ParseContent(SearchResultOrigin s)
20+
21+
protected virtual object ParseContent(SearchResultOrigin origin)
2022
{
2123
var parser = new HtmlParser();
22-
var readStringTask = s.Response.Content.ReadAsStringAsync();
24+
var readStringTask = origin.Response.Content.ReadAsStringAsync();
2325
readStringTask.Wait();
2426
var content = readStringTask.Result;
2527
var document = parser.ParseDocument(content);

SmartImage.Lib/Engines/Search/TraceMoeEngine.cs

Lines changed: 27 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -66,46 +66,19 @@ protected override SearchResult Process(object obj, SearchResult r)
6666
{
6767
Error = (sender, args) =>
6868
{
69-
7069
if (object.Equals(args.ErrorContext.Member, nameof(TraceMoeDoc.episode)) /*&&
7170
args.ErrorContext.OriginalObject.GetType() == typeof(TraceMoeRootObject)*/) {
7271
args.ErrorContext.Handled = true;
73-
7472
}
7573

7674
Debug.WriteLine($"{args.ErrorContext}");
7775
}
7876
};
7977

80-
/*var tm2t = request.GetJsonAsync();
81-
tm2t.Wait();
82-
var tm2 = tm2t.Result;
83-
84-
dynamic result = tm2.result;
85-
Debug.WriteLine($"{result}");
86-
tm = new() { result = new(), error = tm2.error, frameCount = tm2.frameCount };
87-
88-
for (int i = 0; i < result.Count; i++) {
89-
Debug.WriteLine($"{result[i]}");
90-
91-
var d = result[i];
92-
93-
var doc = new TraceMoeDoc()
94-
{
95-
episode = d.episode,
96-
from = d.from,
97-
to = d.to,
98-
filename = d.filename, anilist = d.anilist
99-
};
100-
101-
tm.result.Add(doc);
102-
}*/
103-
104-
10578
tm = JsonConvert.DeserializeObject<TraceMoeRootObject>(json, settings);
10679
}
10780
catch (Exception e) {
108-
Debug.WriteLine($">>>>{e.Message}");
81+
Debug.WriteLine($"{Name}: {nameof(Process)}: {e.Message}");
10982

11083
goto ret;
11184
}
@@ -149,28 +122,18 @@ protected override SearchResult Process(object obj, SearchResult r)
149122
return r;
150123
}
151124

152-
private IEnumerable<ImageResult> ConvertResults(TraceMoeRootObject obj, SearchResult r)
125+
private IEnumerable<ImageResult> ConvertResults(TraceMoeRootObject obj, SearchResult sr)
153126
{
154-
var docs = obj.result;
155-
var results = new ImageResult[docs.Count];
127+
var results = obj.result;
128+
var imageResults = new ImageResult[results.Count];
156129

157-
for (int i = 0; i < results.Length; i++) {
158-
var doc = docs[i];
130+
for (int i = 0; i < imageResults.Length; i++) {
131+
var doc = results[i];
159132
float sim = MathF.Round((float) (doc.similarity * 100.0f), 2);
160133

161-
var episode = doc.episode;
162-
163-
string epStr = episode.ToString();
134+
string epStr = GetEpisodeString(doc);
164135

165-
if (episode is string) {
166-
epStr = episode as string;
167-
}
168-
else if (episode is IEnumerable enumerable) {
169-
var ls = enumerable.CopyToList().Select(x => Int64.Parse(x.ToString() ?? String.Empty));
170-
epStr = ls.QuickJoin();
171-
}
172-
173-
var result = new ImageResult(r)
136+
var result = new ImageResult(sr)
174137
{
175138
Similarity = sim,
176139
Description = $"Episode #{epStr} @ {TimeSpan.FromSeconds(doc.from)}"
@@ -192,10 +155,26 @@ private IEnumerable<ImageResult> ConvertResults(TraceMoeRootObject obj, SearchRe
192155
$"< {FILTER_THRESHOLD / 100:P})");
193156
}
194157

195-
results[i] = result;
158+
imageResults[i] = result;
196159
}
197160

198-
return results;
161+
return imageResults;
162+
163+
static string GetEpisodeString(TraceMoeDoc doc)
164+
{
165+
object episode = doc.episode;
166+
167+
string epStr = episode is string s ? s : episode.ToString();
168+
169+
if (episode is IEnumerable e) {
170+
var epList = e.CopyToList()
171+
.Select(x => Int64.Parse(x.ToString() ?? String.Empty));
172+
173+
epStr = epList.QuickJoin();
174+
}
175+
176+
return epStr;
177+
}
199178
}
200179

201180
/// <summary>
@@ -223,8 +202,7 @@ private class TraceMoeDoc
223202
public string filename { get; set; }
224203

225204

226-
/// <remarks>Episode field may contain multiple possible results delimited by <c>|</c></remarks>
227-
// [JsonIgnore]
205+
/// <remarks>Episode may be a JSON array (edge case) or a normal integer</remarks>
228206
public object episode { get; set; }
229207

230208
public double similarity { get; set; }

SmartImage/App/AppToast.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Kantan.Net;
44
using Microsoft.Toolkit.Uwp.Notifications;
55
using SmartImage.Lib;
6+
using SmartImage.Lib.Searching;
67
using SmartImage.Lib.Utilities;
78

89
// ReSharper disable PossibleNullReferenceException
@@ -34,9 +35,12 @@ internal static void ShowToast(object sender, SearchCompletedEventArgs args)
3435
}
3536
else if (Program.Client.Results.Any()) {
3637
var result = Program.Client.Results.First();
37-
url = result.PrimaryResult.Url.ToString();
3838

39-
builder.AddText($"Engine: {result.Engine}");
39+
url = result.PrimaryResult.Url.ToString();
40+
/*var rr = Program.Client.Results.Where(x => x.PrimaryResult is { Url: { } });
41+
var first = rr.First();
42+
url = first.PrimaryResult?.Url?.ToString() ?? first.RawUri.ToString();*/
43+
builder.AddText($"Engine: {result.Engine.Name}");
4044
}
4145

4246
button.SetContent("Open")

SmartImage/Cli/CliArguments.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using Kantan.Utilities;
2+
using SmartImage.Lib.Searching;
3+
4+
namespace SmartImage.Cli;
5+
6+
internal static class CliArguments
7+
{
8+
/// <summary>
9+
/// Command line argument handler
10+
/// </summary>
11+
internal static readonly CliHandler ArgumentHandler = new()
12+
{
13+
Parameters =
14+
{
15+
new()
16+
{
17+
ArgumentCount = 1,
18+
ParameterId = "-se",
19+
Function = strings =>
20+
{
21+
Program.Config.SearchEngines = Enum.Parse<SearchEngineOptions>(strings[0]);
22+
return null;
23+
}
24+
},
25+
new()
26+
{
27+
ArgumentCount = 1,
28+
ParameterId = "-pe",
29+
Function = strings =>
30+
{
31+
Program.Config.PriorityEngines = Enum.Parse<SearchEngineOptions>(strings[0]);
32+
return null;
33+
}
34+
},
35+
new()
36+
{
37+
ArgumentCount = 0,
38+
ParameterId = "-f",
39+
Function = delegate
40+
{
41+
Program.Config.Filtering = true;
42+
return null;
43+
}
44+
},
45+
new()
46+
{
47+
ArgumentCount = 0,
48+
ParameterId = "-output_only",
49+
Function = delegate
50+
{
51+
Program.Config.OutputOnly = true;
52+
return null;
53+
}
54+
}
55+
},
56+
Default = new()
57+
{
58+
ArgumentCount = 1,
59+
ParameterId = null,
60+
Function = strings =>
61+
{
62+
Program.Config.Query = strings[0];
63+
return null;
64+
}
65+
}
66+
};
67+
}

SmartImage/Program.UI.Elements.cs

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)