@@ -118,11 +118,6 @@ public async ValueTask ApplyAsync(SearchConfig cfg)
118118 */
119119 public async Task < bool > LoginAsync ( bool useEx = true )
120120 {
121- /*
122- if (IsLoggedIn) {
123- return false;
124- }
125- */
126121
127122 var b = await CookiesManager . LoadCookiesAsync ( ) ;
128123
@@ -139,43 +134,10 @@ public async Task<bool> LoginAsync(bool useEx = true)
139134 return x . Host . Contains ( HOST_EX ) ;
140135 } ) ;
141136
142- /*var fcc = CookiesManager.Cookies.Where(x =>
143- {
144- if (!useEx) {
145- return x.Domain.Contains(HOST_EH);
146- }
147-
148- return x.Domain.Contains(HOST_EX);
149- });*/
150-
151- /*var content = new MultipartFormDataContent()
152- {
153- { new StringContent("1"), "CookieDate" },
154- { new StringContent("d"), "b" },
155- { new StringContent("1-6"), "bt" },
156- { new StringContent(Username), "UserName" },
157- { new StringContent(Password), "PassWord" },
158- { new StringContent("Login!"), "ipb_login_submit" }
159- };
160-
161- var response = await EHentaiIndex
162- .SetQueryParams(new
163- {
164- act = "Login",
165- CODE = 01
166- }).WithHeaders(new
167- {
168- User_Agent = HttpUtilities.UserAgent
169- })
170- .WithCookies(out var cj)
171- .PostAsync(content);*/
172-
173137 foreach ( var cookie in fcc ) {
174138 m_cookies . Add ( cookie . AsCookie ( ) ) ;
175139 }
176140
177- // foreach (var fc in fcc) { }
178-
179141 var res2 = await GetSessionAsync ( useEx ) ;
180142
181143 /*var res2 = await EHentaiBase.WithCookies(m_clientHandler.CookieContainer)
@@ -185,96 +147,47 @@ public async Task<bool> LoginAsync(bool useEx = true)
185147 })
186148 .WithAutoRedirect(true)
187149 .GetAsync();*/
150+
188151 return IsLoggedIn = res2 . ResponseMessage . IsSuccessStatusCode ;
189152 }
190153
191154 public event PropertyChangedEventHandler PropertyChanged ;
192155
193- /*protected async Task<IDocument> GetDocumentAsync2(SearchResult sr, SearchQuery query,
194- CancellationToken token = default)
195- {
196-
197- const string name_default = "a.jpg";
198-
199- string name;
200-
201- string t = null;
202-
203- if (query.HasFile) {
204- t = query.FilePath;
205- name = Path.GetFileName(t);
206-
207- /*if (Path.GetFileName(t) != name) {
208- // Debugger.Break();
209- }#1#
210- }
211- else {
212- name = name_default;
213- var ok = query.TryGetFile(name);
214-
215- if (ok) {
216- t = query.FilePath;
217- }
218- else {
219- Debugger.Break();
220- }
221- }
222-
223- var req = new HttpRequestMessage(HttpMethod.Post, LookupUrl)
224- {
225- Headers =
226- {
227- { "User-Agent", R1.UserAgent1 }
228- },
229- Content = new MultipartFormDataContent()
230- {
231- { new FileContent(t), "sfile", name }
232- }
233- };
234- m_clientHandler.CookieContainer.Add(m_cookies);
235-
236- var res = await m_client.SendAsync(req);
237-
238- var content = await res.Content.ReadAsStringAsync();
239- var parser = new HtmlParser();
240- return await parser.ParseDocumentAsync(content, token);
241- }*/
242-
243156 protected override async Task < IDocument > GetDocumentAsync ( SearchResult sr , SearchQuery query ,
244157 CancellationToken token = default )
245158 {
246159
247- const string name_default = "a.jpg" ;
248- string name ;
249- string t = null ;
160+ const string SFILE_NAME_DEFAULT = "a.jpg" ;
161+ string fileName ;
162+ string filePath = null ;
250163
251164 if ( query . HasFile ) {
252- t = query . FilePath ;
253- name = Path . GetFileName ( t ) ;
165+ filePath = query . FilePath ;
166+ fileName = Path . GetFileName ( filePath ) ;
254167
255168 /*if (Path.GetFileName(t) != name) {
256169 // Debugger.Break();
257170 }*/
258171 }
259172 else {
260- name = name_default ;
261- var ok = query . TryGetFile ( name ) ;
173+ fileName = SFILE_NAME_DEFAULT ;
174+ var ok = query . TryGetFile ( fileName ) ;
262175
263176 if ( ok ) {
264- t = query . FilePath ;
177+ filePath = query . FilePath ;
265178 }
266179 else {
267180 Debugger . Break ( ) ;
268181 }
269182 }
270183
271- if ( t != null ) {
272- Trace . WriteLine ( $ "allocated { t } ", nameof ( GetDocumentAsync ) ) ;
184+ if ( filePath != null ) {
185+ Trace . WriteLine ( $ "allocated { filePath } ", nameof ( GetDocumentAsync ) ) ;
273186 }
274187
275188 var data = new MultipartFormDataContent ( )
276189 {
277- { new FileContent ( t ) , "sfile" , name } ,
190+ { new FileContent ( filePath ) , "sfile" , fileName } ,
278191
279192 // { new StreamContent((Stream) query.Uni.Stream), "sfile", "a.jpg" },
280193 { new StringContent ( "fs_similar" ) } ,
@@ -303,6 +216,7 @@ protected override async Task<IDocument> GetDocumentAsync(SearchResult sr, Searc
303216 } ;
304217
305218 var res = await m_client . SendAsync ( req , token ) ;
219+
306220 // Debug.WriteLine($"{res.StatusCode}");
307221
308222 sr . RawUrl = res . RequestMessage . RequestUri ;
@@ -393,96 +307,96 @@ private bool SetField<T>(ref T field, T value, [CallerMemberName] string propert
393307 return true ;
394308 }
395309
396- private sealed record EhResult : IParseable < EhResult , INode >
397- {
310+ }
398311
399- internal string Type { get ; set ; }
312+ public sealed record EhResult : IParseable < EhResult , INode >
313+ {
400314
401- internal string Pages { get ; set ; }
315+ public string Type { get ; internal set ; }
402316
403- internal string Title { get ; set ; }
317+ public string Pages { get ; internal set ; }
404318
405- internal string Author { get ; set ; }
319+ public string Title { get ; internal set ; }
406320
407- internal string AuthorUrl { get ; set ; }
321+ public string Author { get ; internal set ; }
408322
409- internal Url Url { get ; set ; }
323+ public string AuthorUrl { get ; internal set ; }
410324
411- internal ConcurrentDictionary < string , ConcurrentBag < string > > Tags { get ; } = new ( ) ;
325+ public Url Url { get ; internal set ; }
412326
413- public static EhResult Parse ( INode n )
414- {
415- // ReSharper disable InconsistentNaming
416- var eh = new EhResult ( ) ;
327+ public ConcurrentDictionary < string , ConcurrentBag < string > > Tags { get ; } = new ( ) ;
417328
418- var gl1c = n . ChildNodes . TryFindSingleElementByClassName ( "gl1c" ) ;
329+ public static EhResult Parse ( INode n )
330+ {
331+ // ReSharper disable InconsistentNaming
332+ var eh = new EhResult ( ) ;
419333
420- if ( gl1c is { } ) {
421- if ( gl1c . FirstChild is { } t ) {
422- eh . Type = t . TextContent ;
423- }
334+ var gl1c = n . ChildNodes . TryFindSingleElementByClassName ( "gl1c" ) ;
335+
336+ if ( gl1c is { } ) {
337+ if ( gl1c . FirstChild is { } t ) {
338+ eh . Type = t . TextContent ;
424339 }
340+ }
425341
426- var gl2c = n . ChildNodes . TryFindSingleElementByClassName ( "gl2c" ) ;
342+ var gl2c = n . ChildNodes . TryFindSingleElementByClassName ( "gl2c" ) ;
427343
428- if ( gl2c is { } ) {
429- if ( gl2c . ChildNodes [ 1 ] . ChildNodes [ 1 ] . ChildNodes [ 1 ] . ChildNodes [ 1 ] is { } div ) {
430- eh . Pages = div . TextContent ;
431- }
344+ if ( gl2c is { } ) {
345+ if ( gl2c . ChildNodes [ 1 ] . ChildNodes [ 1 ] . ChildNodes [ 1 ] . ChildNodes [ 1 ] is { } div ) {
346+ eh . Pages = div . TextContent ;
432347 }
348+ }
433349
434- var gl3c = n . ChildNodes . TryFindSingleElementByClassName ( "gl3c glname" ) ;
350+ var gl3c = n . ChildNodes . TryFindSingleElementByClassName ( "gl3c glname" ) ;
435351
436- if ( gl3c is { } ) {
437- if ( gl3c . FirstChild is { } f ) {
438- eh . Url = ( Url ) f . TryGetAttribute ( Serialization . Atr_href ) ;
352+ if ( gl3c is { } ) {
353+ if ( gl3c . FirstChild is { } f ) {
354+ eh . Url = ( Url ) f . TryGetAttribute ( Serialization . Atr_href ) ;
439355
440- if ( f . FirstChild is { } ff ) {
441- eh . Title = ff . TextContent ;
442- }
356+ if ( f . FirstChild is { } ff ) {
357+ eh . Title = ff . TextContent ;
358+ }
443359
444- if ( f . ChildNodes [ 1 ] is { ChildNodes : { Length : > 0 } cn } f2 ) {
445- var tagValuesRaw = cn . Select ( c => c . TryGetAttribute ( "title" ) ) ;
360+ if ( f . ChildNodes [ 1 ] is { ChildNodes : { Length : > 0 } cn } f2 ) {
361+ var tagValuesRaw = cn . Select ( c => c . TryGetAttribute ( "title" ) ) ;
446362
447- foreach ( string s in tagValuesRaw ) {
448- if ( s is not { } ) {
449- continue ;
450- }
363+ foreach ( string s in tagValuesRaw ) {
364+ if ( s is not { } ) {
365+ continue ;
366+ }
451367
452- var split = s . Split ( ':' ) ;
453- var tag = split [ 0 ] ;
454- var val = split [ 1 ] ;
368+ var split = s . Split ( ':' ) ;
369+ var tag = split [ 0 ] ;
370+ var val = split [ 1 ] ;
455371
456- if ( eh . Tags . ContainsKey ( tag ) ) {
457- eh . Tags [ tag ] . Add ( val ) ;
458- }
459- else {
460- eh . Tags . TryAdd ( tag , [ val ] ) ;
372+ if ( eh . Tags . ContainsKey ( tag ) ) {
373+ eh . Tags [ tag ] . Add ( val ) ;
374+ }
375+ else {
376+ eh . Tags . TryAdd ( tag , [ val ] ) ;
461377
462- }
463378 }
464379 }
465380 }
466381 }
382+ }
467383
468- var gl4c = n . ChildNodes . TryFindSingleElementByClassName ( "gl4c glhide" ) ;
469-
470- if ( gl4c is { } ) {
471- if ( gl4c . ChildNodes [ 0 ] is { FirstChild : { } div1 } div1Outer ) {
472- eh . AuthorUrl = div1 . TryGetAttribute ( Serialization . Atr_href ) ;
473- eh . Author = div1Outer . TextContent ?? div1 . TextContent ;
474- }
384+ var gl4c = n . ChildNodes . TryFindSingleElementByClassName ( "gl4c glhide" ) ;
475385
476- if ( gl4c . ChildNodes [ 1 ] is { } div2 ) {
477- eh . Pages ??= div2 . TextContent ;
478- }
386+ if ( gl4c is { } ) {
387+ if ( gl4c . ChildNodes [ 0 ] is { FirstChild : { } div1 } div1Outer ) {
388+ eh . AuthorUrl = div1 . TryGetAttribute ( Serialization . Atr_href ) ;
389+ eh . Author = div1Outer . TextContent ?? div1 . TextContent ;
479390 }
480391
481- return eh ;
482-
483- // ReSharper restore InconsistentNaming
392+ if ( gl4c . ChildNodes [ 1 ] is { } div2 ) {
393+ eh . Pages ??= div2 . TextContent ;
394+ }
484395 }
485396
397+ return eh ;
398+
399+ // ReSharper restore InconsistentNaming
486400 }
487401
488402}
0 commit comments