Skip to content

Commit 070b0ef

Browse files
committed
Iqdb previews
1 parent 8d6232a commit 070b0ef

File tree

8 files changed

+74
-56
lines changed

8 files changed

+74
-56
lines changed

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

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ private SearchResultItem ParseResult(IHtmlCollection<IElement> tr, SearchResult
4343
var img = tr[1];
4444
var src = tr[2];
4545

46-
var img2 = img.Children[0].Children[0].Attributes["src"];
47-
var thumbnail = img2 != null ? Url.Combine(BaseUrl.Root, img2.Value) : null;
48-
var thumbnail1 = img.Children[0].Children[0].Attributes["alt"];
46+
var img2 = img.Children[0].Children[0].Children[0].Attributes["src"];
47+
var thumbnail = img2 != null ? Url.Combine(BaseUrl.Root, img2.Value) : null;
48+
var thumbnail1 = img.Children[0].Children[0].Attributes["alt"];
4949
var thumbnailAlt = thumbnail1?.Value;
5050

51-
string url = null;
51+
string url = null;
5252

5353
//img.ChildNodes[0].ChildNodes[0].TryGetAttribute("href")
5454

@@ -107,18 +107,20 @@ private SearchResultItem ParseResult(IHtmlCollection<IElement> tr, SearchResult
107107

108108
var result = new SearchResultItem(r)
109109
{
110-
Url = uri,
111-
Similarity = sim,
112-
Width = w,
113-
Height = h,
114-
Source = src.TextContent,
115-
Description = caption.TextContent,
116-
Thumbnail = thumbnail,
110+
Url = uri,
111+
Similarity = sim,
112+
Width = w,
113+
Height = h,
114+
Source = src.TextContent,
115+
Description = caption.TextContent,
116+
Thumbnail = thumbnail,
117117
ThumbnailTitle = thumbnailAlt
118118

119119
};
120120
result.Site ??= uri?.Host;
121121

122+
// r.Results.Add(result);
123+
122124
return result;
123125
}
124126

@@ -205,21 +207,27 @@ public override async Task<SearchResult> GetResultAsync(SearchQuery query, Cance
205207
}
206208

207209
var select = tables.Select(table => ((IHtmlElement) table)
208-
.QuerySelectorAll(Serialization.S_Iqdb_Table));
210+
.QuerySelectorAll(Serialization.S_Iqdb_Table))
211+
.ToArray();
212+
213+
for (int i = 1; i < select.Length; i++) {
214+
var sri = ParseResult(select[i], sr);
215+
sr.Results.Add(sri);
216+
}
209217

210-
var images = select.Select(x => ParseResult(x, sr)).ToList();
218+
// XPATH //body/div/div/table
211219

212220
// First is original image
213-
images.RemoveAt(0);
221+
// images.RemoveAt(0);
214222

215223
// var best = images[0];
216224
// sr.PrimaryResult.UpdateFrom(best);
217-
sr.Results.AddRange(images);
225+
// sr.Results.AddRange(images);
218226

219227
/*sr.Results.Quality = sr.PrimaryResult.Similarity switch
220228
{
221-
>= 75 => ResultQuality.High,
222-
_ or null => ResultQuality.NA,
229+
>= 75 => ResultQuality.High,
230+
_ or null => ResultQuality.NA,
223231
};*/
224232

225233
ret:

