Adblocker for Spotify

Overview

spotify-adblock

Spotify adblocker for Linux (macOS untested) that works by wrapping getaddrinfo and cef_urlrequest_create. It blocks requests to domains that are not on the allowlist, as well as URLs that are on the denylist.

Notes

  • This does not work with the snap Spotify package.
  • This might not work with the Flatpak Spotify package, depending on your system's shared libraries' versions.
  • On Debian-based distributions (e.g. Ubuntu), the Debian Spotify package can be installed by following the instructions at the bottom of this page. (recommended)

Build

Prerequisites:

  • Git
  • Make
  • Rust
$ git clone https://github.com/abba23/spotify-adblock.git
$ cd spotify-adblock
$ make

Install

$ sudo make install

Flatpak

$ mkdir -p ~/.spotify-adblock && cp target/release/libspotifyadblock.so ~/.spotify-adblock/spotify-adblock.so
$ mkdir -p ~/.config/spotify-adblock && cp config.toml ~/.config/spotify-adblock
$ flatpak override --user --filesystem="~/.spotify-adblock/spotify-adblock.so" --filesystem="~/.config/spotify-adblock/config.toml" com.spotify.Client

Usage

Command-line

$ LD_PRELOAD=/usr/local/lib/spotify-adblock.so spotify

Flatpak

$ flatpak run --command=sh com.spotify.Client -c 'eval "$(sed s#LD_PRELOAD=#LD_PRELOAD=$HOME/.spotify-adblock/spotify-adblock.so:#g /app/bin/spotify)"'

Desktop file

You can integrate it with your desktop environment by creating a .desktop file (e.g. spotify-adblock.desktop) in ~/.local/share/applications. This lets you easily run it from an application launcher without opening a terminal.

Examples:

Debian Package

[Desktop Entry]
Type=Application
Name=Spotify (adblock)
GenericName=Music Player
Icon=spotify-client
TryExec=spotify
Exec=env LD_PRELOAD=/usr/local/lib/spotify-adblock.so spotify %U
Terminal=false
MimeType=x-scheme-handler/spotify;
Categories=Audio;Music;Player;AudioVideo;
StartupWMClass=spotify

Flatpak

[Desktop Entry]
Type=Application
Name=Spotify (adblock)
GenericName=Music Player
Icon=com.spotify.Client
Exec=flatpak run --file-forwarding --command=sh com.spotify.Client -c 'eval "$(sed s#LD_PRELOAD=#LD_PRELOAD=$HOME/.spotify-adblock/spotify-adblock.so:#g /app/bin/spotify)"' @@u %U @@
Terminal=false
MimeType=x-scheme-handler/spotify;
Categories=Audio;Music;Player;AudioVideo;
StartupWMClass=spotify

Uninstall

$ sudo make uninstall

Flatpak

$ rm -r ~/.spotify-adblock ~/.config/spotify-adblock
$ flatpak override --user --reset com.spotify.Client

Configuration

The allowlist and denylist can be configured in a config file located at (in ascending order of precedence):

  • /etc/spotify-adblock/config.toml (default)
  • ~/.config/spotify-adblock/config.toml (default for Flatpak)
  • config.toml in the working directory
