.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
imdb.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""IMDB - Internet Movie Database
3
4Retrieves results from a basic search. Advanced search options are not
5supported. IMDB's API is undocumented, here are some posts about:
6
7- https://stackoverflow.com/questions/1966503/does-imdb-provide-an-api
8- https://rapidapi.com/blog/how-to-use-imdb-api/
9
10An alternative that needs IMDPro_ is `IMDb and Box Office Mojo
11<https://developer.imdb.com/documentation>`_
12
13.. __IMDPro: https://pro.imdb.com/login
14
15"""
16
17import json
18
19about = {
20 "website": 'https://imdb.com/',
21 "wikidata_id": 'Q37312',
22 "official_api_documentation": None,
23 "use_official_api": False,
24 "require_api_key": False,
25 "results": 'HTML',
26}
27
28categories = ["movies"]
29paging = False
30
31# suggestion_url = "https://sg.media-imdb.com/suggestion/{letter}/{query}.json"
32suggestion_url = "https://v2.sg.media-imdb.com/suggestion/{letter}/{query}.json"
33
34href_base = 'https://imdb.com/{category}/{entry_id}'
35
36search_categories = {"nm": "name", "tt": "title", "kw": "keyword", "co": "company", "ep": "episode"}
37
38
39def request(query, params):
40
41 query = query.replace(" ", "_").lower()
42 params['url'] = suggestion_url.format(letter=query[0], query=query)
43
44 return params
45
46
47def response(resp):
48
49 suggestions = json.loads(resp.text)
50 results = []
51
52 for entry in suggestions.get('d', []):
53
54 # https://developer.imdb.com/documentation/key-concepts#imdb-ids
55 entry_id = entry['id']
56 categ = search_categories.get(entry_id[:2])
57 if categ is None:
58 logger.error('skip unknown category tag %s in %s', entry_id[:2], entry_id)
59 continue
60
61 title = entry['l']
62 if 'q' in entry:
63 title += " (%s)" % entry['q']
64
65 content = ''
66 if 'rank' in entry:
67 content += "(%s) " % entry['rank']
68 if 'y' in entry:
69 content += str(entry['y']) + " - "
70 if 's' in entry:
71 content += entry['s']
72
73 # imageUrl is the image itself, it is not a thumb!
74 image_url = entry.get('i', {}).get('imageUrl')
75 if image_url:
76 # get thumbnail
77 image_url_name, image_url_prefix = image_url.rsplit('.', 1)
78 # recipe to get the magic value:
79 # * search on imdb.com, look at the URL of the thumbnail on the right side of the screen
80 # * search using the imdb engine, compare the imageUrl and thumbnail URL
81 # QL75 : JPEG quality (?)
82 # UX280 : resize to width 320
83 # 280,414 : size of the image (add white border)
84 magic = 'QL75_UX280_CR0,0,280,414_'
85 if not image_url_name.endswith('_V1_'):
86 magic = '_V1_' + magic
87 image_url = image_url_name + magic + '.' + image_url_prefix
88 results.append(
89 {
90 "title": title,
91 "url": href_base.format(category=categ, entry_id=entry_id),
92 "content": content,
93 "img_src": image_url,
94 }
95 )
96
97 return results
response(resp)
Definition imdb.py:47
request(query, params)
Definition imdb.py:39