@@ -12,7 +12,7 @@
1212from lxml import html
1313from searx.engines.xpath import extract_text
1414from searx.url_utils import urlencode
15−from searx.utils import get_torrent_size
15+from searx.utils import get_torrent_size, int_or_zero
1616
1717# engine dependent config
1818categories = ['files', 'images', 'videos', 'music']
@@ -49,14 +49,14 @@ def response(resp):
4949 for result in dom.xpath(xpath_results):
5050 # defaults
5151 filesize = 0
52− seed = 0
53− leech = 0
54− downloads = 0
5552 magnet_link = ""
5653 torrent_link = ""
5754
5855 # category in which our torrent belongs
59− category = result.xpath(xpath_category)[0].attrib.get('title')
56+ try:
57+ category = result.xpath(xpath_category)[0].attrib.get('title')
58+ except:
59+ pass
6060
6161 # torrent title
6262 page_a = result.xpath(xpath_title)[0]
@@ -74,12 +74,14 @@ def response(resp):
7474 # link to the torrent file
7575 torrent_link = url
7676
77− # get seeders and leechers
78− try:
79− seed = int(result.xpath(xpath_seeds)[0])
80− leech = int(result.xpath(xpath_leeches)[0])
81− except:
82− pass
77+ # seed count
78+ seed = int_or_zero(result.xpath(xpath_seeds))
79+
80+ # leech count
81+ leech = int_or_zero(result.xpath(xpath_leeches))
82+
83+ # torrent downloads count
84+ downloads = int_or_zero(result.xpath(xpath_downloads))
8385
8486 # let's try to calculate the torrent size
8587 try:
@@ -89,12 +91,6 @@ def response(resp):
8991 except:
9092 pass
9193
92− # torrent downloads count
93− try:
94− downloads = result.xpath(xpath_downloads)[0]
95− except:
96− pass
97−
9894 # content string contains all information not included into template
9995 content = 'Category: "{category}". Downloaded {downloads} times.'
10096 content = content.format(category=category, downloads=downloads)