SmartImage.Lib 3/SearchConfig.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public string EhPassword
103103
OnPropertyChanged();
104104
}
105105
}
106+
107+
/*
106108
/// <summary>
107109
/// <see cref="HydrusClient.EndpointUrl"/>
108110
/// </summary>
@@ -128,6 +130,8 @@ public string HydrusKey
128130
OnPropertyChanged();
129131
}
130132
}
133+
*/
134+
131135
public bool OpenRaw
132136
{
133137
get { return Configuration.ReadSetting(nameof(OpenRaw), false); }
@@ -221,8 +225,8 @@ public DataTable ToTable()
221225
table.Rows.Add(Resources.S_Clipboard, Clipboard);
222226
table.Rows.Add(Resources.S_AutoSearch, AutoSearch);
223227
table.Rows.Add(Resources.S_SauceNaoKey, SauceNaoKey);
224-
table.Rows.Add(Resources.S_HydrusEndpoint, HydrusEndpoint);
225-
table.Rows.Add(Resources.S_HydrusKey, HydrusKey);
228+
/*table.Rows.Add(Resources.S_HydrusEndpoint, HydrusEndpoint);
229+
table.Rows.Add(Resources.S_HydrusKey, HydrusKey);*/
226230

227231
// table.Rows.Add("Path", new FileInfo(Configuration.FilePath).Name);
228232

SmartImage.UI/ControlsHelper.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,26 @@ public static void HandleEnum<T>(this ListBox lb, T src) where T : struct, Enum
8484
public static SearchEngineOptions HandleEnum(this ListBox lb, SelectionChangedEventArgs e,
8585
SearchEngineOptions orig)
8686
{
87-
var rg = lb.ItemsSource.OfType<SearchEngineOptions>().ToArray();
87+
// var rg = lb.ItemsSource.OfType<SearchEngineOptions>().ToArray();
8888

8989
var ai = e.AddedItems.OfType<SearchEngineOptions>()
90-
.Aggregate(default(SearchEngineOptions), (n, l) => n | l);
90+
.Aggregate(default(SearchEngineOptions), Func);
9191

9292
var ri = e.RemovedItems.OfType<SearchEngineOptions>()
93-
.Aggregate(default(SearchEngineOptions), (n, l) => n | l);
93+
.Aggregate(default(SearchEngineOptions), Func);
9494

9595
var si = lb.SelectedItems.OfType<SearchEngineOptions>().ToArray();
9696

97-
var siv = si.Aggregate(default(SearchEngineOptions), (n, l) => n | l);
97+
var siv = si.Aggregate(default(SearchEngineOptions), Func);
9898

9999
orig &= siv;
100100
orig &= (~ri);
101101
orig |= ai;
102102

103103
return orig;
104104

105+
static SearchEngineOptions Func(SearchEngineOptions n, SearchEngineOptions l)
106+
=> n | l;
105107
}
106108

107109
public static string[] GetFilesFromDrop(this DragEventArgs e)

SmartImage.UI/HydrusWindow.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public HydrusWindow(SharedInfo s)
3434

3535
private void Btn_1_OnClick(object sender, RoutedEventArgs e)
3636
{
37-
Tb_Info.Dispatcher.InvokeAsync(async () =>
37+
/*Tb_Info.Dispatcher.InvokeAsync(async () =>
3838
{
3939
Shared.Query.Uni.Stream.TrySeek();
4040
var data = SHA256.HashData(Shared.Query.Uni.Stream);
@@ -47,7 +47,7 @@ private void Btn_1_OnClick(object sender, RoutedEventArgs e)
4747
imageSource.EndInit();
4848
imageSource.Freeze();
4949
Img_Preview.Source = imageSource;
50-
});
50+
});*/
5151
e.Handled = true;
5252
}
5353
}

SmartImage.UI/MainWindow.Handlers.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,15 @@ private void Lv_Results_SelectionChanged(object sender, SelectionChangedEventArg
308308
CheckMedia();
309309
}
310310
else {
311-
UpdatePreview(m_image);
311+
UpdatePreview();
312312
if (ri.Result.Metadata is TraceMoeEngine.TraceMoeDoc doc) {
313313

314314
Me_Preview.ScrubbingEnabled = false;
315315
Me_Preview.UnloadedBehavior = MediaState.Close;
316316
Me_Preview.LoadedBehavior = MediaState.Manual;
317317
Me_Preview.Source = new Uri(doc.video, UriKind.Absolute);
318318
Me_Preview.Play();
319-
ShowMedia = true;
319+
ShowMedia = true;
320320
}
321321
else {
322322
CheckMedia();
@@ -339,6 +339,9 @@ void CheckMedia()
339339
Me_Preview.Source = null;
340340
ShowMedia = false;
341341
}
342+
else {
343+
344+
}
342345
}
343346
}
344347

