Skip to content

Commit a76e23a

Browse files
committed
Image scanning overhaul
1 parent f09b02e commit a76e23a

File tree

5 files changed

+148
-158
lines changed

5 files changed

+148
-158
lines changed

SmartImage.Lib/SearchClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public ImageResult[] FindDirectResults()
216216

217217
best.AsParallel().ForAll(delegate(ImageResult f)
218218
{
219-
f.FindDirectImagesAsync();
219+
f.FindDirectImages();
220220
});
221221

222222
//foreach (var result in best) {

SmartImage.Lib/Searching/ImageResult.cs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -186,31 +186,33 @@ public void UpdateFrom(ImageResult result)
186186
Date = result.Date;
187187

188188

189-
ReadDirectImageData();
189+
UpdateImageData();
190190

191191
}
192192

193-
public async void FindDirectImagesAsync()
193+
public Image? Image { get; set; }
194+
195+
public void FindDirectImages()
194196
{
195197
if (Url is not null && Direct == null) {
196198

197199
if (ImageHelper.IsDirect(Url.ToString())) {
198200
Direct = Url;
199-
201+
200202
}
201203
else {
202204
try {
203205

204-
string[]? directImages = await ImageHelper.FindDirectImagesAsync(Url.ToString());
206+
//string[]? directImages = await ImageHelper.FindDirectImagesAsync(Url.ToString());
207+
var directImages = ImageHelper.FindDirectImages(Url.ToString(), out var im);
205208

206-
if (directImages is { }) {
207-
string? images = directImages.FirstOrDefault();
209+
Image = im.First();
210+
string? images = directImages?.FirstOrDefault();
208211

209-
if (images is { }) {
210-
var uri = new Uri(images);
211-
Direct = uri;
212-
Debug.WriteLine($"{Url} -> {Direct}");
213-
}
212+
if (images != null) {
213+
var uri = new Uri(images);
214+
Direct = uri;
215+
Debug.WriteLine($"{Url} -> {Direct}");
214216
}
215217
}
216218
catch (Exception e) {
@@ -221,7 +223,7 @@ public async void FindDirectImagesAsync()
221223

222224

223225
try {
224-
ReadDirectImageData();
226+
UpdateImageData();
225227
}
226228
catch (Exception) {
227229
// ignored
@@ -230,20 +232,16 @@ public async void FindDirectImagesAsync()
230232
}
231233
}
232234

233-
private void ReadDirectImageData()
235+
private void UpdateImageData()
234236
{
235-
if (Direct is { }) {
236-
var stream = WebUtilities.GetStream(Direct.ToString());
237-
var image = Image.FromStream(stream);
238-
239-
240-
Width = image.Width;
241-
Height = image.Height;
237+
if (Image is { }) {
242238

243-
byte[] rg = stream.ToByteArray();
244239

245-
OtherMetadata.Add("Size", MathHelper.ConvertToUnit(rg.Length));
246-
OtherMetadata.Add("Mime", MediaTypes.ResolveFromData(stream));
240+
Width = Image.Width;
241+
Height = Image.Height;
242+
//
243+
// OtherMetadata.Add("Size", MathHelper.ConvertToUnit(rg.Length));
244+
// OtherMetadata.Add("Mime", MediaTypes.ResolveFromData(rg));
247245
}
248246
}
249247

0 commit comments

Comments
 (0)