.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
"""
3
Freesound (Sound)
4
"""
5
6
from
json
import
loads
7
from
urllib.parse
import
urlencode
8
from
datetime
import
datetime
9
10
disabled =
True
11
api_key =
""
12
13
# about
14
about = {
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
24
paging =
True
25
26
# search url
27
url =
"https://freesound.org/apiv2/"
28
search_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
34
def
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
44
def
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
searx.engines.freesound.request
request(query, params)
Definition
freesound.py:34
searx.engines.freesound.response
response(resp)
Definition
freesound.py:44
searxng
searx
engines
freesound.py
Generated on Sat Nov 16 2024 00:10:57 for .oO SearXNG Developer Documentation Oo. by
1.12.0