@@ -402,10 +405,12 @@ private void Lv_Results_KeyDown(object sender, KeyEventArgs e)
402405
case Key.R when ctrl && alt:
403406
Dispatcher.InvokeAsync(() => RetryEngineAsync(CurrentResultItem));
404407
break;
408+
/*
405409
case Key.H when ctrl:
406410
var w = new HydrusWindow(Shared);
407411
w.Show();
408412
break;
413+
*/
409414

410415
}
411416

SmartImage.UI/MainWindow.xaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<MenuItem Header="Retry" Click="RetryItem_Click" />
6262
<MenuItem Header="Enqueue" Click="EnqueueItem_Click" IsEnabled="{Binding CanDownload}" />
6363
</ContextMenu>
64-
64+
6565
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
6666
<controls:InvertableBooleanToVisibilityConverter x:Key="BooleanVisConverter"/>
6767

@@ -435,7 +435,7 @@
435435
<ProgressBar x:Name="Pb_Status" HorizontalAlignment="Left" Height="10" Margin="4,54,0,0"
436436
VerticalAlignment="Top" Width="100" Minimum="0" Maximum="100" Grid.Row="1" />
437437

438-
<ListView x:Name="Lv_Results" Margin="0,70,0,0"
438+
<ListView x:Name="Lv_Results" Margin="0,85,0,0"
439439
MouseDoubleClick="Lv_Results_MouseDoubleClick"
440440
Foreground="White"
441441
IsSynchronizedWithCurrentItem="True"
@@ -582,6 +582,7 @@
582582
TextChanged="Tb_Search_TextChanged" Grid.ColumnSpan="2" />
583583
<ComboBox x:Name="Cb_SearchFields" HorizontalAlignment="Right" Margin="0,17,499,0" Grid.Row="1"
584584
VerticalAlignment="Top" Width="148" Grid.ColumnSpan="2" />
585+
<TextBlock x:Name="Tb_Preview" Grid.Column="1" HorizontalAlignment="Left" Margin="460,65,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" TextDecorations="Underline" Foreground="White"/>
585586
</Grid>
586587
</TabItem>
587588
<TabItem x:Name="Ti_Config" HorizontalAlignment="Center" Height="20" Header="Config"
@@ -641,17 +642,18 @@
641642
VerticalAlignment="Top" Foreground="White" />
642643
<Label x:Name="Lbl_UploadEngines" Content="Upload Engine" HorizontalAlignment="Left"
643644
Margin="600,3,0,0" VerticalAlignment="Top" Foreground="White" FontWeight="Bold" />
644-
<TextBox x:Name="Tb_HyEndpoint" HorizontalAlignment="Left" Margin="527,297,0,0" TextWrapping="Wrap"
645+
646+
<!--<TextBox x:Name="Tb_HyEndpoint" HorizontalAlignment="Left" Margin="527,297,0,0" TextWrapping="Wrap"
645647
VerticalAlignment="Top" Width="120"
646-
Text="{Binding Config.HydrusEndpoint, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
648+
Text="{Binding Config.HydrusEndpoint, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" d:IsHidden="True" />
647649
<TextBox x:Name="Tb_HyKey" HorizontalAlignment="Left" Margin="527,326,0,0" TextWrapping="Wrap"
648650
VerticalAlignment="Top" Width="120"
649-
Text="{Binding Config.HydrusKey, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
651+
Text="{Binding Config.HydrusKey, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" d:IsHidden="True" />
650652
<Label x:Name="Lb_HyEndpoint" Content="Hydrus Endpoint" HorizontalAlignment="Left"
651653
Margin="424,293,0,0"
652-
VerticalAlignment="Top" Foreground="White" />
654+
VerticalAlignment="Top" Foreground="White" d:IsHidden="True" />
653655
<Label x:Name="Lb_HyKey" Content="Hydrus Key" HorizontalAlignment="Left" Margin="424,322,0,0"
654-
VerticalAlignment="Top" Foreground="White" />
656+
VerticalAlignment="Top" Foreground="White" d:IsHidden="True" />-->
655657

