Last active
December 1, 2020 20:12
-
-
Save Boot-Error/fc73f41bb59afd9b6ff23b07e63b4692 to your computer and use it in GitHub Desktop.
A script to mute Spotify Client on Linux when it plays an advertisement
This file contains hidden or 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
| #!/bin/bash | |
| # This script mutes spotify when it plays an advertisement | |
| # Requires playerctl and pactl | |
| check_deps() { | |
| if ! [ -x "$(command -v playerctl)" ]; then | |
| echo 'Error: playerctl is not installed or not in PATH. Check https://github.com/altdesktop/playerctl' >&2 | |
| exit 1 | |
| fi | |
| if ! [ -x "$(command -v pactl)" ]; then | |
| echo 'Error: pactl is required but not found in PATH' >&2 | |
| exit 1 | |
| fi | |
| } | |
| mute_spotify() { | |
| # extract sink input value | |
| SINK_INPUT_ID=$(pactl list sink-inputs | grep -B 17 "Spotify" | grep "Sink Input" | cut -c13-) | |
| MUTE_VAL=$1 | |
| # set mute state | |
| pactl set-sink-input-mute $SINK_INPUT_ID $MUTE_VAL | |
| } | |
| check_ads_mute() { | |
| TRACK_TITLE=$(playerctl metadata xesam:title) | |
| if [[ $TRACK_TITLE == "Advertisement" ]]; then | |
| echo "$(date) Stupid Ad, going to mute" | |
| mute_spotify 1 | |
| # the advertisement usually plays for 30 seconds | |
| sleep 30 | |
| else | |
| mute_spotify 0 | |
| fi | |
| } | |
| while true; do | |
| sleep 1 | |
| check_ads_mute | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment