.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
moviepilot.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Moviepilot is a German movie database, similar to IMDB or TMDB. It doesn't
3have any official API, but it uses JSON requests internally to fetch search
4results and suggestions, that's being used in this implementation.
5
6Moviepilot additionally allows to discover movies by certain categories
7or filters, hence we provide the following syntax:
8
9- Any normal search query -> Fetch search results by the query
10
11- A query containing one of the category identifiers ``fsk``, ``genre``,
12 ``jahr``, ``jahrzent``, ``land``, ``online``, ``stimmung`` will be used to
13 search trending items by the provided filters, which are appended to the
14 filter category after a ``-``.
15
16Search examples:
17
18- Normal: ``!mp Tom Cruise``
19- By filter: ``!mp person-Ryan-Gosling``
20- By filter: ``!mp fsk-0 land-deutschland genre-actionfilm``
21- By filter: ``!mp jahrzehnt-2020er online-netflix``
22
23For a list of all public filters, observe the url path when browsing
24
25- https://www.moviepilot.de/filme/beste.
26
27"""
28
29from urllib.parse import urlencode
30from searx.utils import html_to_text
31
32about = {
33 'website': "https://www.moviepilot.de",
34 'official_api_documentation': None,
35 'use_official_api': False,
36 'require_api_key': False,
37 'results': 'JSON',
38 'language': 'de',
39}
40paging = True
41categories = ["movies"]
42
43base_url = "https://www.moviepilot.de"
44image_url = "https://assets.cdn.moviepilot.de/files/{image_id}/fill/155/223/{filename}"
45
46filter_types = ["fsk", "genre", "jahr", "jahrzehnt", "land", "online", "stimmung", "person"]
47
48
49def request(query, params):
50 query_parts = query.split(" ")
51
52 discovery_filters = []
53 for query_part in query_parts:
54 filter_category_and_value = query_part.split("-", 1)
55
56 if len(filter_category_and_value) < 2:
57 continue
58
59 filter_category = filter_category_and_value[0]
60
61 if filter_category in filter_types:
62 discovery_filters.append(query_part)
63
64 params['discovery'] = len(discovery_filters) != 0
65
66 if params['discovery']:
67 args = {
68 'page': params['pageno'],
69 'order': 'beste',
70 }
71 params["url"] = f"{base_url}/api/discovery?{urlencode(args)}"
72 for discovery_filter in discovery_filters:
73 params["url"] += f"&filters[]={discovery_filter}"
74 else:
75 args = {
76 'q': query,
77 'page': params['pageno'],
78 'type': 'suggest',
79 }
80 params["url"] = f"{base_url}/api/search?{urlencode(args)}"
81
82 return params
83
84
85def response(resp):
86 results = []
87
88 json = resp.json()
89
90 json_results = []
91
92 if resp.search_params['discovery']:
93 json_results = json['results']
94 else:
95 json_results = json
96
97 for result in json_results:
98 item = {'title': result['title']}
99
100 if resp.search_params['discovery']:
101 content_list = [result.get(x) for x in ['abstract', 'summary']]
102 item['url'] = base_url + result['path']
103 item['content'] = html_to_text(' | '.join([x for x in content_list if x]))
104 item['metadata'] = html_to_text(result.get('meta_short', ''))
105
106 if result.get('image'):
107 item['img_src'] = image_url.format(image_id=result['image'], filename=result['image_filename'])
108 else:
109 item['url'] = result['url']
110 item['content'] = ', '.join([result['class'], result['info'], result['more']])
111 item['img_src'] = result['image']
112
113 results.append(item)
114
115 return results
request(query, params)
Definition moviepilot.py:49