.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
yandex_music.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Yandex Music
3
4.. _Countries where Yandex.Music is available: https://yandex.com/support/music/access.html
5
6.. hint::
7
8 Access to music is limited to a few countries: `Countries where Yandex.Music
9 is available`_
10
11"""
12
13from urllib.parse import urlencode
14
15# about
16about = {
17 "website": 'https://music.yandex.ru',
18 "wikidata_id": 'Q4537983',
19 "official_api_documentation": None,
20 "use_official_api": False,
21 "require_api_key": False,
22 "results": 'JSON',
23}
24
25# engine dependent config
26categories = ['music']
27paging = True
28
29# search-url
30url = 'https://music.yandex.ru'
31search_url = url + '/handlers/music-search.jsx'
32
33
34# do search-request
35def request(query, params):
36 args = {'text': query, 'page': params['pageno'] - 1}
37 params['url'] = search_url + '?' + urlencode(args)
38
39 return params
40
41
42# get response from search-request
43def response(resp):
44 results = []
45 search_res = resp.json()
46
47 # parse results
48 for result in search_res.get('tracks', {}).get('items', []):
49 if result['type'] == 'music':
50 track_id = result['id']
51 album_id = result['albums'][0]['id']
52
53 # append result
54 results.append(
55 {
56 'url': f'{url}/album/{album_id}/track/{track_id}',
57 'title': result['title'],
58 'content': f"[{result['albums'][0]['title']}] {result['artists'][0]['name']} - {result['title']}",
59 'iframe_src': f'{url}/iframe/track/{track_id}/{album_id}',
60 }
61 )
62
63 return results