From 1cf870c02447a636d8b21057934e69afd5289ba2 Mon Sep 17 00:00:00 2001 From: dalf Date: Thu, 12 Feb 2015 12:30:03 +0100 Subject: [PATCH 1/3] [fix] kickass engine : change the hostname to kickass.to (since kickass.so doesn't respond). Close #197 perhaps not in clean way. Explaination : 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 begining 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 --- searx/engines/kickass.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/searx/engines/kickass.py b/searx/engines/kickass.py index 8b89e1f47..f2ede034e 100644 --- a/searx/engines/kickass.py +++ b/searx/engines/kickass.py @@ -20,7 +20,7 @@ categories = ['videos', 'music', 'files'] paging = True # search-url -url = 'https://kickass.so/' +url = 'https://kickass.to/' search_url = url + 'search/{search_term}/{pageno}/' # specific xpath variables @@ -45,6 +45,9 @@ def request(query, params): def response(resp): results = [] + if resp.is_redirect: + return results + dom = html.fromstring(resp.text) search_res = dom.xpath('//table[@class="data"]//tr') From 9db0bbc30421cec9d42438ccab748439eea60105 Mon Sep 17 00:00:00 2001 From: dalf Date: Thu, 12 Feb 2015 12:30:03 +0100 Subject: [PATCH 2/3] [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 --- searx/engines/kickass.py | 7 ++++++- searx/tests/engines/test_kickass.py | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/searx/engines/kickass.py b/searx/engines/kickass.py index 8b89e1f47..8b7e24579 100644 --- a/searx/engines/kickass.py +++ b/searx/engines/kickass.py @@ -20,7 +20,7 @@ categories = ['videos', 'music', 'files'] paging = True # search-url -url = 'https://kickass.so/' +url = 'https://kickass.to/' search_url = url + 'search/{search_term}/{pageno}/' # specific xpath variables @@ -45,6 +45,11 @@ def request(query, params): def response(resp): results = [] + # check if redirect comparing to the True value, + # because resp can be a Mock object, and any attribut name returns something. + if resp.is_redirect == True: + return results + dom = html.fromstring(resp.text) search_res = dom.xpath('//table[@class="data"]//tr') diff --git a/searx/tests/engines/test_kickass.py b/searx/tests/engines/test_kickass.py index 3c20a97e7..971d0847e 100644 --- a/searx/tests/engines/test_kickass.py +++ b/searx/tests/engines/test_kickass.py @@ -14,7 +14,7 @@ class TestKickassEngine(SearxTestCase): params = kickass.request(query, dicto) self.assertIn('url', params) self.assertIn(query, params['url']) - self.assertIn('kickass.so', params['url']) + self.assertIn('kickass.to', params['url']) self.assertIn('verify', params) self.assertFalse(params['verify']) @@ -98,7 +98,7 @@ class TestKickassEngine(SearxTestCase): self.assertEqual(type(results), list) self.assertEqual(len(results), 1) self.assertEqual(results[0]['title'], 'This should be the title') - self.assertEqual(results[0]['url'], 'https://kickass.so/url.html') + self.assertEqual(results[0]['url'], 'https://kickass.to/url.html') self.assertEqual(results[0]['content'], 'Posted by riri in Other > Unsorted') self.assertEqual(results[0]['seed'], 10) self.assertEqual(results[0]['leech'], 1) @@ -381,7 +381,7 @@ class TestKickassEngine(SearxTestCase): self.assertEqual(type(results), list) self.assertEqual(len(results), 5) self.assertEqual(results[0]['title'], 'This should be the title') - self.assertEqual(results[0]['url'], 'https://kickass.so/url.html') + self.assertEqual(results[0]['url'], 'https://kickass.to/url.html') self.assertEqual(results[0]['content'], 'Posted by riri in Other > Unsorted') self.assertEqual(results[0]['seed'], 10) self.assertEqual(results[0]['leech'], 1) From 9d537c0bad5b68f9c83ea4ac026d22a27264b8dd Mon Sep 17 00:00:00 2001 From: dalf Date: Thu, 12 Feb 2015 14:50:41 +0100 Subject: [PATCH 3/3] [fix] kickass tests --- searx/engines/kickass.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/searx/engines/kickass.py b/searx/engines/kickass.py index 8b7e24579..4e5a64350 100644 --- a/searx/engines/kickass.py +++ b/searx/engines/kickass.py @@ -47,7 +47,7 @@ def response(resp): # check if redirect comparing to the True value, # because resp can be a Mock object, and any attribut name returns something. - if resp.is_redirect == True: + if resp.is_redirect is True: return results dom = html.fromstring(resp.text)