diff --git a/searx/engines/yandex_music.py b/searx/engines/yandex_music.py new file mode 100644 index 000000000..b44a5992e --- /dev/null +++ b/searx/engines/yandex_music.py @@ -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 diff --git a/searx/settings.yml b/searx/settings.yml index 6847db53d..f56536ec0 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -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