From b4aece2bf54590cbea3e50456233a4cefdbbae47 Mon Sep 17 00:00:00 2001 From: Malanius Privierre Date: Wed, 6 Mar 2024 20:37:53 +0100 Subject: [PATCH] feat: create podcasts-specific menu and controls --- scripts/seek.sh | 8 ++++++++ scripts/speed.sh | 9 +++++++++ scripts/spotify.sh | 36 ++++++++++++++++++------------------ 3 files changed, 35 insertions(+), 18 deletions(-) create mode 100755 scripts/seek.sh create mode 100755 scripts/speed.sh diff --git a/scripts/seek.sh b/scripts/seek.sh new file mode 100755 index 0000000..0da0257 --- /dev/null +++ b/scripts/seek.sh @@ -0,0 +1,8 @@ +offset_s=$1 +current_position=$(busctl --user get-property org.mpris.MediaPlayer2.spotify \ + /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player Position | awk '{print $2}') + +offset_us=$(($offset_s * 1000000)) + +busctl --user -- call org.mpris.MediaPlayer2.spotify \ + /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player Seek x $offset_us diff --git a/scripts/speed.sh b/scripts/speed.sh new file mode 100755 index 0000000..de5e6c7 --- /dev/null +++ b/scripts/speed.sh @@ -0,0 +1,9 @@ +speed_offset=$1 + +current_speed=$(busctl --user get-property org.mpris.MediaPlayer2.spotify \ + /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player Rate | awk '{print $2}') + +new_speed=$(echo "$current_speed + $speed_offset" | bc -l) + +busctl --user -- set-property org.mpris.MediaPlayer2.spotify \ + /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player Rate d $new_speed diff --git a/scripts/spotify.sh b/scripts/spotify.sh index 8549485..c22f5b3 100755 --- a/scripts/spotify.sh +++ b/scripts/spotify.sh @@ -32,27 +32,27 @@ show_not_running_menu() { } show_podcast_menu() { - # TODO: handle this after songs are working correctly - # $(tmux display-menu -T "#[align=centre fg=green]Spotify" -x R -y P \ - # "" \ - # "-#[nodim]Episode: $track_name" "" "" \ - # "-#[nodim]Podcast: $album" "" "" \ - # "" \ - # "Copy URL" c "run -b 'printf \"%s\" $id | pbcopy'" \ - # "Open Spotify" o "run -b 'source \"$CURRENT_DIR/spotify.sh\" && open_spotify'" \ - # "Play/Pause" p "run -b 'source \"$CURRENT_DIR/spotify.sh\" && toggle_play_pause'" \ - # "Previous" b "run -b 'source \"$CURRENT_DIR/spotify.sh\" && previous_track'" \ - # "Next" n "run -b 'source \"$CURRENT_DIR/spotify.sh\" && next_track'" \ - # "$repeating_label" r "run -b 'source \"$CURRENT_DIR/spotify.sh\" && toggle_repeat $is_repeat_on'" \ - # "$shuffling_label" s "run -b 'source \"$CURRENT_DIR/spotify.sh\" && toggle_shuffle $is_shuffle_on'" \ - # "" \ - # "Close menu" q "" \ - # ) + metadata=$1 + local title=$(echo $metadata | jq -r '.data["xesam:title"].data') + local podcast=$(echo $metadata | jq -r '.data["xesam:album"].data') + local track_url=$(echo $metadata | jq -r '.data["xesam:url"].data') + local possition=$(echo $metadata | jq -r '.data["mpris:position"].data') tmux display-menu -T "#[align=centre fg=green] Spotify " -x R -y P \ - "Podcasts are not supported yet" "" "" \ - \ + "" \ + "-#[nodim]Episode: $title" "" "" \ + "-#[nodim]Podcast: $podcast" "" "" \ + "" \ + "Play/Pause" p "run -b '$CURRENT_DIR/play_pause.sh'" \ + "Back 15s" b "run -b '$CURRENT_DIR/seek.sh -15'" \ + "Forward 15s" n "run -b '$CURRENT_DIR/seek.sh 15'" \ + "Copy URL" c "run -b 'echo $track_url | xclip -sel clip'" \ "" \ "Close menu" q "" + + # Seems like the rate is not supported by spotify + # even Min/Max rate in DBus is always 1.0 no matter what the actual rate is + # "Slow down" s "run -b '$CURRENT_DIR/speed.sh -0.1'" \ + # "Speed up" f "run -b '$CURRENT_DIR/speed.sh 0.1'" \ } show_track_menu() {