SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.
Python bingbravedegoogleduckduckgogooglemetasearchprivacypythonqwantsearchsearch-enginesearxsearxngstartpageyahoo
[mod] tpb sort refactor
Adam Tauber7e946a369b5c
diff --git a/searx/engines/piratebay.py b/searx/engines/piratebay.pyindex c14b70f3c..bb4886868 100644--- a/searx/engines/piratebay.py+++ b/searx/engines/piratebay.py@@ -2,6 +2,7 @@ from urlparse import urljoinfrom cgi import escapefrom urllib import quotefrom lxml import html+from operator import itemgettercategories = ['videos', 'music']@@ -24,18 +25,32 @@ def request(query, params):pageno=params['pageno'] - 1)return params+def response(resp):results = []dom = html.fromstring(resp.text)search_res = dom.xpath('//table[@id="searchResult"]//tr')+if not search_res:return results+for result in search_res[1:]:link = result.xpath('.//div[@class="detName"]//a')[0]href = urljoin(url, link.attrib.get('href'))title = ' '.join(link.xpath('.//text()'))content = escape(' '.join(result.xpath(content_xpath)))seed, leech = result.xpath('.//td[@align="right"]/text()')[:2]++ if seed.isdigit():+ seed = int(seed)+ else:+ seed = 0++ if leech.isdigit():+ leech = int(leech)+ else:+ leech = 0+magnetlink = result.xpath(magnet_xpath)[0]results.append({'url': href,'title': title,@@ -44,10 +59,5 @@ def response(resp):'leech': leech,'magnetlink': magnetlink.attrib['href'],'template': 'torrent.html'})- return sorted(results, key=lambda x: get_int('seed'), reversed=True)-def get_int(field):- try:- return int(field)- except TypeError:- return 0+ return sorted(results, key=itemgetter('seed'), reverse=True)