@@ -21,6 +21,7 @@ namespace SmartImage.Lib.Engines.Impl
2121{
2222 public sealed class Ascii2DEngine : WebSearchEngine
2323 {
24+
2425 public Ascii2DEngine ( ) : base ( "https://ascii2d.net/search/url/" )
2526 {
2627 FollowRedirects = true ;
@@ -33,22 +34,6 @@ public Ascii2DEngine() : base("https://ascii2d.net/search/url/")
3334
3435 public override string Name => EngineOption . ToString ( ) ;
3536
36-
37- /*protected override bool GetRawResultUri(ImageQuery query, out Uri uri, out IRestResponse res)
38- {
39- uri = new Uri(BaseUrl + query.UploadUri);
40-
41- res = Network.GetResponse(uri.ToString(), (int) Timeout.TotalMilliseconds, Method.GET, false);
42-
43- if (!res.IsSuccessful && res.StatusCode != HttpStatusCode.Redirect) {
44- Debug.WriteLine($"{Name} is unavailable or timed out after {Timeout:g} | {uri} {res.StatusCode}",
45- LogCategories.C_WARN);
46- return false;
47- }
48-
49- return true;
50- }*/
51-
5237 private Uri ConvertToDetailUri ( Uri url )
5338 {
5439 /*
@@ -59,6 +44,11 @@ private Uri ConvertToDetailUri(Uri url)
5944 *
6045 */
6146
47+ /*
48+ * With Ascii2D, two requests need to be made in order to get the detail results
49+ * as the color results are returned by default
50+ *
51+ */
6252
6353 var res = Network . GetResponse ( url . ToString ( ) , ( int ) Timeout . TotalMilliseconds , Method . GET , false ) ;
6454
@@ -70,7 +60,6 @@ private Uri ConvertToDetailUri(Uri url)
7060
7161 string detailUrl = newUrl . Replace ( "/color/" , "/bovw/" ) ;
7262
73-
7463 return new Uri ( detailUrl ) ;
7564 }
7665
@@ -81,7 +70,7 @@ protected override Uri GetRaw(ImageQuery query)
8170
8271 }
8372
84- protected override IDocument GetContent ( IRestResponse response )
73+ protected internal override IDocument GetContent ( IRestResponse response )
8574 {
8675 var url = response . ResponseUri ;
8776
@@ -96,41 +85,19 @@ protected override IDocument GetContent(IRestResponse response)
9685 protected override bool GetInitialResult ( ImageQuery query , out Uri rawUri , out IRestResponse res )
9786 {
9887 rawUri = GetRaw ( query ) ;
99-
100- /*if (!Network.IsAlive(uri, (int) Timeout.TotalMilliseconds)) {
101- Debug.WriteLine($"{Name} is unavailable or timed out after {Timeout:g} | {uri}", C_WARN);
102- return null;
103- }*/
104-
105-
88+
10689 // NOTE: wtf?
10790
10891 res = Network . GetResponse ( rawUri . ToString ( ) , ( int ) Timeout . TotalMilliseconds , Method . GET , FollowRedirects ) ;
109-
110- //res = new RestClient(rawUri).Execute(new RestRequest());
111-
92+
11293 res . Content = WebUtilities . GetString ( rawUri . ToString ( ) ) ;
11394
114-
115- /*if (!res.IsSuccessful)
116- {
117- if ((FollowRedirects && res.StatusCode == HttpStatusCode.Redirect))
118- {
119- return true;
120- }
121-
122- Debug.WriteLine($"{Name} is unavailable or timed out after " +
123- $"{Timeout:g} | {rawUri} {res.StatusCode}", LogCategories.C_WARN);
124- return false;
125- }*/
126-
12795 return true ;
128-
12996 }
13097
131- protected override SearchResult Process ( object content , SearchResult sr )
98+ protected override SearchResult Process ( object obj , SearchResult sr )
13299 {
133- var doc = ( IDocument ) content ;
100+ var doc = ( IDocument ) obj ;
134101 var nodes = doc . Body . SelectNodes ( "//*[contains(@class, 'info-box')]" ) ;
135102
136103 var rg = new List < ImageResult > ( ) ;
0 commit comments