summaryrefslogtreecommitdiff
path: root/searx
diff options
context:
space:
mode:
authorPaul Alcock <25768075+Guilvareux@users.noreply.github.com>2021-09-22 01:55:09 +0100
committerMarkus Heiser <markus.heiser@darmarit.de>2021-10-03 11:44:25 +0200
commit823d44ed0a267335fce4d6ae172a4342e7439d7b (patch)
tree2d8a475700a0e85f3523977f290ce877aa400ba0 /searx
parente39a03cc61e9792afb34084fb4d9973a61deecea (diff)
downloadsearxng-823d44ed0a267335fce4d6ae172a4342e7439d7b.tar.gz
searxng-823d44ed0a267335fce4d6ae172a4342e7439d7b.zip
[mod] engines - add IMDB / Internet Movie Database
Merged from @Guilvareux's commit [1] and slightly modfied / see [2]. [1] https://github.com/searx/searx/pull/2980/commits/f2f90071 [2] https://github.com/searx/searx/pull/2980
Diffstat (limited to 'searx')
-rw-r--r--searx/engines/imdb.py95
-rw-r--r--searx/settings.yml6
2 files changed, 101 insertions, 0 deletions
diff --git a/searx/engines/imdb.py b/searx/engines/imdb.py
new file mode 100644
index 000000000..88913ddc6
--- /dev/null
+++ b/searx/engines/imdb.py
@@ -0,0 +1,95 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+# lint: pylint
+
+"""IMDB - Internet Movie Database
+
+Retrieves results from a basic search. Advanced search options are not
+supported. IMDB's API is undocumented, here are some posts about:
+
+- https://stackoverflow.com/questions/1966503/does-imdb-provide-an-api
+- https://rapidapi.com/blog/how-to-use-imdb-api/
+
+An alternative that needs IMDPro_ is `IMDb and Box Office Mojo
+<https://developer.imdb.com/documentation>`_
+
+.. __IMDPro: https://pro.imdb.com/login
+
+"""
+
+import json
+
+about = {
+ "website": 'https://imdb.com/',
+ "wikidata_id": 'Q37312',
+ "official_api_documentation": None,
+ "use_official_api": False,
+ "require_api_key": False,
+ "results": 'HTML',
+}
+
+categories = ['general', ]
+paging = False
+
+# suggestion_url = "https://sg.media-imdb.com/suggestion/{letter}/{query}.json"
+suggestion_url = "https://v2.sg.media-imdb.com/suggestion/{letter}/{query}.json"
+
+href_base = 'https://imdb.com/{category}/{entry_id}'
+
+search_categories = {
+ "nm": "name",
+ "tt": "title",
+ "kw": "keyword",
+ "co": "company",
+ "ep": "episode"
+}
+
+
+def request(query, params):
+
+ query = query.replace(" ", "_").lower()
+ params['url'] = suggestion_url.format(letter=query[0], query=query)
+
+ return params
+
+
+def response(resp):
+
+ suggestions = json.loads(resp.text)
+ results = []
+
+ for entry in suggestions['d']:
+
+ # https://developer.imdb.com/documentation/key-concepts#imdb-ids
+ entry_id = entry['id']
+ categ = search_categories.get(entry_id[:2])
+ if categ is None:
+ logger.error(
+ 'skip unknown category tag %s in %s', entry_id[:2], entry_id
+ )
+ continue
+
+ title = entry['l']
+ if 'q' in entry:
+ title += " (%s)" % entry['q']
+
+ content = ''
+ if 'rank' in entry:
+ content += "(%s) " % entry['rank']
+ if 'y' in entry:
+ content += str(entry['y']) + " - "
+ if 's' in entry:
+ content += entry['s']
+
+ # imageUrl is the image itself, it is not a thumb!
+ # image_url = entry['i']['imageUrl']
+
+ results.append({
+ "title": title,
+ "url": href_base.format(category=categ, entry_id=entry_id),
+ "content": content,
+ # "thumbnail" : image_url,
+ # "template": "videos.html",
+
+ })
+
+ return results
diff --git a/searx/settings.yml b/searx/settings.yml
index 207024192..cce70ac53 100644
--- a/searx/settings.yml
+++ b/searx/settings.yml
@@ -744,6 +744,12 @@ engines:
require_api_key: false
results: JSON
+ - name: imdb
+ engine: imdb
+ shortcut: imdb
+ timeout: 6.0
+ disabled: true
+
- name: ina
engine: ina
shortcut: in