[feat] engine: implementation of yandex music

Access to music is limited to a few countries:

- https://yandex.com/support/music/access.html
This commit is contained in:
Xinos 2024-02-20 18:38:34 +07:00 committed by Markus Heiser
parent fb36a06acd
commit 3c42252c78
2 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,63 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
# lint: pylint
"""Yandex Music
.. _Countries where Yandex.Music is available: https://yandex.com/support/music/access.html
.. hint::
Access to music is limited to a few countries: `Countries where Yandex.Music
is available`_
"""
from urllib.parse import urlencode
# about
about = {
"website": 'https://music.yandex.ru',
"wikidata_id": 'Q4537983',
"official_api_documentation": None,
"use_official_api": False,
"require_api_key": False,
"results": 'JSON',
}
# engine dependent config
categories = ['music']
paging = True
# search-url
url = 'https://music.yandex.ru'
search_url = url + '/handlers/music-search.jsx'
# do search-request
def request(query, params):
args = {'text': query, 'page': params['pageno'] - 1}
params['url'] = search_url + '?' + urlencode(args)
return params
# get response from search-request
def response(resp):
results = []
search_res = resp.json()
# parse results
for result in search_res.get('tracks', {}).get('items', []):
if result['type'] == 'music':
track_id = result['id']
album_id = result['albums'][0]['id']
# append result
results.append(
{
'url': f'{url}/album/{album_id}/track/{track_id}',
'title': result['title'],
'content': f"[{result['albums'][0]['title']}] {result['artists'][0]['name']} - {result['title']}",
'iframe_src': f'{url}/iframe/track/{track_id}/{album_id}',
}
)
return results

View File

@ -1708,6 +1708,13 @@ engines:
engine: unsplash
shortcut: us
- name: yandex music
engine: yandex_music
shortcut: ydm
disabled: true
# https://yandex.com/support/music/access.html
inactive: true
- name: yahoo
engine: yahoo
shortcut: yh