-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug fix when having multiple audio sinks to not confuse processes
- Loading branch information
Showing
4 changed files
with
42 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash | ||
tmux new-session -d -s adfree | ||
tmux send-keys '~/Spotify-Ads-Muter-Linux/mute_spotify_timer.sh' C-m # C-m sends ENTER keystroke | ||
tmux send-keys "~/git/Spotify-Ads-Muter-Linux/mute_spotify_timer.sh $respawn" C-m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,50 @@ | ||
#!/bin/bash | ||
# Script to mute an application using PulseAudio, depending solely on | ||
# process name, constructed as answer on askubuntu.com:. | ||
# http://askubuntu.com/questions/180612/script-to-mute-an-application | ||
|
||
# It works as: mute_application.sh vlc mute OR mute_application.sh vlc unmute | ||
# Script to respawn or mute an application using PulseAudio | ||
|
||
# it works as mute_app.sh <app_name> <action>, such as mute_app.sh spotify mute | ||
if [ -z "$1" ]; then | ||
echo "Please provide me with an application name" | ||
echo "Please provide an application name." | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$2" ]; then | ||
echo "Please provide me with an action mute/unmute after the application name" | ||
echo "Please provide an action: mute, unmute, or respawn." | ||
exit 1 | ||
fi | ||
|
||
if ! [[ "$2" == "mute" || "$2" == "unmute" ]]; then | ||
echo "The 2nd argument must be mute/unmute" | ||
if [[ "$2" != "mute" && "$2" != "unmute" && "$2" != "respawn" ]]; then | ||
echo "The action must be mute, unmute, or respawn." | ||
exit 1 | ||
fi | ||
|
||
process_id=$(pidof "$1") | ||
# Get the process ID associated with the specified application | ||
process_ids=$(pgrep -d ' ' -x "$1") | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "There is no such process as "$1"" | ||
if [ -z "$process_ids" ]; then | ||
echo "There is no such process matching: '$1'." | ||
exit 1 | ||
fi | ||
|
||
temp=$(mktemp) | ||
|
||
pacmd list-sink-inputs > $temp | ||
|
||
inputs_found=0; | ||
current_index=-1; | ||
# Loop through each process ID | ||
for process_id in $process_ids; do | ||
# Get the sink input index for the sink with "spotify" in the name | ||
sink_input_index=$(pacmd list-sink-inputs | grep -B 20 -P "application.name = \"${1}\"" | grep "index" | awk '{print $2}') | ||
|
||
while read line; do | ||
if [ $inputs_found -eq 0 ]; then | ||
inputs=$(echo -ne "$line" | awk '{print $2}') | ||
if [[ "$inputs" == "to" ]]; then | ||
continue | ||
fi | ||
inputs_found=1 | ||
else | ||
if [[ "${line:0:6}" == "index:" ]]; then | ||
current_index="${line:7}" | ||
elif [[ "${line:0:25}" == "application.process.id = " ]]; then | ||
if [[ "${line:25}" == "\"$process_id\"" ]]; then | ||
# index found... | ||
break; | ||
fi | ||
fi | ||
if [ -z "$sink_input_index" ]; then | ||
echo "Could not find sink input index for '$1' (PID: $process_id)." | ||
exit 1 | ||
fi | ||
done < $temp | ||
|
||
rm -f $temp | ||
|
||
if [ $current_index -eq -1 ]; then | ||
echo "Could not find "$1" in the processes that output sound." | ||
exit 1 | ||
fi | ||
|
||
# muting... | ||
if [[ "$2" == "mute" ]]; then | ||
pacmd set-sink-input-mute "$current_index" 1 > /dev/null 2>&1 | ||
else | ||
pacmd set-sink-input-mute "$current_index" 0 > /dev/null 2>&1 | ||
fi | ||
# Perform the specified action | ||
if [ "$2" == "mute" ]; then | ||
pacmd set-sink-input-mute "$sink_input_index" 1 > /dev/null 2>&1 | ||
elif [ "$2" == "unmute" ]; then | ||
pacmd set-sink-input-mute "$sink_input_index" 0 > /dev/null 2>&1 | ||
elif [ "$2" == "respawn" ]; then | ||
kill "$process_id" # kill application | ||
while pgrep -x "$1" >/dev/null; do sleep 1; done # wait for application to die | ||
"$1" & # start application | ||
fi | ||
done | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
#!/bin/bash | ||
|
||
respawn=false # set whether to mute or restart spotify to skip ads | ||
|
||
while true; do | ||
# get Spotify playing song name | ||
name=`dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata | sed -n '/title/{n;p}' | cut -d '"' -f 2` | ||
url=`dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata | sed -n '/url/{n;p}' | cut -d '"' -f 2` | ||
echo $name | ||
|
||
if [[ "$name" = *"Advertisement"* || "$name" = *"Spotify"* ]] || [[ $url == *"/ad/"* ]]; then | ||
# if song name contains "Advertisement" or "Spotify" or url contains "/ad/" | ||
if [[ "$name" = *"Advertisement"* || "$name" = *"Spotify"* ]] || [[ $url == *"/ad/"* ]]; then | ||
echo "Muting" | ||
~/Spotify-Ads-Muter-Linux/mute_app.sh spotify mute | ||
~/git/Spotify-Ads-Muter-Linux/mute_app.sh spotify mute | ||
if [[ $respawn == true ]]; then | ||
echo "Respawning" | ||
~/git/Spotify-Ads-Muter-Linux/mute_app.sh spotify respawn | ||
fi | ||
else | ||
echo "Unmuting" | ||
~/Spotify-Ads-Muter-Linux/mute_app.sh spotify unmute | ||
~/git/Spotify-Ads-Muter-Linux/mute_app.sh spotify unmute | ||
fi | ||
sleep 1 | ||
done |