logo

searx

Unnamed repository; edit this file 'description' to name the repository.
commit: d88e2d89354ce1176694108fec44e4b608fbf40b
parent: 4d94a26734fae49f0f63c3efa4c08861dd3332f9
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun, 27 Aug 2017 17:14:42 +0200

Still too lazy for proper commit message

Diffstat:

searx/engines/nyaa.py | 4++--
searx/engines/pantsu.py | 46++++++++++++++++++++++++++++++++++++++++++++++
searx/settings.yml | 11+++++++----
searx/static/themes/simple/css/searx.min.css | 56++++++++++++++++++++++++++++++++++++++++++++++----------
searx/templates/simple/base.html | 4----
searx/templates/simple/categories.html | 4+---
searx/templates/simple/macros.html | 11+----------
searx/templates/simple/messages/no_results.html | 3+--
searx/templates/simple/preferences.html | 2+-
searx/templates/simple/result_templates/default.html | 3---
searx/templates/simple/result_templates/map.html | 8++++----
searx/templates/simple/result_templates/torrent.html | 4++--
searx/templates/simple/results.html | 52+++++++++++++++++++++++-----------------------------
13 files changed, 134 insertions(+), 74 deletions(-)

diff --git a/searx/engines/nyaa.py b/searx/engines/nyaa.py @@ -18,8 +18,8 @@ categories = ['files', 'images', 'videos', 'music'] paging = True # search-url -base_url = 'http://www.nyaa.se/' -search_url = base_url + '?page=search&{query}&offset={offset}' +base_url = 'http://www.nyaa.si/' +search_url = base_url + '?q={query}&p={offset}' # xpath queries xpath_results = '//table[@class="tlist"]//tr[contains(@class, "tlistrow")]' diff --git a/searx/engines/pantsu.py b/searx/engines/pantsu.py @@ -0,0 +1,46 @@ +""" + Nyaa Pantsu (Anime Bittorrent tracker) + + @website https://nyaa.pantsu.cat/ + @provide-api yes (https://nyaa.pantsu.cat/apidoc/) + @using-api yes + @stable yes (using API) + @parse url, title, content, seed, leech, magnetlink +""" +from json import loads +from searx.url_utils import urlencode + +# engine dependent config +categories = ['files', 'images', 'videos', 'music'] + +# search-url +base_url = 'https://nyaa.pantsu.cat/' +search_url = base_url + 'api/search?${query}' + +def request(query, params): + params['url'] = search_url.format(query=urlencode({'q': query, 'sort': '5'})) + return params + +def response(resp): + results = [] + + search_res = loads(resp.text) + + if 'torrents' not in search_res: + return [] + + for res in search_res['torrents']: + url = base_url + 'view/' + str(res['id']) + + results.append({ + 'url': url, + 'title': res['name'], + 'content': res['description'][:500], + 'seed': res['seeders'], + 'leech': res['leechers'], + 'magnetlink': res['magnet'], + 'torrentfile': res['torrent'], + 'template': 'torrent.html' + }) + + return results diff --git a/searx/settings.yml b/searx/settings.yml @@ -3,8 +3,8 @@ general: instance_name : "searx" # displayed name search: - safe_search : 0 # Filter results. 0: None, 1: Moderate, 2: Strict - autocomplete : "" # Existing autocomplete backends: "dbpedia", "duckduckgo", "google", "startpage", "wikipedia" - leave blank to turn it off by default + safe_search : 1 # Filter results. 0: None, 1: Moderate, 2: Strict + autocomplete : "duckduckgo" # Existing autocomplete backends: "dbpedia", "duckduckgo", "google", "startpage", "wikipedia" - leave blank to turn it off by default language : "all" server: @@ -18,7 +18,7 @@ server: ui: static_path : "" # Custom static path - leave it blank if you didn't change templates_path : "" # Custom templates path - leave it blank if you didn't change - default_theme : oscar # ui theme + default_theme : simple # 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 @@ -404,6 +404,10 @@ engines: engine : mixcloud shortcut : mc + - name : pantsu + engine : pantsu + shortcut : npc + - name : nyaa engine : nyaa shortcut : nt @@ -439,7 +443,6 @@ engines: - name : piratebay engine : piratebay shortcut : tpb - url: https://pirateproxy.red/ timeout : 3.0 - name : qwant diff --git a/searx/static/themes/simple/css/searx.min.css b/searx/static/themes/simple/css/searx.min.css @@ -2,32 +2,64 @@ html, body { background-color: #002b36; color: #839496; } -main, #main, #search, #main_results { +#main, #main_results { display: table; margin: auto; } +#search { + display: flex; + margin: auto 15%; + flex-direction: column; + max-width: 80em; +} +#search > * { + display: flex; + flex-direction: row; + /* width: 100%; */ +} +#search > * > * { + flex: auto; + margin: .1em .5em; +} +#search #safesearch, #search #send_search { + flex: 1; +} +#search #q { + flex: 4; + min-width: 30ch; +} #results { display: table; margin-left: auto; } +#pagination_prev { + float: left; +} +#pagination_next { + float: right; +} code, pre { font-family: monospace; background: #073642; word-break: break-all; word-wrap: break-word; } -nav { - font-size: x-large; +#linkto_preferences { position: absolute; + font-size: x-large; } header { - text-align: center; font-size: xx-large; color: #3498DB; - margin: .5em; font-weight: bold; } -nav a, header a { +footer, header { + margin: .5em; + text-align: center; + vertical-align: center; +} +a { + color: #3498DB; text-decoration: none; } input, button, select { @@ -57,7 +89,7 @@ p { #categories div { display: inline-block; } -categories_container, #search_main, #search_filters { +#search_main, #search_filters { display: flex; } @@ -72,6 +104,10 @@ categories_container, #search_main, #search_filters { } .tabs label, #categories label { padding: 0 1em; + margin: 0 .5em; + flex-grow: 1; + display: block; + text-align: center; } #apis div { @@ -85,9 +121,6 @@ categories_container, #search_main, #search_filters { .engines span, .url a, .url span { margin: 0 .25em; } -.left { - float: left; -} /*images*/ .result-images, .result-videos { @@ -149,4 +182,7 @@ img { } .tabs>input:checked~section { display: none; +} +.dialog-error strong { + color: orange; } \ No newline at end of file diff --git a/searx/templates/simple/base.html b/searx/templates/simple/base.html @@ -41,7 +41,6 @@ <main id="main_{{ self._TemplateReference__context.name|replace("simple/", "")|replace(".html", "") }}"> {% if errors %} <div class="dialog-error" role="alert"> - <a href="#" class="close" aria-label="close" title="close">×</a> <ul> {% for message in errors %} <li>{{ message }}</li> @@ -56,8 +55,5 @@ <footer> <p>{{ _('Powered by') }} <a href="{{ url_for('about') }}">searx</a> - {{ searx_version }} - {{ _('a privacy-respecting, hackable metasearch engine') }}</p> </footer> - <!--[if gte IE 9]>--> - <script src="{{ url_for('static', filename='js/searx.min.js') }}" ></script> - <!--<![endif]--> </body> </html> diff --git a/searx/templates/simple/categories.html b/searx/templates/simple/categories.html @@ -1,8 +1,6 @@ <div id="categories">{{- '' -}} - <div id="categories_container"> {%- for category in categories -%} <div class="category"><input type="checkbox" id="checkbox_{{ category|replace(' ', '_') }}" name="category_{{ category }}"{% if category in selected_categories %} checked="checked"{% endif %}/><label for="checkbox_{{ category|replace(' ', '_') }}" class="tooltips">{{ _(category) }}</label></div> {%- endfor -%} {%- if display_tooltip %}<div class="help">{{ _('Click on the magnifier to perform search') }}</div>{% endif -%} - </div>{{- '' -}} -</div> +{{- '' -}}</div> diff --git a/searx/templates/simple/macros.html b/searx/templates/simple/macros.html @@ -1,12 +1,3 @@ -<!-- Draw glyphicon icon from bootstrap-theme --> -{% macro icon(action) -%} - <span class="ion-icon-big ion-{{ action }}"></span> -{%- endmacro %} - -{% macro icon_small(action) -%} - <span class="ion-icon ion-{{ action }}"></span> -{%- endmacro %} - <!-- Draw favicon --> <!-- TODO: using url_for methode --> {% macro draw_favicon(favicon) -%} @@ -41,7 +32,7 @@ <!-- Draw result sub footer --> {%- macro result_sub_footer(result, proxify) -%} <div class="engines">{% for engine in result.engines %}<span>{{ engine }}</span>{% endfor %}</div>{{- '' -}} -<p class="url"><span class="url">{{ result.pretty_url }}</span>{{ result_link("https://web.archive.org/web/" + result.url, icon('link') + _('cached'), "cache_link") }}&lrm; {% if proxify %} {{ result_link(proxify(result.url), icon('link') + _('proxied'), "proxyfied_link") }} {% endif %}</p>{{- '' -}} +<p class="url"><span class="url">{{ result.pretty_url }}</span>{{ result_link("https://web.archive.org/web/" + result.url, "🔗" + _('cached'), "cache_link") }}&lrm; {% if proxify %} {{ result_link(proxify(result.url), "🔗" + _('proxied'), "proxyfied_link") }} {% endif %}</p>{{- '' -}} <div class="break"></div>{{- '' -}} {%- endmacro -%} diff --git a/searx/templates/simple/messages/no_results.html b/searx/templates/simple/messages/no_results.html @@ -1,4 +1,3 @@ -{% from 'simple/macros.html' import icon %} {% if unresponsive_engines %} <div class="dialog-error" role="alert"> <p><strong>{{ _('Error!') }}</strong> {{ _('Engines cannot retrieve results.') }}</p> @@ -7,7 +6,7 @@ {{ engine_name }} ({{ error_type }}){% if not loop.last %}, {% endif %} {% endfor %} </p> - <p><small>{{ _('Please, try again later or find another searx instance.') }}</small></p> + <p>{{ _('Please, try again later or find another searx instance.') }}</p> </div> {% else %} <div class="dialog-error" role="alert"> diff --git a/searx/templates/simple/preferences.html b/searx/templates/simple/preferences.html @@ -95,7 +95,7 @@ {% if not search_engine.private %} {% set engine_id = 'engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_') %} <tr> - <td class="engine_checkbox">{{ checkbox_onoff(engine_id, (search_engine.name, categ) in disabled_engines) }}</td> + <td class="engine_checkbox">{{ checkbox_onoff(engine_id, (search_engine.name, categ) in enabled_engines) }}</td> <th class="name">{{ search_engine.name }}</th> <td class="shortcut">{{ shortcuts[search_engine.name] }}</td> <td>{{ checkbox(engine_id + '_supported_languages', current_language == 'all' or current_language in search_engine.supported_languages or current_language.split('-')[0] in search_engine.supported_languages, true, true) }}</td> diff --git a/searx/templates/simple/result_templates/default.html b/searx/templates/simple/result_templates/default.html @@ -2,9 +2,6 @@ {{ result_header(result, favicons, image_proxify) -}} {{- result_sub_header(result) -}} -{% if result.embedded -%} -<p class="altlink"> &bull; <a class="btn-collapse collapsed media-loader disabled_if_nojs" data-target="#result-media-{{ index }}" data-btn-text-collapsed="{{ _('show media') }}" data-btn-text-not-collapsed="{{ _('hide media') }}">{{ icon('music-note') }} {{ _('show media') }}</a></p> -{%- endif %} <p class="content"> {%- if result.content %}{{ result.content|safe }}{% endif -%} </p> diff --git a/searx/templates/simple/result_templates/map.html b/searx/templates/simple/result_templates/map.html @@ -1,18 +1,18 @@ -{% from 'simple/macros.html' import result_header, result_sub_header, result_sub_footer, result_footer, result_footer_rtl, icon %} +{% from 'simple/macros.html' import result_header, result_sub_header, result_sub_footer, result_footer, result_footer_rtl %} {{ result_header(result, favicons, image_proxify) -}} {{- result_sub_header(result) -}} {%- if (result.latitude and result.longitude) or result.boundingbox -%} - <small> &bull; <a class="btn-collapse collapsed searx_init_map hide_if_nojs" data-target="#result-map-{{ index }}" data-btn-text-collapsed="{{ _('show map') }}" data-btn-text-not-collapsed="{{ _('hide map') }}" data-leaflet-target="osm-map-{{ index }}" data-map-lon="{{ result.longitude }}" data-map-lat="{{ result.latitude }}" {% if result.boundingbox %}data-map-boundingbox='{{ result.boundingbox|tojson|safe }}'{% endif %} {% if result.geojson %}data-map-geojson='{{ result.geojson|tojson|safe }}'{% endif %}>{{ icon( 'globe') }} {{ _('show map') }}</a></small> + <small> &bull; <a class="btn-collapse collapsed searx_init_map hide_if_nojs" data-target="#result-map-{{ index }}" data-btn-text-collapsed="{{ _('show map') }}" data-btn-text-not-collapsed="{{ _('hide map') }}" data-leaflet-target="osm-map-{{ index }}" data-map-lon="{{ result.longitude }}" data-map-lat="{{ result.latitude }}" {% if result.boundingbox %}data-map-boundingbox='{{ result.boundingbox|tojson|safe }}'{% endif %} {% if result.geojson %}data-map-geojson='{{ result.geojson|tojson|safe }}'{% endif %}>🌐 {{ _('show map') }}</a></small> {%- endif -%} {%- if result.osm and (result.osm.type and result.osm.id) -%} - <small> &bull; <a class="btn-collapse collapsed hide_if_nojs searx_overpass_request" data-target="#result-overpass-{{ index }}" data-btn-text-collapsed="{{ _('show details') }}" data-btn-text-not-collapsed="{{ _('hide details') }}" data-osm-type="{{ result.osm.type }}" data-osm-id="{{ result.osm.id }}" data-result-table="result-overpass-table-{{ index }}" data-result-table-loadicon="result-overpass-table-loading-{{ index }}">{{ icon('location') }} {{ _('show details') }}</a></small> + <small> &bull; <a class="btn-collapse collapsed hide_if_nojs searx_overpass_request" data-target="#result-overpass-{{ index }}" data-btn-text-collapsed="{{ _('show details') }}" data-btn-text-not-collapsed="{{ _('hide details') }}" data-osm-type="{{ result.osm.type }}" data-osm-id="{{ result.osm.id }}" data-result-table="result-overpass-table-{{ index }}" data-result-table-loadicon="result-overpass-table-loading-{{ index }}">📍 {{ _('show details') }}</a></small> {%- endif -%} {#- {% if (result.latitude and result.longitude) %} - <small> &bull; <a class="btn-collapse disabled_if_nojs" data-target="#result-geodata-{{ index }}" data-btn-text-collapsed="{{ _('show geodata') }}" data-btn-text-not-collapsed="{{ _('hide geodata') }}">{{ icon('location') }} {{ _('show geodata') }}</a></small> + <small> &bull; <a class="btn-collapse disabled_if_nojs" data-target="#result-geodata-{{ index }}" data-btn-text-collapsed="{{ _('show geodata') }}" data-btn-text-not-collapsed="{{ _('hide geodata') }}">📍 {{ _('show geodata') }}</a></small> {% endif %} -#} diff --git a/searx/templates/simple/result_templates/torrent.html b/searx/templates/simple/result_templates/torrent.html @@ -3,8 +3,8 @@ {{ result_header(result, favicons, image_proxify) -}} {{- result_sub_header(result) -}} <ul> -{% if result.magnetlink %}<li class="result_magnetlink">{{ result_link(result.magnetlink, icon('magnet') + _('magnet link'), "magnetlink") }}</li>{% endif %} -{% if result.torrentfile %}<li class="result_torrentfile">{{ result_link(result.torrentfile, icon('download-alt') + _('torrent file'), "torrentfile") }}</li>{% endif %} +{% if result.magnetlink %}<li class="result_magnetlink">{{ result_link(result.magnetlink, "" + _('magnet link'), "magnetlink") }}</li>{% endif %} +{% if result.torrentfile %}<li class="result_torrentfile">{{ result_link(result.torrentfile, "⬇️" + _('torrent file'), "torrentfile") }}</li>{% endif %} {% if result.seed %}<li class="result_seed">{{ _('Seeder') }} {{ result.seed }}</li>{% endif %} {% if result.leech %}<li class="result_leech">{{ _('Leecher') }} {{ result.leech }}</li>{% endif %} {%- if result.filesize %}<li class="result_filesize">{{ _('Filesize') }} diff --git a/searx/templates/simple/results.html b/searx/templates/simple/results.html @@ -1,9 +1,7 @@ {% extends "simple/base.html" %} -{% from 'simple/macros.html' import icon, icon_small %} {% block title %}{{ q|e }} - {% endblock %} {% block meta %}<link rel="alternate" type="application/rss+xml" title="Searx search: {{ q|e }}" href="{{ url_for('index') }}?q={{ q|urlencode }}&amp;categories={{ selected_categories|join(",") | replace(' ','+') }}&amp;pageno={{ pageno }}&amp;time_range={{ time_range }}&amp;language={{ current_language }}&amp;safesearch={{ safesearch }}&amp;format=rss">{% endblock %} {% block content %} -<nav id="linkto_preferences"><a href="{{ url_for('preferences') }}">{{ icon('navicon-round') }}</a></nav> {% include 'simple/search.html' %} <div id="results"> {% if answers %} @@ -110,39 +108,35 @@ {% endif %} </div> <div id="backToTop"> - <a href="#">{{ icon_small('chevron-up') }}</a> + <a href="#">⏫</a> </div> {% if paging %} <nav id="pagination"> {% if pageno > 1 %} - <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}"> - <div class="{% if rtl %}right{% else %}left{% endif %}"> - <input type="hidden" name="q" value="{{ q|e }}" > - {% for category in selected_categories %} - <input type="hidden" name="category_{{ category }}" value="1" > - {% endfor %} - <input type="hidden" name="pageno" value="{{ pageno-1 }}" > - <input type="hidden" name="time_range" value="{{ time_range }}" > - <input type="hidden" name="language" value="{{ current_language }}" > - <input type="hidden" name="safesearch" value="{{ safesearch }}" > - <input type="hidden" name="theme" value="{{ theme }}" > - <button type="submit">{{ icon_small('chevron-left') }} {{ _('previous page') }}</button> - </div> + <form id="pagination_previous" method="{{ method or 'POST' }}" action="{{ url_for('index') }}"> + <input type="hidden" name="q" value="{{ q|e }}" > + {% for category in selected_categories %} + <input type="hidden" name="category_{{ category }}" value="1" > + {% endfor %} + <input type="hidden" name="pageno" value="{{ pageno-1 }}" > + <input type="hidden" name="time_range" value="{{ time_range }}" > + <input type="hidden" name="language" value="{{ current_language }}" > + <input type="hidden" name="safesearch" value="{{ safesearch }}" > + <input type="hidden" name="theme" value="{{ theme }}" > + <button type="submit">⏮️ {{ _('previous page') }}</button> </form> {% endif %} - <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}"> - <div class="{% if rtl %}left{% else %}right{% endif %}"> - <input type="hidden" name="q" value="{{ q|e }}" > - {% for category in selected_categories %} - <input type="hidden" name="category_{{ category }}" value="1" > - {% endfor %} - <input type="hidden" name="pageno" value="{{ pageno+1 }}" > - <input type="hidden" name="time_range" value="{{ time_range }}" > - <input type="hidden" name="language" value="{{ current_language }}" > - <input type="hidden" name="safesearch" value="{{ safesearch }}" > - <input type="hidden" name="theme" value="{{ theme }}" > - <button type="submit">{{ _('next page') }} {{ icon_small('chevron-right') }}</button> - </div> + <form id="pagination_next" method="{{ method or 'POST' }}" action="{{ url_for('index') }}"> + <input type="hidden" name="q" value="{{ q|e }}" > + {% for category in selected_categories %} + <input type="hidden" name="category_{{ category }}" value="1" > + {% endfor %} + <input type="hidden" name="pageno" value="{{ pageno+1 }}" > + <input type="hidden" name="time_range" value="{{ time_range }}" > + <input type="hidden" name="language" value="{{ current_language }}" > + <input type="hidden" name="safesearch" value="{{ safesearch }}" > + <input type="hidden" name="theme" value="{{ theme }}" > + <button type="submit">{{ _('next page') }} ⏭️</button> </form> </nav> {% endif %}