We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Wikimedia Commons
**Working URL to the engine**
https://commons.wikimedia.org

**Why do you want to add this engine?**
Out of all of the Wikimedia projects, Wikimedia Commons is one of only two to not appear in any engine category in SearXNG, with the other being Wikispecies.

**Features of this engine**
It has a collection of [82,886,704](https://commons.wikimedia.org/wiki/Special:Statistics) [freely usable](https://commons.wikimedia.org/wiki/Commons:Reusing_content_outside_Wikimedia) media files.

**How can SearXNG fetch the information from this engine?**
`https://commons.wikimedia.org/w/index.php?search=%s` with `%s` being what you want to search.

**Applicable category of this engine**
General, files, images, music, videos.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `searx/engines/wikicommons.py`
Content:
```
1 # SPDX-License-Identifier: AGPL-3.0-or-later
2 """Wikimedia Commons (images)
3 
4 """
5 
6 from urllib.parse import urlencode
7 
8 # about
9 about = {
10     "website": 'https://commons.wikimedia.org/',
11     "wikidata_id": 'Q565',
12     "official_api_documentation": 'https://commons.wikimedia.org/w/api.php',
13     "use_official_api": True,
14     "require_api_key": False,
15     "results": 'JSON',
16 }
17 
18 base_url = "https://commons.wikimedia.org"
19 search_prefix = (
20     '?action=query'
21     '&format=json'
22     '&generator=search'
23     '&gsrnamespace=6'
24     '&gsrprop=snippet'
25     '&prop=info|imageinfo'
26     '&iiprop=url|size|mime'
27     '&iiurlheight=180'  # needed for the thumb url
28 )
29 paging = True
30 number_of_results = 10
31 
32 
33 def request(query, params):
34     language = 'en'
35     if params['language'] != 'all':
36         language = params['language'].split('-')[0]
37 
38     args = {
39         'uselang': language,
40         'gsrlimit': number_of_results,
41         'gsroffset': number_of_results * (params["pageno"] - 1),
42         'gsrsearch': "filetype:bitmap|drawing " + query,
43     }
44 
45     params["url"] = f"{base_url}/w/api.php{search_prefix}&{urlencode(args, safe=':|')}"
46     return params
47 
48 
49 def response(resp):
50     results = []
51     json = resp.json()
52 
53     if not json.get("query", {}).get("pages"):
54         return results
55 
56     for item in json["query"]["pages"].values():
57         imageinfo = item["imageinfo"][0]
58         title = item["title"].replace("File:", "").rsplit('.', 1)[0]
59         result = {
60             'url': imageinfo["descriptionurl"],
61             'title': title,
62             'content': item["snippet"],
63             'img_src': imageinfo["url"],
64             'resolution': f'{imageinfo["width"]} x {imageinfo["height"]}',
65             'thumbnail_src': imageinfo["thumburl"],
66             'template': 'images.html',
67         }
68         results.append(result)
69 
70     return results
71
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/searx/engines/wikicommons.py b/searx/engines/wikicommons.py
--- a/searx/engines/wikicommons.py
+++ b/searx/engines/wikicommons.py
@@ -3,6 +3,8 @@
 
 """
 
+import datetime
+
 from urllib.parse import urlencode
 
 # about
@@ -14,6 +16,8 @@
     "require_api_key": False,
     "results": 'JSON',
 }
+categories = ['images']
+search_type = 'images'
 
 base_url = "https://commons.wikimedia.org"
 search_prefix = (
@@ -29,17 +33,29 @@
 paging = True
 number_of_results = 10
 
+search_types = {
+    'images': 'bitmap|drawing',
+    'videos': 'video',
+    'audio': 'audio',
+    'files': 'multimedia|office|archive|3d',
+}
+
 
 def request(query, params):
     language = 'en'
     if params['language'] != 'all':
         language = params['language'].split('-')[0]
 
+    if search_type not in search_types:
+        raise ValueError(f"Unsupported search type: {search_type}")
+
+    filetype = search_types[search_type]
+
     args = {
         'uselang': language,
         'gsrlimit': number_of_results,
         'gsroffset': number_of_results * (params["pageno"] - 1),
-        'gsrsearch': "filetype:bitmap|drawing " + query,
+        'gsrsearch': f"filetype:{filetype} {query}",
     }
 
     params["url"] = f"{base_url}/w/api.php{search_prefix}&{urlencode(args, safe=':|')}"
@@ -52,7 +68,6 @@
 
     if not json.get("query", {}).get("pages"):
         return results
-
     for item in json["query"]["pages"].values():
         imageinfo = item["imageinfo"][0]
         title = item["title"].replace("File:", "").rsplit('.', 1)[0]
@@ -60,11 +75,28 @@
             'url': imageinfo["descriptionurl"],
             'title': title,
             'content': item["snippet"],
-            'img_src': imageinfo["url"],
-            'resolution': f'{imageinfo["width"]} x {imageinfo["height"]}',
-            'thumbnail_src': imageinfo["thumburl"],
-            'template': 'images.html',
         }
+
+        if search_type == "images":
+            result['template'] = 'images.html'
+            result['img_src'] = imageinfo["url"]
+            result['thumbnail_src'] = imageinfo["thumburl"]
+            result['resolution'] = f'{imageinfo["width"]} x {imageinfo["height"]}'
+        else:
+            result['thumbnail'] = imageinfo["thumburl"]
+
+        if search_type == "videos":
+            result['template'] = 'videos.html'
+            if imageinfo.get('duration'):
+                result['length'] = datetime.timedelta(seconds=int(imageinfo['duration']))
+            result['iframe_src'] = imageinfo['url']
+        elif search_type == "files":
+            result['template'] = 'files.html'
+            result['metadata'] = imageinfo['mime']
+            result['size'] = imageinfo['size']
+        elif search_type == "audio":
+            result['iframe_src'] = imageinfo['url']
+
         results.append(result)
 
     return results

{"golden_diff": "diff --git a/searx/engines/wikicommons.py b/searx/engines/wikicommons.py\n--- a/searx/engines/wikicommons.py\n+++ b/searx/engines/wikicommons.py\n@@ -3,6 +3,8 @@\n \n \"\"\"\n \n+import datetime\n+\n from urllib.parse import urlencode\n \n # about\n@@ -14,6 +16,8 @@\n     \"require_api_key\": False,\n     \"results\": 'JSON',\n }\n+categories = ['images']\n+search_type = 'images'\n \n base_url = \"https://commons.wikimedia.org\"\n search_prefix = (\n@@ -29,17 +33,29 @@\n paging = True\n number_of_results = 10\n \n+search_types = {\n+    'images': 'bitmap|drawing',\n+    'videos': 'video',\n+    'audio': 'audio',\n+    'files': 'multimedia|office|archive|3d',\n+}\n+\n \n def request(query, params):\n     language = 'en'\n     if params['language'] != 'all':\n         language = params['language'].split('-')[0]\n \n+    if search_type not in search_types:\n+        raise ValueError(f\"Unsupported search type: {search_type}\")\n+\n+    filetype = search_types[search_type]\n+\n     args = {\n         'uselang': language,\n         'gsrlimit': number_of_results,\n         'gsroffset': number_of_results * (params[\"pageno\"] - 1),\n-        'gsrsearch': \"filetype:bitmap|drawing \" + query,\n+        'gsrsearch': f\"filetype:{filetype} {query}\",\n     }\n \n     params[\"url\"] = f\"{base_url}/w/api.php{search_prefix}&{urlencode(args, safe=':|')}\"\n@@ -52,7 +68,6 @@\n \n     if not json.get(\"query\", {}).get(\"pages\"):\n         return results\n-\n     for item in json[\"query\"][\"pages\"].values():\n         imageinfo = item[\"imageinfo\"][0]\n         title = item[\"title\"].replace(\"File:\", \"\").rsplit('.', 1)[0]\n@@ -60,11 +75,28 @@\n             'url': imageinfo[\"descriptionurl\"],\n             'title': title,\n             'content': item[\"snippet\"],\n-            'img_src': imageinfo[\"url\"],\n-            'resolution': f'{imageinfo[\"width\"]} x {imageinfo[\"height\"]}',\n-            'thumbnail_src': imageinfo[\"thumburl\"],\n-            'template': 'images.html',\n         }\n+\n+        if search_type == \"images\":\n+            result['template'] = 'images.html'\n+            result['img_src'] = imageinfo[\"url\"]\n+            result['thumbnail_src'] = imageinfo[\"thumburl\"]\n+            result['resolution'] = f'{imageinfo[\"width\"]} x {imageinfo[\"height\"]}'\n+        else:\n+            result['thumbnail'] = imageinfo[\"thumburl\"]\n+\n+        if search_type == \"videos\":\n+            result['template'] = 'videos.html'\n+            if imageinfo.get('duration'):\n+                result['length'] = datetime.timedelta(seconds=int(imageinfo['duration']))\n+            result['iframe_src'] = imageinfo['url']\n+        elif search_type == \"files\":\n+            result['template'] = 'files.html'\n+            result['metadata'] = imageinfo['mime']\n+            result['size'] = imageinfo['size']\n+        elif search_type == \"audio\":\n+            result['iframe_src'] = imageinfo['url']\n+\n         results.append(result)\n \n     return results\n", "issue": "Wikimedia Commons\n**Working URL to the engine**\r\nhttps://commons.wikimedia.org\r\n\r\n**Why do you want to add this engine?**\r\nOut of all of the Wikimedia projects, Wikimedia Commons is one of only two to not appear in any engine category in SearXNG, with the other being Wikispecies.\r\n\r\n**Features of this engine**\r\nIt has a collection of [82,886,704](https://commons.wikimedia.org/wiki/Special:Statistics) [freely usable](https://commons.wikimedia.org/wiki/Commons:Reusing_content_outside_Wikimedia) media files.\r\n\r\n**How can SearXNG fetch the information from this engine?**\r\n`https://commons.wikimedia.org/w/index.php?search=%s` with `%s` being what you want to search.\r\n\r\n**Applicable category of this engine**\r\nGeneral, files, images, music, videos.\n", "before_files": [{"content": "# SPDX-License-Identifier: AGPL-3.0-or-later\n\"\"\"Wikimedia Commons (images)\n\n\"\"\"\n\nfrom urllib.parse import urlencode\n\n# about\nabout = {\n    \"website\": 'https://commons.wikimedia.org/',\n    \"wikidata_id\": 'Q565',\n    \"official_api_documentation\": 'https://commons.wikimedia.org/w/api.php',\n    \"use_official_api\": True,\n    \"require_api_key\": False,\n    \"results\": 'JSON',\n}\n\nbase_url = \"https://commons.wikimedia.org\"\nsearch_prefix = (\n    '?action=query'\n    '&format=json'\n    '&generator=search'\n    '&gsrnamespace=6'\n    '&gsrprop=snippet'\n    '&prop=info|imageinfo'\n    '&iiprop=url|size|mime'\n    '&iiurlheight=180'  # needed for the thumb url\n)\npaging = True\nnumber_of_results = 10\n\n\ndef request(query, params):\n    language = 'en'\n    if params['language'] != 'all':\n        language = params['language'].split('-')[0]\n\n    args = {\n        'uselang': language,\n        'gsrlimit': number_of_results,\n        'gsroffset': number_of_results * (params[\"pageno\"] - 1),\n        'gsrsearch': \"filetype:bitmap|drawing \" + query,\n    }\n\n    params[\"url\"] = f\"{base_url}/w/api.php{search_prefix}&{urlencode(args, safe=':|')}\"\n    return params\n\n\ndef response(resp):\n    results = []\n    json = resp.json()\n\n    if not json.get(\"query\", {}).get(\"pages\"):\n        return results\n\n    for item in json[\"query\"][\"pages\"].values():\n        imageinfo = item[\"imageinfo\"][0]\n        title = item[\"title\"].replace(\"File:\", \"\").rsplit('.', 1)[0]\n        result = {\n            'url': imageinfo[\"descriptionurl\"],\n            'title': title,\n            'content': item[\"snippet\"],\n            'img_src': imageinfo[\"url\"],\n            'resolution': f'{imageinfo[\"width\"]} x {imageinfo[\"height\"]}',\n            'thumbnail_src': imageinfo[\"thumburl\"],\n            'template': 'images.html',\n        }\n        results.append(result)\n\n    return results\n", "path": "searx/engines/wikicommons.py"}], "after_files": [{"content": "# SPDX-License-Identifier: AGPL-3.0-or-later\n\"\"\"Wikimedia Commons (images)\n\n\"\"\"\n\nimport datetime\n\nfrom urllib.parse import urlencode\n\n# about\nabout = {\n    \"website\": 'https://commons.wikimedia.org/',\n    \"wikidata_id\": 'Q565',\n    \"official_api_documentation\": 'https://commons.wikimedia.org/w/api.php',\n    \"use_official_api\": True,\n    \"require_api_key\": False,\n    \"results\": 'JSON',\n}\ncategories = ['images']\nsearch_type = 'images'\n\nbase_url = \"https://commons.wikimedia.org\"\nsearch_prefix = (\n    '?action=query'\n    '&format=json'\n    '&generator=search'\n    '&gsrnamespace=6'\n    '&gsrprop=snippet'\n    '&prop=info|imageinfo'\n    '&iiprop=url|size|mime'\n    '&iiurlheight=180'  # needed for the thumb url\n)\npaging = True\nnumber_of_results = 10\n\nsearch_types = {\n    'images': 'bitmap|drawing',\n    'videos': 'video',\n    'audio': 'audio',\n    'files': 'multimedia|office|archive|3d',\n}\n\n\ndef request(query, params):\n    language = 'en'\n    if params['language'] != 'all':\n        language = params['language'].split('-')[0]\n\n    if search_type not in search_types:\n        raise ValueError(f\"Unsupported search type: {search_type}\")\n\n    filetype = search_types[search_type]\n\n    args = {\n        'uselang': language,\n        'gsrlimit': number_of_results,\n        'gsroffset': number_of_results * (params[\"pageno\"] - 1),\n        'gsrsearch': f\"filetype:{filetype} {query}\",\n    }\n\n    params[\"url\"] = f\"{base_url}/w/api.php{search_prefix}&{urlencode(args, safe=':|')}\"\n    return params\n\n\ndef response(resp):\n    results = []\n    json = resp.json()\n\n    if not json.get(\"query\", {}).get(\"pages\"):\n        return results\n    for item in json[\"query\"][\"pages\"].values():\n        imageinfo = item[\"imageinfo\"][0]\n        title = item[\"title\"].replace(\"File:\", \"\").rsplit('.', 1)[0]\n        result = {\n            'url': imageinfo[\"descriptionurl\"],\n            'title': title,\n            'content': item[\"snippet\"],\n        }\n\n        if search_type == \"images\":\n            result['template'] = 'images.html'\n            result['img_src'] = imageinfo[\"url\"]\n            result['thumbnail_src'] = imageinfo[\"thumburl\"]\n            result['resolution'] = f'{imageinfo[\"width\"]} x {imageinfo[\"height\"]}'\n        else:\n            result['thumbnail'] = imageinfo[\"thumburl\"]\n\n        if search_type == \"videos\":\n            result['template'] = 'videos.html'\n            if imageinfo.get('duration'):\n                result['length'] = datetime.timedelta(seconds=int(imageinfo['duration']))\n            result['iframe_src'] = imageinfo['url']\n        elif search_type == \"files\":\n            result['template'] = 'files.html'\n            result['metadata'] = imageinfo['mime']\n            result['size'] = imageinfo['size']\n        elif search_type == \"audio\":\n            result['iframe_src'] = imageinfo['url']\n\n        results.append(result)\n\n    return results\n", "path": "searx/engines/wikicommons.py"}]}