summaryrefslogtreecommitdiff
path: root/searx/engines
diff options
context:
space:
mode:
Diffstat (limited to 'searx/engines')
-rw-r--r--searx/engines/flickr-noapi.py2
-rw-r--r--searx/engines/kickass.py32
-rw-r--r--searx/engines/wikidata.py22
3 files changed, 39 insertions, 17 deletions
diff --git a/searx/engines/flickr-noapi.py b/searx/engines/flickr-noapi.py
index aa2fa5d3b..89dd2ee5f 100644
--- a/searx/engines/flickr-noapi.py
+++ b/searx/engines/flickr-noapi.py
@@ -73,7 +73,7 @@ def response(resp):
url = build_flickr_url(photo['owner']['id'], photo['id'])
- title = photo['title']
+ title = photo.get('title', '')
content = '<span class="photo-author">' +\
photo['owner']['username'] +\
diff --git a/searx/engines/kickass.py b/searx/engines/kickass.py
index 16e9d6de6..ac349283d 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,15 +77,43 @@ 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']
+ torrentfileurl = quote(torrentfile, safe="%/:=&?~#+!$,;'@()*")
+
# append result
results.append({'url': href,
'title': title,
'content': content,
'seed': seed,
'leech': leech,
+ 'filesize': filesize,
+ 'files': files,
'magnetlink': magnetlink,
+ 'torrentfile': torrentfileurl,
'template': 'torrent.html'})
# return results sorted by seeder
diff --git a/searx/engines/wikidata.py b/searx/engines/wikidata.py
index df976ae35..da3152ac8 100644
--- a/searx/engines/wikidata.py
+++ b/searx/engines/wikidata.py
@@ -1,8 +1,7 @@
import json
from requests import get
from urllib import urlencode
-import locale
-import dateutil.parser
+from searx.utils import format_date_by_locale
result_count = 1
wikidata_host = 'https://www.wikidata.org'
@@ -38,27 +37,18 @@ def response(resp):
if language == 'all':
language = 'en'
- try:
- locale.setlocale(locale.LC_ALL, str(resp.search_params['language']))
- except:
- try:
- locale.setlocale(locale.LC_ALL, 'en_US')
- except:
- pass
- pass
-
url = url_detail.format(query=urlencode({'ids': '|'.join(wikidata_ids),
'languages': language + '|en'}))
htmlresponse = get(url)
jsonresponse = json.loads(htmlresponse.content)
for wikidata_id in wikidata_ids:
- results = results + getDetail(jsonresponse, wikidata_id, language)
+ results = results + getDetail(jsonresponse, wikidata_id, language, resp.search_params['language'])
return results
-def getDetail(jsonresponse, wikidata_id, language):
+def getDetail(jsonresponse, wikidata_id, language, locale):
results = []
urls = []
attributes = []
@@ -176,12 +166,12 @@ def getDetail(jsonresponse, wikidata_id, language):
date_of_birth = get_time(claims, 'P569', None)
if date_of_birth is not None:
- date_of_birth = dateutil.parser.parse(date_of_birth[8:]).strftime(locale.nl_langinfo(locale.D_FMT))
+ date_of_birth = format_date_by_locale(date_of_birth[8:], locale)
attributes.append({'label': 'Date of birth', 'value': date_of_birth})
date_of_death = get_time(claims, 'P570', None)
if date_of_death is not None:
- date_of_death = dateutil.parser.parse(date_of_death[8:]).strftime(locale.nl_langinfo(locale.D_FMT))
+ date_of_death = format_date_by_locale(date_of_death[8:], locale)
attributes.append({'label': 'Date of death', 'value': date_of_death})
if len(attributes) == 0 and len(urls) == 2 and len(description) == 0:
@@ -235,7 +225,7 @@ def get_string(claims, propertyName, defaultValue=None):
if len(result) == 0:
return defaultValue
else:
- #TODO handle multiple urls
+ # TODO handle multiple urls
return result[0]