From 6725112e6bde20a78ea12df5ee23a323493e8395 Mon Sep 17 00:00:00 2001 From: rhapsodhy Date: Wed, 14 May 2014 19:30:32 +0100 Subject: [PATCH] [enh] sort piratebay results by seeders --- searx/engines/piratebay.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/searx/engines/piratebay.py b/searx/engines/piratebay.py index ca1085141..85268dcab 100644 --- a/searx/engines/piratebay.py +++ b/searx/engines/piratebay.py @@ -24,7 +24,6 @@ def request(query, params): pageno=params['pageno'] - 1) return params - def response(resp): results = [] dom = html.fromstring(resp.text) @@ -45,4 +44,10 @@ def response(resp): 'leech': leech, 'magnetlink': magnetlink.attrib['href'], 'template': 'torrent.html'}) - return results + return sorted(results, key=lambda x: get_int('seed'), reversed=True) + +def get_int(field): + try: + return int(field) + except TypeError: + return 0