@@ -99,7 +99,7 @@ public static bool IsDirect(string url, DirectImageType directType = DirectImage
9999 {
100100 return directType switch
101101 {
102- DirectImageType . Binary => MediaTypes . IsDirect ( url , MimeType . Image ) ,
102+ DirectImageType . Binary => IsImage ( url , 1 ) ,
103103 DirectImageType . Regex =>
104104 /*
105105 * https://github.com/PactInteractive/image-downloader
@@ -179,7 +179,23 @@ public static string Download(Uri direct, string path)
179179 return combine ;
180180 }
181181
182- public static bool IsImage ( string s , double d ) => Network . IsType ( s , "image" , ( long ) TimeSpan . FromSeconds ( d ) . TotalMilliseconds ) ;
182+ public static bool IsImage ( string s , double d )
183+ {
184+ if ( ! Network . IsUri ( s , out var u ) ) {
185+ return false ;
186+ }
187+
188+ var m = Network . GetMetaResponse ( u . ToString ( ) , ( long ) TimeSpan . FromSeconds ( d ) . TotalMilliseconds ) ;
189+
190+ if ( m == null ) {
191+ return false ;
192+ }
193+
194+ var a = m . ContentType . StartsWith ( "image" ) && m . ContentType != "image/svg+xml" ;
195+ var b = m . ContentLength >= 2500 ;
196+
197+ return a && b ;
198+ }
183199
184200 public static Image GetImage ( string s )
185201 {
@@ -214,7 +230,7 @@ public static List<string> FindDirectImages(string url, int count = 10, double p
214230 */
215231
216232 var images = new List < string > ( ) ;
217-
233+
218234
219235 string gallerydl = UtilitiesMap [ GALLERY_DL_EXE ] ;
220236
@@ -304,14 +320,28 @@ public static List<string> FindDirectImages(string url, int count = 10, double p
304320 Parallel . For ( 0 , flat . Count , options , ( i , s ) =>
305321 {
306322 string currentUrl = flat [ i ] ;
323+
307324
325+
326+ if ( s . IsStopped ) {
327+ return ;
328+ }
329+
308330 if ( ! IsImage ( currentUrl , pingTimeSec ) ) {
309331 return ;
310332 }
311333
312334 Debug . WriteLine ( $ "{ nameof ( FindDirectImages ) } : Adding { currentUrl } ") ;
313335
314336 imagesCopy . Add ( currentUrl ) ;
337+
338+ if ( imagesCopy . Count >= count )
339+ {
340+ s . Stop ( ) ;
341+ return ;
342+ }
343+
344+
315345 } ) ;
316346
317347
0 commit comments