media-controller (3651B)
1 #!/bin/sh 2 # TODO: REWRITE THIS 3 dunstify "FIX THIS" "$0" 4 exit $? 5 6 VIDEO_PLAYER="mpv" 7 MUSIC_PLAYER="mpd" 8 [ "$CURRENT_PLAYER" ] || CURRENT_PLAYER="$(pgrep -f "$VIDEO_PLAYER" > /dev/null && echo "$VIDEO_PLAYER" || echo "$MUSIC_PLAYER")" 9 10 if [[ "$CURRENT_PLAYER" = "mpd" ]]; then 11 prev="mpc -q prev" 12 next="mpc -q next" 13 stop="mpc -q stop" 14 togg="mpc -q toggle" 15 skfw="mpc -q seek +5" 16 skbw="mpc -q seek -5" 17 stat="mpc status" 18 titl="mpc --format '[%title%|%file%]' current" 19 20 elif [[ "$CURRENT_PLAYER" = "mpv" ]]; then 21 LAST_MPV_SOCKET="$(find /tmp/mpvSockets -type s -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" ")" 22 next="echo 'playlist-next' | socat - ${LAST_MPV_SOCKET}" 23 prev="echo 'playlist-prev' | socat - ${LAST_MPV_SOCKET}" 24 stop="echo 'stop' | socat - ${LAST_MPV_SOCKET}" 25 togg="echo 'cycle pause' | socat - ${LAST_MPV_SOCKET}" 26 skfw="echo 'seek +5' | socat - ${LAST_MPV_SOCKET}" 27 skbw="echo 'seek -5' | socat - ${LAST_MPV_SOCKET}" 28 stat="echo \"{ \\\"command\\\": [\\\"get_property\\\", \\\"core-idle\\\"] }\" | socat - \"$LAST_MPV_SOCKET\" | grep -Eiq '\"data\":false' && echo \"Playing\" || echo \"Paused\"" 29 titl="echo \"{ \\\"command\\\": [\\\"get_property\\\", \\\"media-title\\\"] }\" | socat - \"$LAST_MPV_SOCKET\" | sed 's/{.*data\":\"*\(.*\)\",\"*.*}/\1/'" 30 31 elif [[ "$CURRENT_PLAYER" = "spotify" ]]; then 32 prev="playerctl -p spotify previous" 33 next="playerctl -p spotify next" 34 stop="playerctl -p spotify stop" 35 togg="playerctl -p spotify play-pause" 36 skfw="playerctl -p spotify position 5+" 37 skbw="playerctl -p spotify position 5-" 38 stat="playerctl -p spotify status" 39 titl="playerctl -p spotify metadata -f '{{title}}'" 40 else 41 prev="" togg="" stop="" next="" stat="" 42 titl="There's no $MUSIC_PLAYER or $VIDEO_PLAYER installed" 43 fi 44 45 case ${1} in 46 pause-all) 47 find "/tmp/mpvSockets" -type s | while read -r i; do echo "set pause yes" | socat - "$i"; done 48 playerctl -p spotify pause 49 mpc -q pause 50 ;; 51 icon) if [[ "$(eval $stat)" = *"laying"* ]]; then 52 exec echo "" 53 else 54 exec echo "" 55 fi 56 ;; 57 seek-bwd) eval "$skbw" 58 ;; 59 prev) eval "$prev"; 60 dunstify -u low -r 100003 -t 2000 -i "player_rew" "Media Controller" "Playing previous: $(eval $titl)" 61 ;; 62 toggle) eval "$togg"; 63 if [[ "$(eval $stat)" =~ "laying" ]]; then 64 dunstify -u low -r 100003 -t 2000 -i "player_play" "Media Controller" "Playing: $(eval $titl)" 65 else 66 dunstify -u low -r 100003 -t 2000 -i "player_pause" "Media Controller" "Paused: $(eval $titl)" 67 fi 68 ;; 69 stop) eval "$stop"; 70 ;; 71 next) eval "$next"; 72 dunstify -u low -r 100003 -t 2000 -i "player_fwd" "Media Controller" "Playing next: $(eval $titl)" 73 ;; 74 seek-fwd) eval "$skfw" 75 ;; 76 status) eval "$stat" 77 ;; 78 title) eval "$titl" 79 ;; 80 switchpl) if [[ "$(eval $stat)" = *"laying"* ]]; then 81 eval "$togg" 82 fi 83 if [[ "$CURRENT_MUSICPL" != "mpd" ]]; then 84 sed -i '/musicpl=/s/".*"/"mpd"/' "$DEFAPPS_FILE" 85 elif [[ "$CURRENT_MUSICPL" != "spotify" ]]; then 86 sed -i '/musicpl=/s/".*"/"spotify"/' "$DEFAPPS_FILE" 87 fi 88 dunstify -u low -r 100003 -t 2000 -i "$NOTIF_MUSIC_ICON" "Media Controller" "<span size='small'><u>$("$DEFAPPS_EXEC" -g musicpl)</u></span>\nSuccessfully set as default" 89 ;; 90 esac 91 92 exit $?