Skip spotify ads by automatically restarting application when ad comes

Overview

SpotiByeAds

made-with-python GitHub license Documentation Status GitHub stars GitHub stars

No one likes interruptions! Don't you hate it when you're listening to your favorite jazz track or your EDM playlist and an ad for Old Spice or Pepsi starting playing interrupting your mood? With SpotiByeAds, you can listen ad-free allowing you to concentrating less on those ads and more towards the task at hand!

How it works?

SpotiByeAds or SBA for short utilizes Python with the SpotiPy API and Pynput Libraries as well as the os and sys modules in order to provide you with an ad-free experience.

First, it asks you for your Spotify Username, Client ID and Client Secret (which is done by running python main.py). Of course if you've used this program and have saved the credentials, it should load a json file with your credentials in it and if not, it will ask for your credentials. Note that whenever you enter your credentials, you have the option of either saving your credentials for future use or keeping your credentials just for that session of using SBA.

After SBA has your credentials, it will establish a connection with Spotify by restarting it and setting it to your last known track/playlist. When an ad enters your spotify queue, SBA will detect the current track as an ad and restart the app. After the restart, SBA will automatically queue up the next track!

Requirements

  • Python 3
  • Pip (Python's Package Manager)

Installation

It should be noted that this is a quick way to get SBA (SpotiByeAds) up and running!

For a detailed documentation, go here.

  • First, clone the repository.
git clone https://github.com/daspartho/SpotiByeAds.git 
  • Then, change your current directory into the SpotiByeAds repository.
cd SpotiByeAds
  • Finally, install the requirements in the requirements file.
pip install -r requirements.txt
  • From here, SpotiByeAds is installed. Continue to the Setting Up section in order to connect SpotiByeAds to Spotify itself.

Setting up

You should need to do these only the first time.

  1. Go to https://developer.spotify.com/dashboard and sign in with your Spotify account.
  2. Click on the 'CREATE AN APP' option and provide an app name and app description as you'd like.
  3. Go to 'EDIT SETTINGS' and fill in the Redirect URIs placeholder with http://localhost:8080/, and click on Save.
  4. Copy the Client ID and Client Secret and paste it in when you start the script later on.
    • ⚠️ Please remember to never share your Client Secret with anyone. This could lead to your account getting stolen or irregular Spotify user behavior that could lead to account termination.
    • Developers of SpotiByeAds will never ask for your Client Secret.

⚠️ ⚠️ ⚠️

If you are on Linux and installed a containerized version of Spotify (e.g via Snap or Flatpack) or any unofficial forms of distribution, please paste the path to the Spotify executable on your computer (or a command that starts up the Spotify app) in the main.py script on the line described below:

    PATH = (shutil.which("spotify")  # For any system with spotify on $PATH
            or ("{HOMEDRIVE}{HOMEPATH}\AppData\Roaming\Spotify\Spotify.exe"
                .format_map(os.environ) if os.name == "nt"  # Windows
                else "/Applications/Spotify.app" if sys.platform == "darwin"  # MacOS
                else ""  # Custom path if installation is different
               )
           )

Please find this part of the script and paste the path/command within the "" (empty quotes) on the line with the comment # Custom path ....

This is also applicable on any other OS, if the Spotify installation path is different from the usual (and is not included in the $PATH environment variable).

⚠️ ⚠️ ⚠️

Usage

  1. Open Spotify and start your favourite track.
  2. Run the script from a terminal using python main.py in the local repository's directory (or probably by double-cliking on the main python script from your file explorer on Windows).
    • If it's the first time running the script, enter your Spotify username and paste in the Client ID and Client Secret when prompted to enter them.
  3. Congratulations! You can now listen to Spotify with no ads and the peace of mind you deserve 😁 .

Pausing playback, Skipping tracks, Changing playlists.

Due to the way the script works, pausing and playing or manually changing tracks disrupts it's work, such that the next ad that comes up might not be skipped. Not, to worry, the script has a way around this...

When you want to perform any of these actions:

  1. Go to the terminal where in the script is running.
  2. Press Ctr-C i.e hold down the Ctrl key and tap the C key.
  3. Follow the prompts to perform your desired action.

⚠️ Note: If you're using Command Prompt on windows, please note that it might have some unwanted behaviour with keyboard input that affects this feature. You are strongly adviced to run the script in Windows Powershell.

Contributing

If you want to contribute code, just write a quick pull request and the developers will take a look at it. If you want to suggest an idea, just write an issue and the developers will check it out!

Building

MacOS / Linux

If you'd like to build for Mac / Linux, do the following:

  1. To build in a development environment (to make sure it works right), run python setup.py py2app -A. Please note: This builds the app in something called alias mode. This is NOT a proper build, and will only work on the machine it was run on.
  2. To build a proper package, run python setup.py py2app.

Any major platform

You'll need Python 3 with the PyInstaller package installed. The run the following command in a terminal from the project directory.

pyinstaller --onefile --collect-submodules pynput -c -n SpotiByeAds main.py

If succesful, then check for the executable file in the dist/ directory created.

Comments
  • Installation guide

    Installation guide

    Can someone volunteer to make a installation guide for those who are not experienced with programming so that will be the go-to on how to use this script.

    documentation 
    opened by daspartho 21
  • Way to reduce number of requests sent

    Way to reduce number of requests sent

    There is limit on number of requests to spotify api and since the program sends one every sec so its quite easy to exhaust it in a long music session which will break the script. We can reduce that one way. Since after a restart its quite certain that there won't be any ad for some time so we can make the detection program sleep for a few min after a restart as we are certain there won't be any ad any time soon. This would somewhat reduce the number of request. What you guys think?

    enhancement 
    opened by daspartho 9
  • Is it possible to bundle the python interpreter installer with main.py in an exe file?

    Is it possible to bundle the python interpreter installer with main.py in an exe file?

    I tried to use PyInstaller to create an exe file from main.py, and it works fine on my main computer that has Python installed, but on my other computer which doesn't have it installed, it gives me the "pip3 not recognized" error. Is there any possible way we could bundle the python3 interpreter with the main.py file in an exe? It would make it a lot more accessible for non computer geeks.

    opened by import-brain 9
  • TypeError: expected str, bytes or os.PathLike object, not NoneType

    TypeError: expected str, bytes or os.PathLike object, not NoneType

    Whenever I attempt to run the code I get this error: TypeError: expected str, bytes or os.PathLike object, not NoneType.
    I run it as follows:

    $ cd C:\Users\me\SpotiByeAds

    $ py main.py Found previously used credentials. Want to use them again? (Y/n) Y

    Awesome, that's all I needed. I'm watching for ads now <.< SUCCESS: The process "Spotify.exe" with PID 12680 has been terminated. SUCCESS: The process "Spotify.exe" with PID 23276 has been terminated. SUCCESS: The process "Spotify.exe" with PID 25124 has been terminated. SUCCESS: The process "Spotify.exe" with PID 11972 has been terminated. SUCCESS: The process "Spotify.exe" with PID 20088 has been terminated. SUCCESS: The process "Spotify.exe" with PID 13544 has been terminated. Traceback (most recent call last): File "C:\Users\me\SpotiByeAds\main.py", line 128, in main(spotify_username, spotifyAccessScope, spotify_client_id, spotify_client_secret, spotifyRedirectURI, PATH) File "C:\Users\me\SpotiByeAds\main.py", line 65, in main restartSpotify(path) File "C:\Users\me\SpotiByeAds\main.py", line 52, in restartSpotify openSpotify(path) File "C:\Users\me\SpotiByeAds\main.py", line 37, in openSpotify subprocess.Popen([path], start_new_session=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, shell=True) File "C:\Users\me\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 951, in init self._execute_child(args, executable, preexec_fn, close_fds, File "C:\Users\me\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1360, in _execute_child args = list2cmdline(args) File "C:\Users\me\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 565, in list2cmdline for arg in map(os.fsdecode, seq): File "C:\Users\me\AppData\Local\Programs\Python\Python39\lib\os.py", line 822, in fsdecode filename = fspath(filename) # Does type-checking of filename. TypeError: expected str, bytes or os.PathLike object, not NoneType`

    opened by mr-hespicable 8
  • A simple fix for issue #44

    A simple fix for issue #44

    Instead of pinging Spotify every second just to check if an ad is playing. We can simply get the song length and wait that amount of time and then check if an ad is playing

    (#44)

    opened by The-Glit-ch 6
  • Fixed issue #44 and crashes on connection errors.

    Fixed issue #44 and crashes on connection errors.

    • Reduced number of requests sent (actually just solved #44).
      • Note that it's possible for ads to be played when the user skips a track.
    • Fixed crashes on connection errors.
    • Tested and works on both Windows and Linux.
    • Fixed #52 introduced by #48.
    opened by AnonymouX47 5
  • Fixed dependency installation and some platform-dependency issues.

    Fixed dependency installation and some platform-dependency issues.

    • Failure in Dependency installation was leading to an infinite loop.
    • Improper platform names were being used.
    • PID was previously hard-coded, but it's never constant.
    opened by AnonymouX47 5
  • Add requirements.txt, dynamic spotify detection, and Linux support

    Add requirements.txt, dynamic spotify detection, and Linux support

    I was a bit bored today and saw your post on Reddit, so I thought that I'd contribute a bit. This pull request adds a few things.

    • .gitignore - File for telling git to ignore Python junk like __pycache__ and also the user's spotipy cache file which contains credentials
    • requirements.txt - File containing the project requirements. This makes it easier for the user to install requirements, since they only have to type pip3 install -r requirements.txt to install all project requirements.
    • Dynamic spotify path detection. I used shutil.which() to automatically detect the spotify file location in the PATH. I still left your path variable, however, so that users can manually override this system.
    • Linux support. I use Linux, so to test the rest of the stuff I had to go ahead and add Linux support. Also, I like things to support more than just Windows in general, so I figured that I'd help out.

    I'd definitely recommend testing this before merging it, as I haven't tested this on Windows. Other than that, feel free to ask me any questions.

    opened by TabulateJarl8 5
  • [Documentation] Could the main README briefly explain how this is detected via the python code? Does not have to be a long explanation, just the main gist of how it works.

    [Documentation] Could the main README briefly explain how this is detected via the python code? Does not have to be a long explanation, just the main gist of how it works.

    [Documentation] Could the main README briefly explain how this is detected via the python code?

    Does not have to be a long explanation, just the main gist of how it works. That way people can understand which part notices when an ad is played. For instance I presently don't know the spotify API so this would be helpful. Thank you for potentially considering and reading this issue request.

    opened by rubyFeedback 5
  • Encryption of stored client secret.

    Encryption of stored client secret.

    I suggest that the user be asked to enter a passphrase of at least 8 ASCII (to reduce complexity) characters. Then that can be used to encrypt the client secret when storing it and to decrypt it when reading it.

    A simple cipher can be used, i'll say the XOR (maybe with a little extra like a random number) is ok... cracking the cipher with such key length will be quite a pain :)

    opened by AnonymouX47 4
  • TypeError : 'method' object is not subscriptable

    TypeError : 'method' object is not subscriptable

    An error was raised by line 71 (time.sleep((spotify.current_user_playing_track['duration_ms']/1000) - 6) #Stop us from getting rate limited from spotify API (It just waits for the song to end)). A quick Google search showed the fix was to replace the brackets in spotify.current_user_playing_track['duration_ms'] with parenthesis. I'll create a PR for it.

    opened by airD173 4
  • doesn't block ads

    doesn't block ads

    Hi, I'm using MacOS and it doesn't block ads. OS: Mac OS error:

    killall: unknown signal r; valid signals:
    HUP INT QUIT ILL TRAP ABRT EMT FPE KILL BUS SEGV SYS PIPE ALRM TERM URG STOP 
    TSTP CONT CHLD TTIN TTOU IO XCPU XFSZ VTALRM PROF WINCH INFO USR1 USR2 
    
    opened by sajjadintel 2
  • Not working at all~~~

    Not working at all~~~

    did exactly what readme says and prompt says: Awesome, that's all I needed. I'm watching for ads now <.<

    but when spoti AD kicks in, nothing happens....is this a sca m?

    Edit: So I'm having 2 different spoti accounts, but this is more wired because when I sign in develop with 2nd account which I currently listening to, the main.py console will close immediately after I enter my password, the message was lighting fast that I will never be able to read....any advice? thanks!

    opened by vacarogit 1
  • New documentation theme

    New documentation theme

    I was experimenting with moving the documentation from the Read The Docs Sphinx theme to the Press Sphinx theme. You can compare them at https://spotibyeads.readthedocs.io/en/latest/ and https://spotibyeads.readthedocs.io/en/press-theme/ respectively. My personal opinion is that the press theme looks nicer, but since I have to manually scale the images (as compared to the automatic scaling on the RTD theme), the images are too small on high-resolution displays and too big on mobile and low-resolution displays. They only look as intended on a 1080p desktop monitor, which I think most people will use, but it's still something to consider.

    opened by airD173 6
  • Prebuilt executables

    Prebuilt executables

    I think we should make a separate thread since this is a common request. We have a way to use py2app for Mac, but my attempts with pyinstaller and cxfreeze on windows have been unsuccessful. Has anyone else built outside of Mac?

    opened by airD173 18
  • Issues with manjaro

    Issues with manjaro

    When running on manjaro the program doesn't close spotify. It still opens a new window tho. There for ads aren't skipped. Specs:

    OS: Manjaro Linux x86_64 
    Kernel: 5.10.53-1-MANJARO 
    Shell: bash 5.1.8 
    WM: i3 
    Terminal: kitty 
    CPU: AMD Ryzen 7 3700X (16) @ 3.600GHz 
    GPU: NVIDIA GeForce GTX 1660 
    Memory: 2875MiB / 15990MiB 
    
    opened by ceceba223 6
Owner
Partho
Partho
Demodulate and error correct FIS-B and ADS-B signals on 978 MHz.

FIS-B 978 ('fisb-978') is a set of programs that demodulates and error corrects FIS-B (Flight Information System - Broadcast) and ADS-B (Automatic Dep

null 2 Nov 15, 2022
Insert a Spotify Playlist, Get a list of YouTube URLs from it.

spotbee This is a module that spits out YouTube URLs from Spotify Playlist URLs Why use this? It is asynchronous which makes it compatible to use with

Nishant Sapkota 10 Apr 6, 2022
A tool for study using pomodoro methodology, while study mode spotify or any other .exe app is opened and while resting is closed.

Pomodoro-Timer-With-Spotify-Connection A tool for study using pomodoro methodology, while study mode spotify or any other .exe app is opened and while

null 2 Oct 23, 2022
A Python application that helps users determine their calorie intake, and automatically generates customized weekly meal and workout plans based on metrics computed using their physical parameters

A Python application that helps users determine their calorie intake, and automatically generates customized weekly meal and workout plans based on metrics computed using their physical parameters

Anam Iqbal 1 Jan 13, 2022
💻 Algo-Phantoms-Backend is an Application that provides pathways and quizzes along with a code editor to help you towards your DSA journey.📰🔥 This repository contains the REST APIs of the application.✨

Algo-Phantom-Backend ?? Algo-Phantoms-Backend is an Application that provides pathways and quizzes along with a code editor to help you towards your D

Algo Phantoms 44 Nov 15, 2022
ArinjoyTheDev 1 Jul 17, 2022
A script to automatically update bot status at GitHub as well as in Telegram channel.

A simple & short repository to show your bot's status in your GitHub README.md file as well as in you channel.

Jainam Oswal 55 Dec 13, 2022
Quick script for automatically extracting syscall numbers for an OS

Syscalls-Extractor Quick script for automatically extracting syscall numbers for an OS $ python3 .\syscalls-extractor.py --help usage: syscalls-extrac

m0rv4i 54 Feb 10, 2022
This script is written with Python for selling steam community items automatically.

SteamCommunityItemAutoSell Description This script is written with Python for selling steam community items automatically. Install git clone https://g

null 14 Oct 26, 2022
A tool that automatically creates fuzzing harnesses based on a library

AutoHarness is a tool that automatically generates fuzzing harnesses for you. This idea stems from a concurrent problem in fuzzing codebases today: large codebases have thousands of functions and pieces of code that can be embedded fairly deep into the library. It is very hard or sometimes even impossible for smart fuzzers to reach that codepath. Even for large fuzzing projects such as oss-fuzz, there are still parts of the codebase that are not covered in fuzzing. Hence, this program tries to alleviate this problem in some capacity as well as provide a tool that security researchers can use to initially test a code base. This program only supports code bases which are coded in C and C++.

null 261 Jan 4, 2023
Automatically find solutions when your Python code encounters an issue.

What The Python?! Helping you find answers to the errors Python spits out. Installation You can find the source code on GitHub at: https://github.com/

What The Python?! 139 Dec 14, 2022
Automatically give thanks to Pypi packages you use in your project!

Automatically give thanks to Pypi packages you use in your project!

Ward 25 Dec 20, 2021
Add-In for Blender to automatically save files when rendering

Autosave - Render: Automatically save .blend, .png and readme.txt files when rendering with Blender Purpose This Blender Add-On provides an easy way t

Volker 9 Aug 10, 2022
Addon to give a keybind to automatically enable contact shadows on all lights in a scene

3-2-1 Contact(Shadow) An easy way to let you enable contact shadows on all your lights, because Blender doesn't enable it by default, and doesn't give

TDV Alinsa 3 Feb 2, 2022
Clock in automatically in SCU.

auto_clock_in Clock in automatically in SCU. Features send logs to Telegram bot How to use? pip install -r requirements.txt () edit user_list, token_A

null 2 Dec 13, 2021
Automatically re-open threads when they get archived, no matter your boost level!

ThreadPersist Automatically re-open threads when they get archived, no matter your boost level! Installation You will need to install poetry to run th

null 7 Sep 18, 2022
Automatically remove user join messages when the user leaves the server.

CleanLeave Automatically remove user join messages when the user leaves the server. Installation You will need to install poetry to run this bot local

null 11 Sep 19, 2022
Chess bot can play automatically as white or black on lichess.com, chess.com and any website using drag and drop to move pieces

Chessbot "Why create another chessbot ?" The explanation is simple : I did not find a free bot I liked online : all the bots I saw on internet are par

Dhimas Bagus Prayoga 2 Nov 11, 2021
An app to automatically take attendance by scanning students' bar coded ID card as they enter the classroom.

Auto Classroom Attendance This application may be run on a PC to automatically scan students' ID card using a generic bar code scanner and output the

null 1 Nov 10, 2021