2"""SensCritique (movies)
4from __future__
import annotations
6from json
import dumps, loads
7from typing
import Any, Optional
11 "website":
'https://www.senscritique.com/',
12 "wikidata_id":
'Q16676060',
13 "official_api_documentation":
None,
14 "use_official_api":
False,
15 "require_api_key":
False,
20categories = [
'movies']
23graphql_url =
'https://apollo.senscritique.com/'
25graphql_query =
"""query SearchProductExplorer($query: String, $offset: Int, $limit: Int,
26 $sortBy: SearchProductExplorerSort) {
27 searchProductExplorer(
64def request(query: str, params: dict[str, Any]) -> dict[str, Any]:
65 offset = (params[
'pageno'] - 1) * page_size
68 "operationName":
"SearchProductExplorer",
69 "variables": {
"offset": offset,
"limit": page_size,
"query": query,
"sortBy":
"RELEVANCE"},
70 "query": graphql_query,
73 params[
'url'] = graphql_url
74 params[
'method'] =
'POST'
75 params[
'headers'][
'Content-Type'] =
'application/json'
76 params[
'data'] = dumps(data)
83 response_data = loads(resp.text)
85 items = response_data.get(
'data', {}).get(
'searchProductExplorer', {}).get(
'items', [])
93 res.add(result=result)
98def parse_item(item: dict[str, Any]) -> MainResult |
None:
99 """Parse a single item from the SensCritique API response"""
100 title = item.get(
'title',
'')
103 year = item.get(
'yearOfProduction')
104 original_title = item.get(
'originalTitle')
107 if item.get(
'medias', {})
and item[
'medias'].get(
'picture'):
108 thumbnail = item[
'medias'][
'picture']
111 url = f
"https://www.senscritique.com{item['url']}"
115 title=title + (f
' ({year})' if year
else ''),
116 content=
' | '.join(content_parts),
122 """Build the content parts for an item"""
125 if item.get(
'category'):
126 content_parts.append(item[
'category'])
128 if original_title
and original_title != title:
129 content_parts.append(f
"Original title: {original_title}")
131 if item.get(
'directors'):
132 directors = [director[
'name']
for director
in item[
'directors']]
133 content_parts.append(f
"Director(s): {', '.join(directors)}")
135 if item.get(
'countries'):
136 countries = [country[
'name']
for country
in item[
'countries']]
137 content_parts.append(f
"Country: {', '.join(countries)}")
139 if item.get(
'genresInfos'):
140 genres = [genre[
'label']
for genre
in item[
'genresInfos']]
141 content_parts.append(f
"Genre(s): {', '.join(genres)}")
143 if item.get(
'duration'):
144 minutes = item[
'duration'] // 60
146 content_parts.append(f
"Duration: {minutes} min")
148 if item.get(
'rating')
and item.get(
'stats', {}).get(
'ratingCount'):
149 content_parts.append(f
"Rating: {item['rating']}/10 ({item['stats']['ratingCount']} votes)")
EngineResults response(resp)
dict[str, Any] request(str query, dict[str, Any] params)
list[str] build_content_parts(dict[str, Any] item, str title, Optional[str] original_title)
MainResult|None parse_item(dict[str, Any] item)