.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
freesound.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""
3Freesound (Sound)
4"""
5
6from json import loads
7from urllib.parse import urlencode
8from datetime import datetime
9
10disabled = True
11api_key = ""
12
13# about
14about = {
15 "website": "https://freesound.org",
16 "wikidata_id": "Q835703",
17 "official_api_documentation": "https://freesound.org/docs/api",
18 "use_official_api": True,
19 "require_api_key": True,
20 "results": "JSON",
21}
22
23# engine dependent config
24paging = True
25
26# search url
27url = "https://freesound.org/apiv2/"
28search_url = (
29 url + "search/text/?query={query}&page={page}&fields=name,url,download,created,description,type&token={api_key}"
30)
31
32
33# search request
34def request(query, params):
35 params["url"] = search_url.format(
36 query=urlencode({"q": query}),
37 page=params["pageno"],
38 api_key=api_key,
39 )
40 return params
41
42
43# get response from search request
44def response(resp):
45 results = []
46 search_res = loads(resp.text)
47 # parse results
48 for result in search_res.get("results", []):
49 title = result["name"]
50 content = result["description"][:128]
51 publishedDate = datetime.fromisoformat(result["created"])
52 uri = result["download"]
53
54 # append result
55 results.append(
56 {
57 "url": result["url"],
58 "title": title,
59 "publishedDate": publishedDate,
60 "audio_src": uri,
61 "content": content,
62 }
63 )
64
65 return results
request(query, params)
Definition freesound.py:34