2023-08-10 17:36:59 +02:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
# lint: pylint
|
2023-08-14 18:30:11 +02:00
|
|
|
"""seekr.com Seeker Score
|
|
|
|
|
|
|
|
Seekr is a privately held search and content evaluation engine that prioritizes
|
|
|
|
credibility over popularity.
|
|
|
|
|
|
|
|
Configuration
|
|
|
|
=============
|
|
|
|
|
|
|
|
The engine has the following additional settings:
|
|
|
|
|
|
|
|
- :py:obj:`seekr_category`
|
|
|
|
- :py:obj:`api_key`
|
|
|
|
|
|
|
|
This implementation is used by seekr engines in the :ref:`settings.yml
|
|
|
|
<settings engine>`:
|
|
|
|
|
|
|
|
.. code:: yaml
|
|
|
|
|
|
|
|
- name: seekr news
|
|
|
|
seekr_category: news
|
|
|
|
...
|
|
|
|
- name: seekr images
|
|
|
|
seekr_category: images
|
|
|
|
...
|
|
|
|
- name: seekr videos
|
|
|
|
seekr_category: videos
|
|
|
|
...
|
|
|
|
|
|
|
|
Known Quirks
|
|
|
|
============
|
|
|
|
|
|
|
|
The implementation to support :py:obj:`paging <searx.enginelib.Engine.paging>`
|
|
|
|
is based on the *nextpage* method of Seekr's REST API. This feature is *next
|
|
|
|
page driven* and plays well with the :ref:`infinite_scroll <settings ui>`
|
|
|
|
setting in SearXNG but it does not really fit into SearXNG's UI to select a page
|
|
|
|
by number.
|
|
|
|
|
|
|
|
Implementations
|
|
|
|
===============
|
|
|
|
|
2023-08-10 17:36:59 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
from json import loads
|
|
|
|
from urllib.parse import urlencode
|
2023-08-14 18:30:11 +02:00
|
|
|
from flask_babel import gettext
|
2023-08-10 17:36:59 +02:00
|
|
|
|
|
|
|
about = {
|
|
|
|
"website": 'https://seekr.com/',
|
|
|
|
"official_api_documentation": None,
|
2023-08-14 18:30:11 +02:00
|
|
|
"use_official_api": False,
|
2023-08-10 17:36:59 +02:00
|
|
|
"require_api_key": True,
|
|
|
|
"results": 'JSON',
|
2023-08-14 18:30:11 +02:00
|
|
|
"language": 'en',
|
2023-08-10 17:36:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
base_url = "https://api.seekr.com"
|
2023-08-14 18:30:11 +02:00
|
|
|
paging = True
|
|
|
|
|
2023-08-10 17:36:59 +02:00
|
|
|
api_key = "srh1-22fb-sekr"
|
2023-08-14 18:30:11 +02:00
|
|
|
"""API key / reversed engineered / is still the same one since 2022."""
|
|
|
|
|
|
|
|
seekr_category: str = 'unset'
|
|
|
|
"""Search category, any of ``news``, ``videos`` or ``images``."""
|
|
|
|
|
|
|
|
|
|
|
|
def init(engine_settings):
|
|
|
|
|
|
|
|
# global paging
|
|
|
|
if engine_settings['seekr_category'] not in ['news', 'videos', 'images']:
|
|
|
|
raise ValueError(f"Unsupported seekr category: {engine_settings['seekr_category']}")
|
2023-08-10 17:36:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
def request(query, params):
|
2023-08-14 18:30:11 +02:00
|
|
|
|
|
|
|
if not query:
|
|
|
|
return None
|
|
|
|
|
2023-08-10 17:36:59 +02:00
|
|
|
args = {
|
|
|
|
'query': query,
|
|
|
|
'apiKey': api_key,
|
|
|
|
}
|
|
|
|
|
2023-08-14 18:30:11 +02:00
|
|
|
api_url = base_url + '/engine'
|
|
|
|
if seekr_category == 'news':
|
|
|
|
api_url += '/v2/newssearch'
|
|
|
|
|
|
|
|
elif seekr_category == 'images':
|
|
|
|
api_url += '/imagetab'
|
|
|
|
|
|
|
|
elif seekr_category == 'videos':
|
|
|
|
api_url += '/videotab'
|
2023-08-10 17:36:59 +02:00
|
|
|
|
2023-08-14 18:30:11 +02:00
|
|
|
params['url'] = f"{api_url}?{urlencode(args)}"
|
|
|
|
if params['pageno'] > 1:
|
|
|
|
nextpage = params['engine_data'].get('nextpage')
|
|
|
|
if nextpage:
|
|
|
|
params['url'] = nextpage
|
2023-08-10 17:36:59 +02:00
|
|
|
|
|
|
|
return params
|
|
|
|
|
|
|
|
|
|
|
|
def _images_response(json):
|
2023-08-14 18:30:11 +02:00
|
|
|
|
|
|
|
search_results = json.get('expertResponses')
|
|
|
|
if search_results:
|
|
|
|
search_results = search_results[0].get('advice')
|
|
|
|
else: # response from a 'nextResultSet'
|
|
|
|
search_results = json.get('advice')
|
|
|
|
|
2023-08-10 17:36:59 +02:00
|
|
|
results = []
|
2023-08-14 18:30:11 +02:00
|
|
|
if not search_results:
|
|
|
|
return results
|
2023-08-10 17:36:59 +02:00
|
|
|
|
2023-08-14 18:30:11 +02:00
|
|
|
for result in search_results['results']:
|
2023-08-10 17:36:59 +02:00
|
|
|
summary = loads(result['summary'])
|
|
|
|
results.append(
|
|
|
|
{
|
|
|
|
'template': 'images.html',
|
|
|
|
'url': summary['refererurl'],
|
|
|
|
'title': result['title'],
|
|
|
|
'img_src': result['url'],
|
|
|
|
'img_format': f"{summary['width']}x{summary['height']}",
|
2023-08-14 18:30:11 +02:00
|
|
|
'thumbnail_src': 'https://media.seekr.com/engine/rp/' + summary['tg'] + '/?src= ' + result['thumbnail'],
|
2023-08-10 17:36:59 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-08-14 18:30:11 +02:00
|
|
|
if search_results.get('nextResultSet'):
|
|
|
|
results.append(
|
|
|
|
{
|
|
|
|
"engine_data": search_results.get('nextResultSet'),
|
|
|
|
"key": "nextpage",
|
|
|
|
}
|
|
|
|
)
|
2023-08-10 17:36:59 +02:00
|
|
|
return results
|
|
|
|
|
|
|
|
|
|
|
|
def _videos_response(json):
|
2023-08-14 18:30:11 +02:00
|
|
|
|
|
|
|
search_results = json.get('expertResponses')
|
|
|
|
if search_results:
|
|
|
|
search_results = search_results[0].get('advice')
|
|
|
|
else: # response from a 'nextResultSet'
|
|
|
|
search_results = json.get('advice')
|
|
|
|
|
2023-08-10 17:36:59 +02:00
|
|
|
results = []
|
2023-08-14 18:30:11 +02:00
|
|
|
if not search_results:
|
|
|
|
return results
|
2023-08-10 17:36:59 +02:00
|
|
|
|
2023-08-14 18:30:11 +02:00
|
|
|
for result in search_results['results']:
|
|
|
|
summary = loads(result['summary'])
|
2023-08-10 17:36:59 +02:00
|
|
|
results.append(
|
|
|
|
{
|
|
|
|
'template': 'videos.html',
|
|
|
|
'url': result['url'],
|
|
|
|
'title': result['title'],
|
2023-08-14 18:30:11 +02:00
|
|
|
'thumbnail': 'https://media.seekr.com/engine/rp/' + summary['tg'] + '/?src= ' + result['thumbnail'],
|
2023-08-10 17:36:59 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-08-14 18:30:11 +02:00
|
|
|
if search_results.get('nextResultSet'):
|
|
|
|
results.append(
|
|
|
|
{
|
|
|
|
"engine_data": search_results.get('nextResultSet'),
|
|
|
|
"key": "nextpage",
|
|
|
|
}
|
|
|
|
)
|
2023-08-10 17:36:59 +02:00
|
|
|
return results
|
|
|
|
|
|
|
|
|
|
|
|
def _news_response(json):
|
2023-08-14 18:30:11 +02:00
|
|
|
|
|
|
|
search_results = json.get('expertResponses')
|
|
|
|
if search_results:
|
|
|
|
search_results = search_results[0]['advice']['categorySearchResult']['searchResult']
|
|
|
|
else: # response from a 'nextResultSet'
|
|
|
|
search_results = json.get('advice')
|
|
|
|
|
2023-08-10 17:36:59 +02:00
|
|
|
results = []
|
2023-08-14 18:30:11 +02:00
|
|
|
if not search_results:
|
|
|
|
return results
|
|
|
|
|
|
|
|
for result in search_results['results']:
|
2023-08-10 17:36:59 +02:00
|
|
|
|
|
|
|
results.append(
|
|
|
|
{
|
|
|
|
'url': result['url'],
|
|
|
|
'title': result['title'],
|
2023-08-14 18:30:11 +02:00
|
|
|
'content': result['summary'] or result["topCategory"] or result["displayUrl"] or '',
|
2023-08-10 17:36:59 +02:00
|
|
|
'thumbnail': result.get('thumbnail', ''),
|
|
|
|
'publishedDate': datetime.strptime(result['pubDate'][:19], '%Y-%m-%d %H:%M:%S'),
|
2023-08-14 18:30:11 +02:00
|
|
|
'metadata': gettext("Language") + ': ' + result.get('language', ''),
|
2023-08-10 17:36:59 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-08-14 18:30:11 +02:00
|
|
|
if search_results.get('nextResultSet'):
|
|
|
|
results.append(
|
|
|
|
{
|
|
|
|
"engine_data": search_results.get('nextResultSet'),
|
|
|
|
"key": "nextpage",
|
|
|
|
}
|
|
|
|
)
|
2023-08-10 17:36:59 +02:00
|
|
|
return results
|
|
|
|
|
|
|
|
|
|
|
|
def response(resp):
|
|
|
|
json = resp.json()
|
|
|
|
|
2023-08-14 18:30:11 +02:00
|
|
|
if seekr_category == "videos":
|
2023-08-10 17:36:59 +02:00
|
|
|
return _videos_response(json)
|
2023-08-14 18:30:11 +02:00
|
|
|
if seekr_category == "images":
|
2023-08-10 17:36:59 +02:00
|
|
|
return _images_response(json)
|
2023-08-14 18:30:11 +02:00
|
|
|
if seekr_category == "news":
|
2023-08-10 17:36:59 +02:00
|
|
|
return _news_response(json)
|
|
|
|
|
2023-08-14 18:30:11 +02:00
|
|
|
raise ValueError(f"Unsupported seekr category: {seekr_category}")
|