diff options
| -rw-r--r-- | Dockerfile | 4 | ||||
| -rwxr-xr-x | dockerfiles/docker-entrypoint.sh | 3 | ||||
| -rw-r--r-- | docs/admin/installation-searx.rst | 2 | ||||
| -rw-r--r-- | searx/engines/bandcamp.py | 73 | ||||
| -rw-r--r-- | searx/engines/google.py | 2 | ||||
| -rw-r--r-- | searx/settings.yml | 5 | ||||
| -rw-r--r-- | searx/static/themes/oscar/img/icons/bandcamp.png | bin | 0 -> 919 bytes | |||
| -rw-r--r-- | searx/templates/oscar/result_templates/default.html | 4 | ||||
| -rwxr-xr-x | searx_extra/standalone_searx.py | 2 | ||||
| -rwxr-xr-x | utils/searx.sh | 2 |
10 files changed, 87 insertions, 10 deletions
diff --git a/Dockerfile b/Dockerfile index d1a5632b5..3fbf62f35 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,9 @@ ENV INSTANCE_NAME=searx \ AUTOCOMPLETE= \ BASE_URL= \ MORTY_KEY= \ - MORTY_URL= + MORTY_URL= \ + SEARX_SETTINGS_PATH=/etc/searx/settings.yml \ + UWSGI_SETTINGS_PATH=/etc/searx/uwsgi.ini WORKDIR /usr/local/searx diff --git a/dockerfiles/docker-entrypoint.sh b/dockerfiles/docker-entrypoint.sh index accc015f7..6592b1c70 100755 --- a/dockerfiles/docker-entrypoint.sh +++ b/dockerfiles/docker-entrypoint.sh @@ -24,9 +24,6 @@ if [ -z "${BIND_ADDRESS}" ]; then export BIND_ADDRESS="${DEFAULT_BIND_ADDRESS}" fi -export UWSGI_SETTINGS_PATH=/etc/searx/uwsgi.ini -export SEARX_SETTINGS_PATH=/etc/searx/settings.yml - # Parse special command line # see docs/admin/installation-docker.rst # display the help message without the version diff --git a/docs/admin/installation-searx.rst b/docs/admin/installation-searx.rst index 512a185a7..adea0166f 100644 --- a/docs/admin/installation-searx.rst +++ b/docs/admin/installation-searx.rst @@ -61,7 +61,7 @@ from the login (*~/.profile*): .. tip:: - Open a second terminal for the configuration tasks and left the ``(searx)$`` + Open a second terminal for the configuration tasks and leave the ``(searx)$`` terminal open for the tasks below. diff --git a/searx/engines/bandcamp.py b/searx/engines/bandcamp.py new file mode 100644 index 000000000..dafb3ee16 --- /dev/null +++ b/searx/engines/bandcamp.py @@ -0,0 +1,73 @@ +""" +Bandcamp (Music) + +@website https://bandcamp.com/ +@provide-api no +@results HTML +@parse url, title, content, publishedDate, embedded, thumbnail +""" + +from urllib.parse import urlencode, urlparse, parse_qs +from dateutil.parser import parse as dateparse +from lxml import html +from searx.utils import extract_text + +categories = ['music'] +paging = True + +base_url = "https://bandcamp.com/" +search_string = search_string = 'search?{query}&page={page}' +embedded_url = '''<iframe width="100%" height="166" + scrolling="no" frameborder="no" + data-src="https://bandcamp.com/EmbeddedPlayer/{type}={result_id}/size=large/bgcol=ffffff/linkcol=0687f5/tracklist=false/artwork=small/transparent=true/" +></iframe>''' + + +def request(query, params): + '''pre-request callback + params<dict>: + method : POST/GET + headers : {} + data : {} # if method == POST + url : '' + category: 'search category' + pageno : 1 # number of the requested page + ''' + + search_path = search_string.format( + query=urlencode({'q': query}), + page=params['pageno']) + + params['url'] = base_url + search_path + + return params + + +def response(resp): + '''post-response callback + resp: requests response object + ''' + results = [] + tree = html.fromstring(resp.text) + search_results = tree.xpath('//li[contains(@class, "searchresult")]') + for result in search_results: + link = result.xpath('.//div[@class="itemurl"]/a')[0] + result_id = parse_qs(urlparse(link.get('href')).query)["search_item_id"][0] + title = result.xpath('.//div[@class="heading"]/a/text()') + date = dateparse(result.xpath('//div[@class="released"]/text()')[0].replace("released ", "")) + content = result.xpath('.//div[@class="subhead"]/text()') + new_result = { + "url": extract_text(link), + "title": extract_text(title), + "content": extract_text(content), + "publishedDate": date, + } + thumbnail = result.xpath('.//div[@class="art"]/img/@src') + if thumbnail: + new_result['thumbnail'] = thumbnail[0] + if "album" in result.classes: + new_result["embedded"] = embedded_url.format(type='album', result_id=result_id) + elif "track" in result.classes: + new_result["embedded"] = embedded_url.format(type='track', result_id=result_id) + results.append(new_result) + return results diff --git a/searx/engines/google.py b/searx/engines/google.py index 8c20029a3..8f5b700eb 100644 --- a/searx/engines/google.py +++ b/searx/engines/google.py @@ -243,7 +243,7 @@ def response(resp): if answer: results.append({'answer': ' '.join(answer)}) else: - logger.debug("did not found 'answer'") + logger.debug("did not find 'answer'") # results --> number_of_results try: diff --git a/searx/settings.yml b/searx/settings.yml index 8f2e50bc9..dde2e249c 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -197,6 +197,11 @@ engines: # engine : base # shortcut : bs + - name: bandcamp + engine: bandcamp + shortcut: bc + categories: music + - name : wikipedia engine : wikipedia shortcut : wp diff --git a/searx/static/themes/oscar/img/icons/bandcamp.png b/searx/static/themes/oscar/img/icons/bandcamp.png Binary files differnew file mode 100644 index 000000000..2de405afe --- /dev/null +++ b/searx/static/themes/oscar/img/icons/bandcamp.png diff --git a/searx/templates/oscar/result_templates/default.html b/searx/templates/oscar/result_templates/default.html index d743f928e..53cfee5cb 100644 --- a/searx/templates/oscar/result_templates/default.html +++ b/searx/templates/oscar/result_templates/default.html @@ -13,10 +13,10 @@ </div> {%- endif -%} -{%- if result.img_src -%} +{%- if result.img_src or result.thumbnail -%} <div class="container-fluid">{{- "" -}} <div class="row">{{- "" -}} - <img src="{{ image_proxify(result.img_src) }}" title="{{ result.title|striptags }}" style="width: auto; max-height: 60px; min-height: 60px;" class="col-xs-2 col-sm-4 col-md-4 result-content"> + <img src="{{ image_proxify(result.img_src or result.thumbnail) }}" title="{{ result.title|striptags }}" style="width: auto; max-height: 60px; min-height: 60px;" class="col-xs-2 col-sm-4 col-md-4 result-content"> {%- if result.content %}<p class="result-content col-xs-8 col-sm-8 col-md-8">{{ result.content|safe }}</p>{% endif -%} </div>{{- "" -}} </div> diff --git a/searx_extra/standalone_searx.py b/searx_extra/standalone_searx.py index f52b7e80c..b30762d3f 100755 --- a/searx_extra/standalone_searx.py +++ b/searx_extra/standalone_searx.py @@ -31,7 +31,7 @@ Example to run it from python: ... engine_cs = list(searx.engines.categories.keys()) ... # load module ... spec = importlib.util.spec_from_file_location( -... 'utils.standalone_searx', 'utils/standalone_searx.py') +... 'utils.standalone_searx', 'searx_extra/standalone_searx.py') ... sas = importlib.util.module_from_spec(spec) ... spec.loader.exec_module(sas) ... # use function from module diff --git a/utils/searx.sh b/utils/searx.sh index ed015bdd2..d2dbe79b6 100755 --- a/utils/searx.sh +++ b/utils/searx.sh @@ -35,7 +35,7 @@ SERVICE_GROUP="${SERVICE_USER}" GIT_BRANCH="${GIT_BRANCH:-master}" SEARX_PYENV="${SERVICE_HOME}/searx-pyenv" SEARX_SRC="${SERVICE_HOME}/searx-src" -SEARX_SETTINGS_PATH="/etc/searx/settings.yml" +SEARX_SETTINGS_PATH="${SEARX_SETTINGS_PATH:-/etc/searx/settings.yml}" SEARX_SETTINGS_TEMPLATE="${SEARX_SETTINGS_TEMPLATE:-${REPO_ROOT}/utils/templates/etc/searx/use_default_settings.yml}" SEARX_UWSGI_APP="searx.ini" # shellcheck disable=SC2034 |