.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.wikicommons Namespace Reference

Functions

 request (query, params)
 
 response (resp)
 

Variables

dict about
 
list categories = ['images']
 
str search_type = 'images'
 
str base_url = "https://commons.wikimedia.org"
 
tuple search_prefix
 
bool paging = True
 
int number_of_results = 10
 
dict search_types
 

Detailed Description

Wikimedia Commons (images)

Function Documentation

◆ request()

searx.engines.wikicommons.request ( query,
params )

Definition at line 46 of file wikicommons.py.

46def request(query, params):
47 language = 'en'
48 if params['language'] != 'all':
49 language = params['language'].split('-')[0]
50
51 if search_type not in search_types:
52 raise ValueError(f"Unsupported search type: {search_type}")
53
54 filetype = search_types[search_type]
55
56 args = {
57 'uselang': language,
58 'gsrlimit': number_of_results,
59 'gsroffset': number_of_results * (params["pageno"] - 1),
60 'gsrsearch': f"filetype:{filetype} {query}",
61 }
62
63 params["url"] = f"{base_url}/w/api.php{search_prefix}&{urlencode(args, safe=':|')}"
64 return params
65
66

◆ response()

searx.engines.wikicommons.response ( resp)

Definition at line 67 of file wikicommons.py.

67def response(resp):
68 results = []
69 json = resp.json()
70
71 if not json.get("query", {}).get("pages"):
72 return results
73 for item in json["query"]["pages"].values():
74 imageinfo = item["imageinfo"][0]
75 title = item["title"].replace("File:", "").rsplit('.', 1)[0]
76 result = {
77 'url': imageinfo["descriptionurl"],
78 'title': title,
79 'content': html_to_text(item["snippet"]),
80 }
81
82 if search_type == "images":
83 result['template'] = 'images.html'
84 result['img_src'] = imageinfo["url"]
85 result['thumbnail_src'] = imageinfo["thumburl"]
86 result['resolution'] = f'{imageinfo["width"]} x {imageinfo["height"]}'
87 else:
88 result['thumbnail'] = imageinfo["thumburl"]
89
90 if search_type == "videos":
91 result['template'] = 'videos.html'
92 if imageinfo.get('duration'):
93 result['length'] = datetime.timedelta(seconds=int(imageinfo['duration']))
94 result['iframe_src'] = imageinfo['url']
95 elif search_type == "files":
96 result['template'] = 'files.html'
97 result['metadata'] = imageinfo['mime']
98 result['size'] = humanize_bytes(imageinfo['size'])
99 elif search_type == "audio":
100 result['iframe_src'] = imageinfo['url']
101
102 results.append(result)
103
104 return results

Variable Documentation

◆ about

dict searx.engines.wikicommons.about
Initial value:
1= {
2 "website": 'https://commons.wikimedia.org/',
3 "wikidata_id": 'Q565',
4 "official_api_documentation": 'https://commons.wikimedia.org/w/api.php',
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": 'JSON',
8}

Definition at line 13 of file wikicommons.py.

◆ base_url

str searx.engines.wikicommons.base_url = "https://commons.wikimedia.org"

Definition at line 24 of file wikicommons.py.

◆ categories

list searx.engines.wikicommons.categories = ['images']

Definition at line 21 of file wikicommons.py.

◆ number_of_results

int searx.engines.wikicommons.number_of_results = 10

Definition at line 36 of file wikicommons.py.

◆ paging

bool searx.engines.wikicommons.paging = True

Definition at line 35 of file wikicommons.py.

◆ search_prefix

tuple searx.engines.wikicommons.search_prefix
Initial value:
1= (
2 '?action=query'
3 '&format=json'
4 '&generator=search'
5 '&gsrnamespace=6'
6 '&gsrprop=snippet'
7 '&prop=info|imageinfo'
8 '&iiprop=url|size|mime'
9 '&iiurlheight=180' # needed for the thumb url
10)

Definition at line 25 of file wikicommons.py.

◆ search_type

str searx.engines.wikicommons.search_type = 'images'

Definition at line 22 of file wikicommons.py.

◆ search_types

dict searx.engines.wikicommons.search_types
Initial value:
1= {
2 'images': 'bitmap|drawing',
3 'videos': 'video',
4 'audio': 'audio',
5 'files': 'multimedia|office|archive|3d',
6}

Definition at line 38 of file wikicommons.py.