656658
</Grid>
657659
</TabItem>

SmartImage.UI/MainWindow.xaml.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static MainWindow() { }
7171

7272
public MainWindow()
7373
{
74-
// Client = new SearchClient(new SearchConfig());
74+
Client = new SearchClient(new SearchConfig());
7575
Shared = new SharedInfo();
7676
m_queries = new ConcurrentDictionary<string, SearchQuery>();
7777

@@ -170,9 +170,11 @@ public MainWindow()
170170

171171
#region
172172

173-
public SearchClient Client => Shared.Client;
173+
public SearchClient Client { get; }
174174

175-
public SearchConfig Config => Shared.Config;
175+
public SearchConfig Config => Client.Config;
176+
177+
public SearchQuery Query { get; internal set; }
176178

177179
public ObservableCollection<ResultItem> Results { get; private set; }
178180

@@ -213,12 +215,6 @@ public bool InPath
213215

214216
#region Queue/Query
215217

216-
public SearchQuery Query
217-
{
218-
get => Shared.Query;
219-
internal set => Shared.Query = value;
220-
}
221-
222218
private string m_currentQueueItem;
223219

224220
public string CurrentQueueItem
@@ -419,7 +415,7 @@ void UpdateImage()
419415

420416
// Img_Preview.Source = m_image;
421417

422-
UpdatePreview(m_image);
418+
UpdatePreview();
423419
}
424420
}
425421

@@ -1036,6 +1032,7 @@ private void ChangeStatus2(ResultItem ri)
10361032
}
10371033
else {
10381034
Tb_Status2.Text = $"{ri.Name}";
1035+
10391036
}
10401037
}
10411038

@@ -1101,13 +1098,21 @@ private void UpdatePreview(ResultItem ri)
11011098
Img_Preview.Source = ri.Image;
11021099
// Debug.WriteLine($"updated image {ri.Image}");
11031100
// PreviewChanged?.Invoke(ri);
1101+
Tb_Preview.Text = $"Preview: {ri.Name}";
1102+
11041103
}
11051104
else {
1106-
Img_Preview.Source = m_image;
1105+
UpdatePreview();
11071106
}
11081107
});
11091108
}
11101109

1110+
private void UpdatePreview()
1111+
{
1112+
UpdatePreview(m_image);
1113+
1114+
}
1115+
11111116
private void UpdatePreview(ImageSource x)
11121117
{
11131118
Application.Current.Dispatcher.Invoke(() =>

SmartImage.UI/Model/SharedInfo.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@ public class SharedInfo : INotifyPropertyChanged
1414
{
1515
public SharedInfo()
1616
{
17-
Client = new SearchClient(new SearchConfig());
17+
// Client = new SearchClient(new SearchConfig());
1818

19-
m_hydrus = new HydrusClient(Config.HydrusEndpoint, Config.HydrusKey);
19+
m_hydrus = new HydrusClient();
2020
}
2121

2222
public readonly HydrusClient m_hydrus;
23-
24-
public SearchClient Client { get; }
25-
26-
public SearchConfig Config => Client.Config;
2723

2824
private string _hash;
2925

@@ -38,11 +34,7 @@ public string Hash
3834
}
3935
}
4036
}
41-
public SearchQuery Query
42-
{
43-
get;
44-
internal set;
45-
}
37+
4638
public event PropertyChangedEventHandler? PropertyChanged;
4739

4840
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)

0 commit comments

Comments
 (0)