Last active
February 12, 2026 07:19
-
-
Save sigsergv/ad4ffdb946b167597f2fdd10786c22db to your computer and use it in GitHub Desktop.
Open yandex music in desktop application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # Author: Sergey Stolyarov <sergei@regolit.com> | |
| # Source: https://gist.github.com/sigsergv/ad4ffdb946b167597f2fdd10786c22db | |
| # License: Public Domain | |
| # Instructions: | |
| # copy this file to $PATH and set executable bit | |
| # Supported URLs: | |
| # | |
| # * https://music.yandex.ru/album/40284270 | |
| # * https://music.yandex.ru/album/40284270/track/147367567 | |
| # * https://music.yandex.ru/artist/95154 | |
| # * https://music.yandex.ru/label/392738 | |
| # * https://music.yandex.ru/playlists/ar.b1c6c8ed-eab1-4293-8334-07b1faa46a49 | |
| # * https://music.yandex.ru/video?ids=149340 | |
| from sys import (argv, exit) | |
| from urllib.parse import urlparse | |
| import re | |
| import subprocess | |
| YM_BINARY = '/opt/Яндекс Музыка/yandexmusic' | |
| if len(argv) != 2: | |
| print('ERROR: Single URL required') | |
| exit(1) | |
| url = urlparse(argv[1]) | |
| if url.hostname != 'music.yandex.ru': | |
| print('ERROR: Not yandex music URL') | |
| exit(1) | |
| ym_uri = None | |
| mo = re.match('^(?:/album/[0-9]+|/album/[0-9]+/track/[0-9]+|/artist/[0-9]+|/label/[0-9]+|/playlists/[0-9a-z.-]+)$', url.path) | |
| if mo is not None: | |
| ym_uri = f'yandexmusic:/{url.path}' | |
| print(ym_uri) | |
| if mo is None: | |
| if url.path == '/video' and re.match('^ids=[0-9]+$', url.query) is not None: | |
| ym_uri = f'yandexmusic://video?{url.query}' | |
| if ym_uri is not None: | |
| subprocess.Popen([YM_BINARY, ym_uri], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) | |
| # or alternative | |
| # subprocess.Popen(['/usr/bin/xdg-open', ym_uri], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) | |
| else: | |
| print('ERROR: not supported URL') | |
| exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment