Coder Social home page Coder Social logo

spotibyeads's Introduction

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 started playing, interrupting your mood? With SpotiByeAds, you can listen ad-free, allowing you to concentrate 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. Please 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 Ctrl-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.

spotibyeads's People

Contributors

aird173 avatar anonymoux47 avatar ceceba223 avatar daspartho avatar greavettey avatar jimmy-print avatar noah6544 avatar roljy avatar the-glit-ch avatar warpwing avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

spotibyeads's Issues

Queue disappears aftert restart

Found this thing that if i added some song in a queue to play next and an Ad comes resulting in restart, it will clear the queue.

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 

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?

How about hotkeys?

I hade rewriten code using hotkeys functions from pynput, should i post it on my repository or should i make branch in this one?

Wrong badge link

The forks badge links to stargazers. This is a pretty minor issue and I'm on my phone at the moment, so I'll fix this myself tomorrow.

Installation instructions have a mistake

In the installation instructions, it says to run cd SpotiByeAds.py after cloning. It should be changed to cd SpotiByeAds without the .py extension, as the folder that is cloned is called SpotiByeAds.

running the program

i can input all the data when it askes for it in python. after that nothing happens at all tho. no box where it asks for permissions

[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.

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!

write credential inside the main folder

normally the code will write a credential.json file to store the clientID etc aswell as a cache text file, but the files are written outside of the SpotiByeAds-main folder, it messes up your file organization and can be pretty easily fixed

in open("./credentials.json", "r") and open("./credentials.json", "w") add in /SpotiByeAds-main or whatever you named the file to get open("./SpotiByeAds-main/credentials.json", "r") for read and write respectively, now the .json file will write to a better spot

i dont know how to make the cache file write into the folder though, it's probably something on the spotify for devs side

PATH variable gives a syntax error

Change the string to a raw string
Like so:
PATH = 'C:\Users\USERNAME\AppData\Roaming\Spotify'
to
PATH = r'C:\Users\USERNAME\AppData\Roaming\Spotify'

Can't find spotify.exe

For some reason this issue from a while ago didn't submit. After putting in credentials, the program spits out an error about being unable to find spotify.exe. I checked, and my spotify executable is Spotify.exe. I'll submit a PR for this, but I'm curious about why nobody else has had this error yet. I didn't change the executable name, this is exactly how it was installed.

Need for a stable and standard update mechanism.

For those that don't use or are not used to git, updating the script after changes have been made could be clumsy.
I suggest including a script for this purpose.

I propose this following:

SpotiByeAds/
    ...
    update.py
    VERSION  # Will contain current version number.

update.py downloads and reads "VERSION" file from git repo to check if an update is available.
If an update is available, downloads the master zip and extracts it (using python's zipfile).

I did not directly open a PR, so that this can be properly discussed before implementation.

Might not skip ads when the user manually skips a track or changes playlist.

Was introduced by #51 (in response to #44).

I figured out a [maybe] temporary but workable fix for the exception of skipping tracks.

A keyboard interrupt (Ctrl-C) can be sent to the program to trigger a dialogue that asks if the user wants to skip a track, change playlist or exit the program.

If the user chooses to skip a track... the program sends the appropriate key signal to automatically do that.

If the user wants to change the playlist, the script would request that the user confirms a dialogue after changing the track.

This way, the script handles skipping tracks and knows when the playlist is changed, hence it can simply go ahead to wait for the new track or skip an ad that pops up next :)

What do you think?

Originally addressed by @AnonymouX47 in #51 (comment)

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?

unspecified except: in line 43

There is a unspecified except: in line 43. This can lead to the KeyboardInterrupt - which gets raised when you hit CTRL+C to exit the program - not being registered. There for making it impossible to exit the program.

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`

Can we add web version ?

can we add a feature to use this in spotify web ?
it will be very convenient. If possible i'll contribute too with whatever I can.
thank you,

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.

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.

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 :)

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.

the script stopped when detected an ad I guess

here's the error message,
main(spotify_username, spotifyAccessScope, spotify_client_id, spotify_client_secret, spotifyRedirectURI, PATH)
File "main.py", line 96, in main
if current_track['item']['name'] != last_track: # Next track
TypeError: 'NoneType' object is not subscriptable

TypeError: 'NoneType' object is not subscriptable

It crashes after a while. And returns the above error. It says,
" line 99, in main
if current_track['item']['name'] != last_track: # Next track
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
TypeError: 'NoneType' object is not subscriptable"

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 

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.