Repository: searx/searx

Issue:
Add SepiaSearch
Here's the search engine: https://sepiasearch.org/

Here's its source code: https://framagit.org/framasoft/peertube/search-index/

They also wrote an article about it: https://framablog.org/2020/09/22/sepia-search-our-search-engine-to-promote-peertube/


Discussion:
Here is a snippet one can add to his `settings.yml` to use Sepia Search

      - name : sepia search
        engine : json_engine
        search_url : https://sepiasearch.org/api/v1/search/videos?search={query}&nsfw=false&start={pageno}&count=20&sort=-match
        paging: True
        page_size: 20
        url_query : url
        title_query : name
        content_query : description
        categories : videos
        shortcut : sep

This is however missing fields for e.g. thumbnail, views, or date. Which are all provided by the Sepia Search API but not jet implemented in `json_engine.py`. Here is a little table with the missing information:

| field | JSON query |
|---|---|
| thumbnail | thumbnailUrl |
| date | publishedAt |
| author | account.displayName |
| views | views |

@dalf Maybe those fields should be added to the `json_engine`?

Edit: Fix some typos
I see that there are a lot filters:
* NSFW
* date range
* language
* not in searx: license, time length

It would be better to create a new engine.

Resolving patch:
diff --git a/searx/engines/sepiasearch.py b/searx/engines/sepiasearch.py
new file mode 100644
--- /dev/null
+++ b/searx/engines/sepiasearch.py
@@ -0,0 +1,97 @@
+# SepiaSearch (Videos)
+#
+# @website     https://sepiasearch.org
+# @provide-api https://framagit.org/framasoft/peertube/search-index/-/tree/master/server/controllers/api
+# @using-api   yes
+# @results     JSON
+# @stable      yes
+# @parse       url, title, content, publishedDate, thumbnail
+
+from json import loads
+from dateutil import parser, relativedelta
+from urllib.parse import urlencode
+from datetime import datetime
+
+categories = ['videos']
+paging = True
+language_support = True
+time_range_support = True
+safesearch = True
+supported_languages = [
+    'en', 'fr', 'ja', 'eu', 'ca', 'cs', 'eo', 'el',
+    'de', 'it', 'nl', 'es', 'oc', 'gd', 'zh', 'pt',
+    'sv', 'pl', 'fi', 'ru'
+]
+base_url = 'https://sepiasearch.org/api/v1/search/videos'
+
+safesearch_table = {
+    0: 'both',
+    1: 'false',
+    2: 'false'
+}
+
+time_range_table = {
+    'day': relativedelta.relativedelta(),
+    'week': relativedelta.relativedelta(weeks=-1),
+    'month': relativedelta.relativedelta(months=-1),
+    'year': relativedelta.relativedelta(years=-1)
+}
+
+
+embedded_url = '<iframe width="540" height="304" src="{url}" frameborder="0" allowfullscreen></iframe>'
+
+
+def minute_to_hm(minute):
+    if isinstance(minute, int):
+        return "%d:%02d" % (divmod(minute, 60))
+    return None
+
+
+def request(query, params):
+    params['url'] = base_url + '?' + urlencode({
+        'search': query,
+        'start': (params['pageno'] - 1) * 10,
+        'count': 10,
+        'sort': '-match',
+        'nsfw': safesearch_table[params['safesearch']]
+    })
+
+    language = params['language'].split('-')[0]
+    if language in supported_languages:
+        params['url'] += '&languageOneOf[]=' + language
+    if params['time_range'] in time_range_table:
+        time = datetime.now().date() + time_range_table[params['time_range']]
+        params['url'] += '&startDate=' + time.isoformat()
+
+    return params
+
+
+def response(resp):
+    results = []
+
+    search_results = loads(resp.text)
+
+    if 'data' not in search_results:
+        return []
+
+    for result in search_results['data']:
+        title = result['name']
+        content = result['description']
+        thumbnail = result['thumbnailUrl']
+        publishedDate = parser.parse(result['publishedAt'])
+        embedded = embedded_url.format(url=result.get('embedUrl'))
+        author = result.get('account', {}).get('displayName')
+        length = minute_to_hm(result.get('duration'))
+        url = result['url']
+
+        results.append({'url': url,
+                        'title': title,
+                        'content': content,
+                        'author': author,
+                        'length': length,
+                        'template': 'videos.html',
+                        'publishedDate': publishedDate,
+                        'embedded': embedded,
+                        'thumbnail': thumbnail})
+
+    return results


Test patch: