96 lines
2.4 KiB
Bash
Executable File
96 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
action="$1"
|
|
|
|
if [ -z "$action" ]; then
|
|
echo "Usage: $0 [play-pause|next|previous|+5%|-5%|50%]"
|
|
exit 1
|
|
fi
|
|
|
|
# Deezer PWA PID
|
|
root_pid=$(hyprctl clients -j | jq -r '.[] | select(.initialTitle == "Deezer") | .pid' | head -n1)
|
|
|
|
if [ -z "$root_pid" ] || [ "$root_pid" = "null" ]; then
|
|
echo "[ERROR] Deezer window not found."
|
|
exit 1
|
|
fi
|
|
|
|
case "$action" in
|
|
play-pause|next|previous)
|
|
playerctl --player="chromium.instance${root_pid}" "$action"
|
|
exit 0
|
|
;;
|
|
*)
|
|
# Volume: find sink-input whose PID is in the process tree
|
|
pids=$(pstree -p "$root_pid" | grep -oP '\(\K[0-9]+')
|
|
sink=$(pactl -f json list sink-inputs | jq -r --argjson pids "$(echo "$pids" | jq -R . | jq -s 'map(tonumber)')" \
|
|
'.[] | select(.properties["application.process.id"] | tonumber | IN($pids[])) | .index' | head -n1)
|
|
|
|
if [ -z "$sink" ]; then
|
|
echo "[ERROR] No audio stream found for Deezer."
|
|
exit 1
|
|
fi
|
|
pactl set-sink-input-volume "$sink" "$action"
|
|
;;
|
|
esac
|
|
|
|
|
|
#
|
|
# # 2) Gather ALL descendant PIDs
|
|
# declare -a pid_array
|
|
# pid_array+=("$root_pid")
|
|
#
|
|
# # Direct children
|
|
# children=($(pgrep -P "$root_pid"))
|
|
# echo "[INFO] Children: ${children[*]}"
|
|
#
|
|
# for c in "${children[@]}"; do
|
|
# pid_array+=("$c")
|
|
# gc=($(pgrep -P "$c"))
|
|
# echo "[INFO] Grandchildren of $c: ${gc[*]}"
|
|
# for g in "${gc[@]}"; do
|
|
# pid_array+=("$g")
|
|
# done
|
|
# done
|
|
#
|
|
# echo "[INFO] All collected PIDs: ${pid_array[*]}"
|
|
#
|
|
# echo "----------------------------------"
|
|
# echo "[INFO] Checking sink inputs..."
|
|
# echo "----------------------------------"
|
|
#
|
|
# sink=""
|
|
#
|
|
# while IFS= read -r block; do
|
|
# pid=$(echo "$block" | jq -r '.properties["application.process.id"] // empty')
|
|
# index=$(echo "$block" | jq -r '.index')
|
|
#
|
|
# echo "[SINK] index=$index pid=$pid"
|
|
#
|
|
# [ -z "$pid" ] && { echo " -> Skipping"; continue; }
|
|
#
|
|
# for candidate in "${pid_array[@]}"; do
|
|
# if [ "$pid" = "$candidate" ]; then
|
|
# echo " -> MATCH with PID $candidate"
|
|
# sink="$index"
|
|
# break 2
|
|
# fi
|
|
# done
|
|
#
|
|
# echo " -> No match"
|
|
#
|
|
# done < <(pactl -f json list sink-inputs | jq -c '.[]')
|
|
#
|
|
# echo "----------------------------------"
|
|
#
|
|
# if [ -z "$sink" ]; then
|
|
# echo "[ERROR] No audio stream found for Deezer."
|
|
# exit 1
|
|
# fi
|
|
#
|
|
# echo "[INFO] Deezer sink index: $sink"
|
|
# echo "[INFO] Applying: $change"
|
|
#
|
|
# pactl set-sink-input-volume "$sink" "$change"
|
|
#
|