📜 ⬆️ ⬇️

We fasten the multimedia keys in Yandeks.Radio

Not so long ago, I discovered the Yandex.Radio service for myself, and I use it quite successfully. But here's what's missing: the ability to turn on the next track or pause without switching to the tab.

My solution is under the cut.

There is Arch Linux, Firefox, i3wm and a keyboard with media keys.

1 Extension in Firefox


Probably, for Chrome, there is something similar, but good people have come up with a quite suitable extension, the essence of which is remote launch of javascript. After it is enabled, on the selected tab, Firefox opens port 32000, on which it receives and executes commands. It's pretty simple.
')
In this way:

$ netstat -ntpl | grep 32000 tcp 0 0 127.0.0.1:32000 0.0.0.0:* LISTEN 3687/firefox 

2 Script to send commands


Next, we make a script to send commands to the browser and place it, for example, in ~ / .opt / bin / radio.yandex.ru-client:

 #!/bin/bash case "$1" in playpause) CMD="Mu.Flow.togglePause();" ;; next) CMD="Mu.Flow.flow.next();" ;; esac echo $CMD | nc -c localhost 32000 exit 0 

3 Bind the media keys



Edit the i3wm ~ / .i3 / config configuration file:

 bindsym XF86AudioPlay exec ~/.opt/bin/radio.yandex.ru-client playpause bindsym XF86AudioNext exec ~/.opt/bin/radio.yandex.ru-client next 

There was no Next key on the keyboard, so I had to bind to Super + VolumeUp:

 bindsym $mod+XF86AudioRaiseVolume exec ~/.opt/bin/radio.yandex.ru-client next 

Attempt 2


In principle, this could have been completed, but the need to include the extension on this tab remained, and the extension seemed to me very interesting, but somewhat limiting.

Revision

There was not enough opportunity to access an arbitrary tab, for example, by name or by uri. The benefit of the extension is published on github. Next, fork -> developer.mozilla.org -> is done. There is a pull request, but for now the modified extension can be found here: raw.githubusercontent.com/irvinzz/FF-Remote-Control/master/remote_control-1.3-fx.xpi .

And, accordingly, an adapted script

 #!/bin/bash case "$1" in playpause) CMD='{"selector":{"uri":"https://radio.yandex.ru/"},"command":"Mu.Flow.togglePause();"}' ;; next) CMD='{"selector":{"uri":"https://radio.yandex.ru/"},"command":"Mu.Flow.flow.next();"}' ;; esac echo $CMD | nc -c localhost 32000 exit 0 

For the order I got a repository for scripts: github.com/irvinzz/sites-remote-control . Ready to accept pull request for other sites.

Thank you for your attention, I think the principle is clear, by analogy you can adapt for Windows, Chrome, other sites with music.

PS:

Under windows


As expected, the adaptation for windows did not keep waiting.
There is a discussion.
NetCat - Take From Here
That's what happened with me:
music.yandex.ru.cmd:
 @echo off GOTO :%1 :playpause set "CMD=(function(f){f.player.pause()^|^|f.player.resume()^|^|f.play()})(Mu.pages.player.flow);" goto :END :next set "CMD=Mu.pages.player.flow.next();" goto :END :prev set "CMD=Mu.pages.player.flow.prev(); goto :END :END echo %CMD% > cmd.txt type cmd.txt | nc.exe -v -d localhost 32000 del cmd.txt 

To get rid of the blinking window in this way:
music.yandex.ru-playpause.vbs:
 CreateObject("Wscript.Shell").Run "music.yandex.ru.cmd playpause", 0, True 

Source: https://habr.com/ru/post/267557/


All Articles