gmdfalk / blockify

mute spotify adverts on linux
MIT License
353 stars 42 forks source link

blockify

Important: This application is no longer being maintained. Please note that using ad blockers is prohibited by Spotify. I highly encourage everyone to support Spotify and your favorite artists by buying a subscription.

Blockify is a linux only application that allows you to automatically mute songs and advertisements in Spotify.

Installation

Dependencies

Mandatory:

Optional but highly recommended:

Optional:

On ArchLinux, you can install all dependencies as follows:
pacman -S git python-pip gst-python pulseaudio alsa-utils pygtk python-dbus python-gobject python-docopt wmctrl

Package Manager

Arch Linux

Available via AUR here: https://aur.archlinux.org/packages/?O=0&K=blockify

Example ArchLinux installation routine:

git clone https://aur.archlinux.org/blockify.git
cd blockify
makepkg -sri

Fedora and openSUSE

Available in the openSUSE build service.

Debian

sudo apt-get install gir1.2-gstreamer-0.10 gir1.2-gstreamer-1.0 python-gst-1.0
sudo apt-get install libdbus-1-dev libdbus-glib-1-dev
sudo pip3 install dbus-python
sudo pip3 install git+https://github.com/serialoverflow/blockify

Manual (pip/setup.py)

If there is no blockify package available on your distribution, you'll have to install it directly via one of pythons many installation tools.

Package names are for ArchLinux and will probably differ slightly between distributions.

Preparation (for Ubuntu):

# Install Spotify beta
echo deb http://repository.spotify.com testing non-free | sudo tee /etc/apt/sources.list.d/spotify.list
sudo apt-get update
sudo apt-get install spotify-client
# Install blockify dependencies
sudo apt-get install git python3-pip python3-gst-1.0 python3-requests python3-docopt python3-setuptools wmctrl

Install routine:

# Install blockify
sudo pip3 install git+https://github.com/serialoverflow/blockify
echo -e '[Desktop Entry]\nName=Blockify\nComment=Blocks Spotify commercials\nExec=blockify-ui\nIcon='$(python3 -c 'import pkg_resources; print(pkg_resources.resource_filename("blockify", "data/icon-red-512.png"))')'\nType=Application\nCategories=AudioVideo' | sudo tee /usr/share/applications/blockify.desktop

Usage

Requirements

It is important to know that blockify relies on dbus (and, for some features, on pulseaudio) for ad detection.
If any of these statements are true for your configuration, ad detection will not work:

Additionally, blockify makes use of pulseaudio sinks, allowing processes to be muted individually.
If you do not have/want pulseaudio, blockify will mute the system sound during commercials instead of just Spotify. The interlude music feature will not work as a consequence.

Detection

Blockify will automatically detect and block ads for you so besides starting it after running spotify, there's not a lot to do.
However, it also comes with the option to complement or replace that autoblock functionality with a blocklist (saved as ~/.config/blockify/blocklist.txt).
Blocklist entries are case-sensitive and greedy, e.g. the entry Blood would match any artist starting with those exact five letters.

Controls/Actions

Blockify accepts several signals:

To easily use these signals add the following function to your .bashrc:

bb() {
    local signal
    case "$1" in
        '')  blockify-dbus get 2>/dev/null && return 0;;
        ex|exit)
            signal='TERM';;       # Exit
        b|block)
            signal='USR1';;       # Block
        u|unblock)
            signal='USR2';;       # Unblock
        p|previous)
            signal='RTMIN';;      # Previous song
        n|next)
            signal='RTMIN+1';;    # Next song
        t|toggle)
            signal='RTMIN+2';;    # Toggle play song
        tb|toggleblock)
            signal='RTMIN+3';;    # Toggle block song
        ip|iprevious)
            signal='RTMIN+10';;   # Previous interlude song
        in|inext)
            signal='RTMIN+11';;   # Next interlude song
        it|itoggle)
            signal='RTMIN+12';;   # Toggle play interlude song
        itr|itoggleresume)
            signal='RTMIN+13';;   # Toggle interlude resume
        *) echo "Usage: bb ( b[lock] | u[nblock] | p[revious] | n[ext] | t[oggle] | t[oggle]b[lock] |...)" && return 0;;
    esac
    pkill --signal "$signal" -f 'python.*blockify'
}

Then use it via e.g. bb to get current song info or bb t to toggle playback.

CLI

Blockify has a CLI/daemon that you can start with blockify.
blockify -h will print out a help text with available options.

GUI

Alternatively, you can use the GUI with blockify-ui which spawns this window.
ScreenShot

Configuration

Please see the provided example_blockify.ini on what settings are available and their purpose.
Blockify automatically creates a configuration file at $HOME/.config/blockify/blockify.ini if you don't have one already. It will also tell you via ERROR-logging messages, if you configuration file is faulty or incomplete, in which case the options that could be read will be merged with the default options you see in example_blockify.ini but you'll still want to fix your configuration file.

Interlude Music

From version 1.4 onwards blockify can play music of your choice during commercial breaks.
The default behaviour is for blockify to automatically play the first song in the playlist file (should you have one), when a commercial starts playing.
Alternatively, you can set the autoresume option to False which will cause blockify to always finish the current interlude song before resuming spotify playback.

The interlude feature only works if you use pulseaudio (i.e. spotify needs to run in its own sink so it can be muted separately).
To make use of interlude music you have to configure a playlist file in ~/.config/blockify/playlist.m3u.
The playlist system is (mostly) M3U-compliant.

An example playlist:

# Lines starting with "#" will be ignored.
# Absolute path to a file:
/media/music/foo/bar.mp3
# Relative path to a file (as seen from playlist location):
foo/bar.flac
# Relative path to another playlist. Just make sure the other playlist doesn't link back or else you'll get a very long playlist:
baz.m3u
# A whole directory:
/media/music/foo
# It's also possible to give full URIs:
file:///media/music/foo/bar.mp4
http://www.example.com/foo/bar.wav
# A radio station. Note that radio streams don't usually end so you'll have to switch
# back to spotify manually, enable autoresume or specify the radio_timeout in the config file.
http://skyserver5.skydisc.net:8000

You can use relative and absolute paths as well as basically any audio source/format, as long as you have the respective gstreamer codec installed.

Troubleshooting

Known issues

Common issues

Debugging

If you can't find or fix the issue you are having by yourself, you are welcome to open an issue on this site. When you do, please provide the following information:

Similar open-source projects

On Linux:

On Windows:

On OS X: