-
I want to use the media key commands for play/pause, next, and previous. With other media players, I bound the key in my Sway config file to run a script that would make an rpc call to the player. I unbound those, hoping that YTM would read the media keys, but it does not. I also tried setting up a global shortcut, but that didn't work either. I tried with overrideMediaKeys true and false. Neither worked.
Or does YTM support an external rpc call to run commands? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I found some remote control programs for YTM and was able to determine the remote API from their source code, so I wrote my own CLI tool to control YTM and bound my keys to call that. Here's the tool for anyone who wants to use it or modify it: |
Beta Was this translation helpful? Give feedback.
-
I personally prefer using MPRIS to control those things ( bindsym XF86AudioPlay exec playerctl play-pause
bindsym XF86AudioPause exec playerctl play-pause
bindsym XF86AudioPrev exec playerctl previous
bindsym XF86AudioNext exec playerctl next When using the Shortcuts (& MRPIS) plugin you can also specify the player If you prefer doing requests to the API, you could also just do it directly with curl: set $YOUTUBE_MUSIC_API "http://localhost:26538"
bindsym XF86AudioMute exec curl -X POST $YOUTUBE_MUSIC_API/api/v1/toggle-mute or use a shell script #!/usr/bin/env sh
API_URL=http://localhost:26538
request() {
local method=$1
local path=$2
local data=()
[ ! -z "$3" ] && data=('-H' 'Content-Type: application/json' '-d' "$3")
curl -X $method "${API_URL}${path}" "${data[@]}" 2>/dev/null
}
volume() {
local increment=$1
local volume=`request GET /api/v1/volume | jq '.state'`
request POST /api/v1/volume '{"volume": '$((volume + increment))'}'
}
toggle_play() { request POST /api/v1/toggle-play; }
prev() { request POST /api/v1/previous; }
next() { request POST /api/v1/next; }
$@ set $youtube-music "$HOME/.config/sway/scripts/youtube-music.sh"
bindsym XF86AudioMute exec $youtube-music request POST /api/v1/toggle-mute
bindsym XF86AudioRaiseVolume exec $youtube-music volume +5
bindsym XF86AudioLowerVolume exec $youtube-music volume -5 All the API endpoints are described in |
Beta Was this translation helpful? Give feedback.
I found some remote control programs for YTM and was able to determine the remote API from their source code, so I wrote my own CLI tool to control YTM and bound my keys to call that. Here's the tool for anyone who wants to use it or modify it:
https://github.com/j8s0n/ytm-cli/tree/main