.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
deezer.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""
3 Deezer (Music)
4"""
5
6from json import loads
7from urllib.parse import urlencode
8
9# about
10about = {
11 "website": 'https://deezer.com',
12 "wikidata_id": 'Q602243',
13 "official_api_documentation": 'https://developers.deezer.com/',
14 "use_official_api": True,
15 "require_api_key": False,
16 "results": 'JSON',
17}
18
19# engine dependent config
20categories = ['music']
21paging = True
22
23# search-url
24url = 'https://api.deezer.com/'
25search_url = url + 'search?{query}&index={offset}'
26iframe_src = "https://www.deezer.com/plugins/player?type=tracks&id={audioid}"
27
28
29# do search-request
30def request(query, params):
31 offset = (params['pageno'] - 1) * 25
32
33 params['url'] = search_url.format(query=urlencode({'q': query}), offset=offset)
34
35 return params
36
37
38# get response from search-request
39def response(resp):
40 results = []
41
42 search_res = loads(resp.text)
43
44 # parse results
45 for result in search_res.get('data', []):
46 if result['type'] == 'track':
47 title = result['title']
48 url = result['link'] # pylint: disable=redefined-outer-name
49
50 if url.startswith('http://'):
51 url = 'https' + url[4:]
52
53 content = '{} - {} - {}'.format(result['artist']['name'], result['album']['title'], result['title'])
54
55 # append result
56 results.append(
57 {'url': url, 'title': title, 'iframe_src': iframe_src.format(audioid=result['id']), 'content': content}
58 )
59
60 # return results
61 return results
request(query, params)
Definition deezer.py:30