From 830f70a6bc2a6e0b7a78d0a13277b28f03c18504 Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Sat, 10 Jan 2015 19:40:27 +0100 Subject: [enh] improve torrent results --- searx/engines/kickass.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'searx/engines') diff --git a/searx/engines/kickass.py b/searx/engines/kickass.py index 16e9d6de6..39b50b0ef 100644 --- a/searx/engines/kickass.py +++ b/searx/engines/kickass.py @@ -24,6 +24,7 @@ search_url = url + 'search/{search_term}/{pageno}/' # specific xpath variables magnet_xpath = './/a[@title="Torrent magnet link"]' +torrent_xpath = './/a[@title="Download torrent file"]' content_xpath = './/span[@class="font11px lightgrey block"]' @@ -60,6 +61,9 @@ def response(resp): method="text")) seed = result.xpath('.//td[contains(@class, "green")]/text()')[0] leech = result.xpath('.//td[contains(@class, "red")]/text()')[0] + filesize = result.xpath('.//td[contains(@class, "nobr")]/text()')[0] + filesize_multiplier = result.xpath('.//td[contains(@class, "nobr")]//span/text()')[0] + files = result.xpath('.//td[contains(@class, "center")][2]/text()')[0] # convert seed to int if possible if seed.isdigit(): @@ -73,7 +77,31 @@ def response(resp): else: leech = 0 + # convert filesize to byte if possible + try: + filesize = float(filesize) + + # convert filesize to byte + if filesize_multiplier == 'TB': + filesize = int(filesize * 1024*1024*1024*1024) + elif filesize_multiplier == 'GB': + filesize = int(filesize * 1024*1024*1024) + elif filesize_multiplier == 'MB': + filesize = int(filesize * 1024*1024) + elif filesize_multiplier == 'kb': + filesize = int(filesize * 1024) + except: + filesize = None + + # convert files to int if possible + if files.isdigit(): + files = int(files) + else: + files = None + magnetlink = result.xpath(magnet_xpath)[0].attrib['href'] + + torrentfile = result.xpath(torrent_xpath)[0].attrib['href'] # append result results.append({'url': href, @@ -81,7 +109,10 @@ def response(resp): 'content': content, 'seed': seed, 'leech': leech, + 'filesize': filesize, + 'files': files, 'magnetlink': magnetlink, + 'torrentfile':torrentfile, 'template': 'torrent.html'}) # return results sorted by seeder -- cgit v1.2.3 From 811515101b750717f6b07fad1a9b75041f91c90d Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Sat, 10 Jan 2015 20:01:36 +0100 Subject: [fix] pep8 --- searx/engines/kickass.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'searx/engines') diff --git a/searx/engines/kickass.py b/searx/engines/kickass.py index 39b50b0ef..a4d270673 100644 --- a/searx/engines/kickass.py +++ b/searx/engines/kickass.py @@ -80,16 +80,16 @@ def response(resp): # convert filesize to byte if possible try: filesize = float(filesize) - + # convert filesize to byte if filesize_multiplier == 'TB': - filesize = int(filesize * 1024*1024*1024*1024) + filesize = int(filesize * 1024 * 1024 * 1024 * 1024) elif filesize_multiplier == 'GB': - filesize = int(filesize * 1024*1024*1024) + filesize = int(filesize * 1024 * 1024 * 1024) elif filesize_multiplier == 'MB': - filesize = int(filesize * 1024*1024) + filesize = int(filesize * 1024 * 1024) elif filesize_multiplier == 'kb': - filesize = int(filesize * 1024) + filesize = int(filesize * 1024) except: filesize = None @@ -100,7 +100,7 @@ def response(resp): files = None magnetlink = result.xpath(magnet_xpath)[0].attrib['href'] - + torrentfile = result.xpath(torrent_xpath)[0].attrib['href'] # append result @@ -112,7 +112,7 @@ def response(resp): 'filesize': filesize, 'files': files, 'magnetlink': magnetlink, - 'torrentfile':torrentfile, + 'torrentfile': torrentfile, 'template': 'torrent.html'}) # return results sorted by seeder -- cgit v1.2.3