summaryrefslogtreecommitdiff
path: root/searx
diff options
context:
space:
mode:
Diffstat (limited to 'searx')
-rw-r--r--searx/engines/kickass.py46
-rw-r--r--searx/settings.yml12
-rw-r--r--searx/templates/courgette/base.html2
-rw-r--r--searx/templates/legacy/base.html2
-rw-r--r--searx/templates/oscar/macros.html6
-rw-r--r--searx/utils.py15
-rw-r--r--searx/webapp.py26
7 files changed, 67 insertions, 42 deletions
diff --git a/searx/engines/kickass.py b/searx/engines/kickass.py
index 4c5d24008..9cd8284da 100644
--- a/searx/engines/kickass.py
+++ b/searx/engines/kickass.py
@@ -16,13 +16,14 @@ from urllib import quote
from lxml import html
from operator import itemgetter
from searx.engines.xpath import extract_text
+from searx.utils import get_torrent_size, convert_str_to_int
# engine dependent config
categories = ['videos', 'music', 'files']
paging = True
# search-url
-url = 'https://kickass.to/'
+url = 'https://kickass.cd/'
search_url = url + 'search/{search_term}/{pageno}/'
# specific xpath variables
@@ -57,41 +58,16 @@ def response(resp):
href = urljoin(url, link.attrib['href'])
title = extract_text(link)
content = escape(extract_text(result.xpath(content_xpath)))
- 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():
- seed = int(seed)
- else:
- seed = 0
+ seed = extract_text(result.xpath('.//td[contains(@class, "green")]'))
+ leech = extract_text(result.xpath('.//td[contains(@class, "red")]'))
+ filesize_info = extract_text(result.xpath('.//td[contains(@class, "nobr")]'))
+ files = extract_text(result.xpath('.//td[contains(@class, "center")][2]'))
- # convert leech to int if possible
- if leech.isdigit():
- leech = int(leech)
- 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
+ seed = convert_str_to_int(seed)
+ leech = convert_str_to_int(leech)
+
+ filesize, filesize_multiplier = filesize_info.split()
+ filesize = get_torrent_size(filesize, filesize_multiplier)
if files.isdigit():
files = int(files)
else:
diff --git a/searx/settings.yml b/searx/settings.yml
index e83f5aea7..ba7ae428b 100644
--- a/searx/settings.yml
+++ b/searx/settings.yml
@@ -18,6 +18,12 @@ ui:
default_theme : oscar # ui theme
default_locale : "" # Default interface locale - leave blank to detect from browser information or use codes from the 'locales' config section
+# searx supports result proxification using an external service: https://github.com/asciimoo/morty
+# uncomment below section if you have running morty proxy
+#result_proxy:
+# url : http://127.0.0.1:3000/
+# key : your_morty_proxy_key
+
outgoing: # communication with search engines
request_timeout : 2.0 # seconds
useragent_suffix : "" # suffix of searx_useragent, could contain informations like an email address to the administrator
@@ -301,6 +307,12 @@ engines:
timeout : 6.0
disabled : True
+ - name: kickass
+ engine : kickass
+ shortcut : kc
+ timeout : 4.0
+ disabled : True
+
- name : microsoft academic
engine : json_engine
paging : True
diff --git a/searx/templates/courgette/base.html b/searx/templates/courgette/base.html
index b2c70a3b7..8e272585c 100644
--- a/searx/templates/courgette/base.html
+++ b/searx/templates/courgette/base.html
@@ -22,7 +22,7 @@
{% endblock %}
{% block meta %}{% endblock %}
{% block head %}
- <link title="searx" type="application/opensearchdescription+xml" rel="search" href="{{ url_for('opensearch') }}"/>
+ <link title="{{ instance_name }}" type="application/opensearchdescription+xml" rel="search" href="{{ url_for('opensearch') }}"/>
{% endblock %}
<script type="text/javascript">
searx = {};
diff --git a/searx/templates/legacy/base.html b/searx/templates/legacy/base.html
index a2c38fef7..da19741cb 100644
--- a/searx/templates/legacy/base.html
+++ b/searx/templates/legacy/base.html
@@ -17,7 +17,7 @@
{% endblock %}
{% block meta %}{% endblock %}
{% block head %}
- <link title="searx" type="application/opensearchdescription+xml" rel="search" href="{{ url_for('opensearch') }}"/>
+ <link title="{{ instance_name }}" type="application/opensearchdescription+xml" rel="search" href="{{ url_for('opensearch') }}"/>
{% endblock %}
</head>
<body>
diff --git a/searx/templates/oscar/macros.html b/searx/templates/oscar/macros.html
index 06881db02..221300fe4 100644
--- a/searx/templates/oscar/macros.html
+++ b/searx/templates/oscar/macros.html
@@ -33,6 +33,9 @@
<span class="label label-default">{{ engine }}</span>
{% endfor %}
<small>{{ result_link("https://web.archive.org/web/" + result.url, icon('link') + _('cached'), "text-info") }}</small>
+ {% if proxify %}
+ <small>{{ result_link(proxify(result.url), icon('sort') + _('proxied'), "text-info") }}</small>
+ {% endif %}
</div>
<div class="text-muted"><small>{{ result.pretty_url }}</small></div>
{%- endmacro %}
@@ -44,6 +47,9 @@
<span class="label label-default">{{ engine }}</span>
{% endfor %}
<small>{{ result_link("https://web.archive.org/web/" + result.url, icon('link') + _('cached'), "text-info") }}</small>
+ {% if proxify %}
+ <small>{{ result_link(proxify(result.url), icon('sort') + _('proxied'), "text-info") }}</small>
+ {% endif %}
<div class="text-muted"><small>{{ result.pretty_url }}</small></div>
{%- endmacro %}
diff --git a/searx/utils.py b/searx/utils.py
index b3806d3fd..5039fa975 100644
--- a/searx/utils.py
+++ b/searx/utils.py
@@ -252,12 +252,27 @@ def get_torrent_size(filesize, filesize_multiplier):
filesize = int(filesize * 1024 * 1024)
elif filesize_multiplier == 'KB':
filesize = int(filesize * 1024)
+ elif filesize_multiplier == 'TiB':
+ filesize = int(filesize * 1000 * 1000 * 1000 * 1000)
+ elif filesize_multiplier == 'GiB':
+ filesize = int(filesize * 1000 * 1000 * 1000)
+ elif filesize_multiplier == 'MiB':
+ filesize = int(filesize * 1000 * 1000)
+ elif filesize_multiplier == 'KiB':
+ filesize = int(filesize * 1000)
except:
filesize = None
return filesize
+def convert_str_to_int(number_str):
+ if number_str.isdigit():
+ return int(number_str)
+ else:
+ return 0
+
+
def is_valid_lang(lang):
is_abbr = (len(lang) == 2)
if is_abbr:
diff --git a/searx/webapp.py b/searx/webapp.py
index 5bdbc71a6..6c2b98c9c 100644
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -22,10 +22,11 @@ if __name__ == '__main__':
from os.path import realpath, dirname
path.append(realpath(dirname(realpath(__file__)) + '/../'))
-import json
import cStringIO
-import os
import hashlib
+import hmac
+import json
+import os
import requests
from searx import logger
@@ -242,6 +243,20 @@ def url_for_theme(endpoint, override_theme=None, **values):
return url_for(endpoint, **values)
+def proxify(url):
+ if url.startswith('//'):
+ url = 'https:' + url
+
+ if not settings.get('result_proxy'):
+ return url
+
+ h = hmac.new(settings['result_proxy']['key'], url.encode('utf-8'), hashlib.sha256).hexdigest()
+
+ return '{0}?{1}'.format(settings['result_proxy']['url'],
+ urlencode(dict(mortyurl=url.encode('utf-8'),
+ mortyhash=h)))
+
+
def image_proxify(url):
if url.startswith('//'):
@@ -250,8 +265,7 @@ def image_proxify(url):
if not request.preferences.get_value('image_proxy'):
return url
- hash_string = url + settings['server']['secret_key']
- h = hashlib.sha256(hash_string.encode('utf-8')).hexdigest()
+ h = hmac.new(settings['server']['secret_key'], url.encode('utf-8'), hashlib.sha256).hexdigest()
return '{0}?{1}'.format(url_for('image_proxy'),
urlencode(dict(url=url.encode('utf-8'), h=h)))
@@ -310,6 +324,8 @@ def render(template_name, override_theme=None, **kwargs):
kwargs['image_proxify'] = image_proxify
+ kwargs['proxify'] = proxify if settings.get('result_proxy') else None
+
kwargs['get_result_template'] = get_result_template
kwargs['theme'] = get_current_theme_name(override=override_theme)
@@ -599,7 +615,7 @@ def image_proxy():
if not url:
return '', 400
- h = hashlib.sha256(url + settings['server']['secret_key'].encode('utf-8')).hexdigest()
+ h = hmac.new(settings['server']['secret_key'], url, hashlib.sha256).hexdigest()
if h != request.args.get('h'):
return '', 400