浏览代码

[fix] kickass engine : change the hostname to kickass.to (since kickass.so doesn't respond).

Close #197 perhaps not in clean way. Explanation :
In fact 301 responses are followed, except the hook is called for each HTTP response,
the first time for the HTTP 301 response then for HTTP 200 response.
Since the kickass engine excepts a real result, the engine crashes, AND the requests lib stops here.
Add a simple test at the beginning of the result function allows pass the first response and handle correctly the second response (the real one)

May be a proper way is to add this test in search.py ?

Code inside requests :
https://github.com/kennethreitz/requests/blob/53d02381e22436b6d0757eb305eb1a960f82d361/requests/sessions.py#L579
and line 591
dalf 10 年前
父节点
当前提交
9db0bbc304
共有 2 个文件被更改,包括 9 次插入4 次删除
  1. 6
    1
      searx/engines/kickass.py
  2. 3
    3
      searx/tests/engines/test_kickass.py

+ 6
- 1
searx/engines/kickass.py 查看文件

@@ -20,7 +20,7 @@ categories = ['videos', 'music', 'files']
20 20
 paging = True
21 21
 
22 22
 # search-url
23
-url = 'https://kickass.so/'
23
+url = 'https://kickass.to/'
24 24
 search_url = url + 'search/{search_term}/{pageno}/'
25 25
 
26 26
 # specific xpath variables
@@ -45,6 +45,11 @@ def request(query, params):
45 45
 def response(resp):
46 46
     results = []
47 47
 
48
+    # check if redirect comparing to the True value,
49
+    # because resp can be a Mock object, and any attribut name returns something.
50
+    if resp.is_redirect == True:
51
+        return results
52
+
48 53
     dom = html.fromstring(resp.text)
49 54
 
50 55
     search_res = dom.xpath('//table[@class="data"]//tr')

+ 3
- 3
searx/tests/engines/test_kickass.py 查看文件

@@ -14,7 +14,7 @@ class TestKickassEngine(SearxTestCase):
14 14
         params = kickass.request(query, dicto)
15 15
         self.assertIn('url', params)
16 16
         self.assertIn(query, params['url'])
17
-        self.assertIn('kickass.so', params['url'])
17
+        self.assertIn('kickass.to', params['url'])
18 18
         self.assertIn('verify', params)
19 19
         self.assertFalse(params['verify'])
20 20
 
@@ -98,7 +98,7 @@ class TestKickassEngine(SearxTestCase):
98 98
         self.assertEqual(type(results), list)
99 99
         self.assertEqual(len(results), 1)
100 100
         self.assertEqual(results[0]['title'], 'This should be the title')
101
-        self.assertEqual(results[0]['url'], 'https://kickass.so/url.html')
101
+        self.assertEqual(results[0]['url'], 'https://kickass.to/url.html')
102 102
         self.assertEqual(results[0]['content'], 'Posted by riri in Other > Unsorted')
103 103
         self.assertEqual(results[0]['seed'], 10)
104 104
         self.assertEqual(results[0]['leech'], 1)
@@ -381,7 +381,7 @@ class TestKickassEngine(SearxTestCase):
381 381
         self.assertEqual(type(results), list)
382 382
         self.assertEqual(len(results), 5)
383 383
         self.assertEqual(results[0]['title'], 'This should be the title')
384
-        self.assertEqual(results[0]['url'], 'https://kickass.so/url.html')
384
+        self.assertEqual(results[0]['url'], 'https://kickass.to/url.html')
385 385
         self.assertEqual(results[0]['content'], 'Posted by riri in Other > Unsorted')
386 386
         self.assertEqual(results[0]['seed'], 10)
387 387
         self.assertEqual(results[0]['leech'], 1)