Comments
  • Can't run the app

    Can't run the app

    I have fedora 34 and spotify client installed from unitedRPMs, compiled from source adblock and when i run LD_PRELOAD=/usr/local/lib/spotify-adblock.so spotify i get /usr/bin/bash: symbol lookup error: /usr/local/lib/spotify-adblock.so: undefined symbol: cef_string_userfree_utf16_free

    edit: I also tried the release and it is giving the same error

    opened by Amanse 33
  • Spotify blocks off and stops working after install

    Spotify blocks off and stops working after install

    After installing spotify-adblock, my spotify stopped working. Not sure if spotify is trying to stop it or what. I'm using Spotify version 1.1.72.439.gc253025e on Arch Linux.

    Screenshot_2021-12-15-02-17-28_1920x1080

    opened by Khosraw 11
  • Starting problem

    Starting problem

    [sahafselim@sahafselim ~]$ spotify spotify: /usr/lib/libcurl-gnutls.so.4: no version information available (required by spotify) /opt/spotify/spotify: /usr/lib/libcurl-gnutls.so.4: no version information available (required by /opt/spotify/spotify) /opt/spotify/spotify: /usr/lib/libcurl-gnutls.so.4: no version information available (required by /opt/spotify/spotify) /proc/self/exe: /usr/lib/libcurl-gnutls.so.4: no version information available (required by /proc/self/exe) [libprotobuf ERROR ../core/vendor/protobuf3/src/google/protobuf/wire_format_lite.cc:577] String field 'spotify.event_sender.proto.DroppedEvents.DroppedEventsBySequenceIdEntry.key' contains invalid UTF-8 data when parsing a protocol buffer. Use the 'bytes' type if you intend to send raw bytes. [sahafselim@sahafselim ~]$

    opened by sahafselim 9
  • imediately crashes if relaunched

    imediately crashes if relaunched

    i can launch the app and works flawlessly i love it, until i decide to exit out of it and relaunch it. if i use the .desktop it pops up then immediately crashes, and with the LD_PRELOAD command it does the same thing but with this error [0827/004841.028258:FATAL:gpu_data_manager_impl_private.cc(447)] GPU process isn't usable. Goodbye. Trace/breakpoint trap (core dumped)

    the only way that i can re open it is after rebooting my system im running xubuntu 22.04. i have literally only about a single weeks worth of linux knowledge, so message me some commands to run if you need more info.

    your wish is my CMD

    opened by dairdevil0420 9
  • symbol lookup error

    symbol lookup error

    when attempting to preload the library with LD_PRELOAD=/usr/local/lib/spotify-adblock.so spotify, an error is returned and Spotify does not open.

    The error says: /bin/sh: symbol lookup error: /usr/local/lib/spotify-adblock.so: undefined symbol: cef_string_userfree_utf16_free

    This happens regardless of whether I point LD_PRELOAD at the .so created from compiling, or the .so downloaded from the GitHub release page.

    This happens regardless of which shell I run the command from (I have tried fish, bash, and sh), though fish reports an exit code of [127] and when using bash the error instead begins with "/bin/bash".

    When using a spotify-adblock.desktop file as described in the README and attempting to launch with wofi, Spotify simply does not open. I assume that the same error is occurring invisibly when wofi runs the command.

    I am running glibc Void Linux, with xbps updates run this morning, and the Spotify that is available via xbps-src - 1.1.68 as of this writing.

    I am lost as to what I could be doing differently and have been unable to find a solution from searching online. I'm happy to provide any other info that might be helpful.

    opened by Raffadiely 8
  • Music don't start if

    Music don't start if "next song" button is pressed

    Dear developers.

    As the tittle says, if I press the "next song" button, the next song is not played. However, the play button says that is playing. After that, the behavior remains when clicking on playlists or other songs. Workarounds are to let the playlist keep playing, or restart Spotify. I have tried to reinstall, with no success.

    OS: Arch-Linux Version: Spotify-adblock installed from source and AUR.

    imagen

    opened by jvellojin 8
  • Songs are greyed

    Songs are greyed

    Running spotify: image

    But running LD_PRELOAD=/usr/lib/spotify-adblock.so spotify, songs are being greyed out. image

    It's not like no internet as I can still explore songs and all, plus it can even play playlists by clicking the big play icon. image

    But cannot play individual songs because play icons don't show up.

    Edit: When the item is double-clicked, this toast is shown, image

    Spotify installed by pacman. spotify-adblock installed from source

    opened by mizzunet 7
  • Autoupdate config.toml definitions

    Autoupdate config.toml definitions

    Thank You for this project, beautiful idea to wrap the spotfy library!!! :)

    A few days ago I had some problems with the app and looking at the project I realized that the definitions of config.toml are updated. I thought: "it wouldn't be nice if you could update them automatically every time you open spotify!"

    A small start bash script before starting the program could check if the definition config.toml is the same on git. In case it is different it could overwrite it.

    I'm not familiar with pull request, so I leave you here a small example of code that could do this (with a litle problem of write permission in etc file... and so I think it is more appropriate to give priority to the definition in home and then to the definition in /etc/ ...)

    
    # start.sh
    
    # generate sha of local def
    LOCAL_DEF_SHA=$(cat /etc/spotify-adblock/config.toml | openssl dgst -sha256)
    
    # generate sha of local def
    REMOTE_DEF_SHA=$(curl https://raw.githubusercontent.com/abba23/spotify-adblock/main/config.toml | openssl dgst -sha256)
    
    # if they are different, download from git ..
    if [ "$LOCAL_DEF_SHA" != "$REMOTE_DEF_SHA" ]; then
        echo "LOCAL != REMOTE, UPDATE definitions ..."
        curl -o /etc/spotify-adblock/config.toml https://raw.githubusercontent.com/abba23/spotify-adblock/main/config.toml 
    else
        echo "LOCAL == REMOTE, OKK"
    fi
    
    #run spotify
    LD_PRELOAD=/usr/local/lib/spotify-adblock.so spotify
    
    opened by labgua 7
  • spotify-adblock is not blocking ads

    spotify-adblock is not blocking ads

    Whenever I run spotify in the terminal, I get this output:

    spotify: /usr/lib/libcurl-gnutls.so.4: no version information available (required by spotify)
    /opt/spotify/spotify: /usr/lib/libcurl-gnutls.so.4: no version information available (required by /opt/spotify/spotify)
    /opt/spotify/spotify: /usr/lib/libcurl-gnutls.so.4: no version information available (required by /opt/spotify/spotify)
    /proc/self/exe: /usr/lib/libcurl-gnutls.so.4: no version information available (required by /proc/self/exe)
    

    I use Arch Linux and I installed spotify-dev using the AUR package. I get no banner ads because I use another AUR package spotify-remove-ad-banner. Am I doing something wrong? What should I do to remove ads?

    Here is an image of the ad: https://imgur.com/a/xaBVahR

    opened by ghost 6
  • Every song is greyed out, no playback available

    Every song is greyed out, no playback available

    I haven't used spotify in a while and suddenly i just could not play anything, every song is greyed out now. I upgraded to the latest so but this didn't fix the issue unfortunately. If any logs can help you out, let me know how i could take them... Thank you for creating this

    opened by JimKatsanoss 6
  • Not working it seems (tested on Aug/2021)

    Not working it seems (tested on Aug/2021)

    Hello, and first of all, thanks for the great idea! This seems very promising. I'm testing the library, but in my case (running linux binary in Brazil), Ads are playing normally, even with the library preloaded. Is there anything I can do in order to help debug that? Maybe collecting the URLs spotify is acessing while playing the Ads...

    Let me know, I'd be glad to help! Cheers

    opened by guilhermepiccoli 6
  • How to use Spotify Adblock on Fedora

    How to use Spotify Adblock on Fedora

    I have installed spotify using the lpf-client method and spotify-adblock is also installed, but I don't know how to use it. Using this command line: LD_PRELOAD=/usr/local/lib/spotify-adblock.so spotify was no good for me and the desktop file method is for debian package only.

    opened by thecursehunter 1
  • Reminder to start official spotify at least once

    Reminder to start official spotify at least once

    On a new debian install, I installed spotify and spotify-adblock straight out of the blocks.

    I ran spotify-adblock first, and used it to log in. This led to the songs only playing 10 seconds before stopping.

    I found that you have to run and login with spotify official at least once before running spotify-adblock

    I recommend that you add this to the notes

    opened by suchetha 0
  • Spotify flatpak fix

    Spotify flatpak fix

    The actual spotify binary is in a different folder, so people may need to run spotify flatpak with something like this:

    flatpak run --command=/app/extra/share/spotify/spotify --env="LD_PRELOAD=/home/user/.spotify-adblock/spotify-adblock.so" com.spotify.Client

    opened by pizzadude 3
Releases(v1.0.2)
Spotify for the terminal written in Rust 🚀

Spotify TUI A Spotify client for the terminal written in Rust. The terminal in the demo above is using the Rigel theme. Spotify TUI Installation Homeb

Alexander Keliris 14.1k Jan 1, 2023
A spotify daemon

Spotifyd An open source Spotify client running as a UNIX daemon. Spotifyd streams music just like the official client, but is more lightweight and sup

null 8.4k Dec 31, 2022
Gtk/Rust native Spotify client for the GNOME desktop.

Gtk/Rust native Spotify client for the GNOME desktop.

Alexandre Trendel 1.7k Jan 1, 2023
🎧 a self-hosted Spotify → Discord music bot

Aoede is a Discord music bot that directly streams from Spotify to Discord. The only interface is Spotify itself. Note: a Spotify Premium account is c

Max Isom 159 Dec 29, 2022
A Spotify downloader written in rust, which does not require a premium account

DownOnSpot A Spotify downloader written in Rust Disclaimer DownOnSpot was not developed for piracy. It is meant to be used in compliance with DMCA, Se

oSumAtrIX 273 Jan 7, 2023
A command driven spotify player

spotify-player Table of Contents Introduction Examples Demo Installation Requirements Spotify Connect Streaming Commands Actions Search Page Mouse sup

Thang Pham 185 Dec 28, 2022
Psst - Fast and multi-platform Spotify client with native GUI

Psst Fast Spotify client with native GUI, without Electron, built in Rust. Very early in development, lacking in features, stability, and general user

Jan Pochyla 7.2k Jan 2, 2023
Rust-port of spotify/annoy as a wrapper for Approximate Nearest Neighbors in C++/Python optimized for memory usage.

Rust-port of spotify/annoy as a wrapper for Approximate Nearest Neighbors in C++/Python optimized for memory usage.

Arthur·Thomas 13 Mar 10, 2022
Rust-port of spotify/annoy as a wrapper for Approximate Nearest Neighbors in C++/Python optimized for memory usage.

Fareast This library is a rust port of spotify/annoy , currently only index serving is supported. It also provides FFI bindings for jvm, dotnet and da

Arthur·Thomas 13 Mar 10, 2022
ncspot is a ncurses Spotify client written in Rust using librespot.

ncspot is a ncurses Spotify client written in Rust using librespot. It is heavily inspired by ncurses MPD clients, such as ncmpc. My motivation was to provide a simple and resource friendly alternative to the official client as well as to support platforms that currently don't have a Spotify client, such as the *BSDs.

Henrik Friedrichsen 3.4k Jan 8, 2023
code to connect + communicate with a Spotify Car Thing

spotify_carthing_bt A grab-bag of spotify car thing related hacks I'm working on. deskthing-rs A Rust port of https://github.com/relative/deskthing, w

Daniel Prilik 6 Dec 19, 2022
An API to track various stats written in Rust. Tracking Github, Wakatime, Spotify, and Duolingo

Null API API For collecting data Explore the docs » View Demo · Report Bug · Request Feature Table of Contents About The Project Built With Getting St

The Null Dev 2 Dec 15, 2022
Effortlessly beautify your Spotify playlists with just a single, enchanting script 💫 🎵

harmonia harmonia, effortlessly beautify your Spotify playlists with just a single, enchanting script. ?? ?? HANDLE WITH LOVE: Since harmonia is bloss

Gülce 4 Jun 23, 2023
Client for spotify's apt repository in Rust for Arch Linux

spotify-launcher Spotify has a free linux client but prohibits re-distribution, so this is a freely distributable opensource program that manages a sp

null 93 Jun 20, 2023
Shows my Spotify status on a small screen. Powered by ESP-IDF & built with 🧡 in Rust! 🦀

ESP Display A small embedded project that shows what I'm listening to on Spotify by using my Spotify service. Example Notable Features ESP32-S3 board

Isaiah Gamble 3 Apr 10, 2024
A command line application to organize Spotify playlists.

Sortify A command line application to organize Spotify playlists. Using Sortify, you can choose a playlist as the source playlist, and then have the o

Francisco Cunha 4 Aug 14, 2024