summaryrefslogtreecommitdiff
path: root/searx/engines/nyaa.py
diff options
context:
space:
mode:
authorKirill Isakov <ukwt@ya.ru>2016-03-26 05:28:58 +0600
committerKirill Isakov <ukwt@ya.ru>2016-03-26 05:28:58 +0600
commit7fbc12ee4e6aea8a8ad0098deb03054976056371 (patch)
tree213517c3d4eb85dc08726de9fd28401720372516 /searx/engines/nyaa.py
parentd026a97e42dce14bb187ea79682b9a303cd91e9e (diff)
downloadsearxng-7fbc12ee4e6aea8a8ad0098deb03054976056371.tar.gz
searxng-7fbc12ee4e6aea8a8ad0098deb03054976056371.zip
Add Torrentz.eu search engine
Diffstat (limited to 'searx/engines/nyaa.py')
-rw-r--r--searx/engines/nyaa.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/searx/engines/nyaa.py b/searx/engines/nyaa.py
index 81caed76f..b0f884b77 100644
--- a/searx/engines/nyaa.py
+++ b/searx/engines/nyaa.py
@@ -43,6 +43,19 @@ def int_or_zero(num):
return int(num)
return 0
+# get multiplier to convert torrent size to bytes
+def get_filesize_mul(suffix):
+ return {
+ 'KB': 1024,
+ 'MB': 1024 ** 2,
+ 'GB': 1024 ** 3,
+ 'TB': 1024 ** 4,
+
+ 'KIB': 1024,
+ 'MIB': 1024 ** 2,
+ 'GIB': 1024 ** 3,
+ 'TIB': 1024 ** 4
+ }[str(suffix).upper()]
# do search-request
def request(query, params):
@@ -74,18 +87,7 @@ def response(resp):
# torrent size
try:
file_size, suffix = result.xpath(xpath_filesize)[0].split(' ')
-
- # convert torrent size to bytes.
- # if there is no correct index in this dictionary,
- # the try block fails as it should
- multiplier = {
- 'KIB': 1024,
- 'MIB': 1024 ** 2,
- 'GIB': 1024 ** 3,
- 'TIB': 1024 ** 4
- }[suffix.upper()]
-
- file_size = int(float(file_size) * multiplier)
+ file_size = int(float(file_size) * get_filesize_mul(suffix))
except Exception as e:
file_size = None