.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 44 of file wikicommons.py.

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

◆ response()

searx.engines.wikicommons.response ( resp)

Definition at line 65 of file wikicommons.py.

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

◆ base_url

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

Definition at line 22 of file wikicommons.py.

◆ categories

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

Definition at line 19 of file wikicommons.py.

◆ number_of_results

int searx.engines.wikicommons.number_of_results = 10

Definition at line 34 of file wikicommons.py.

◆ paging

bool searx.engines.wikicommons.paging = True

Definition at line 33 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 23 of file wikicommons.py.

◆ search_type

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

Definition at line 20 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 36 of file wikicommons.py.