├── ByeAds.py ├── README.md └── requirements.txt /ByeAds.py: -------------------------------------------------------------------------------- 1 | # SpotiByeBye 2 | # by @SakDev (github) 3 | 4 | import os 5 | import time 6 | import spotipy 7 | import spotipy.util as util 8 | from pynput.keyboard import Key, Controller 9 | 10 | keyboard = Controller() 11 | 12 | 13 | def closeSpotify(): 14 | os.system("taskkill /f /im spotify.exe") 15 | time.sleep(0.25) 16 | 17 | 18 | def openSpotify(): 19 | os.system('spotify.exe') 20 | time.sleep(0.25) 21 | 22 | 23 | def playSpotify(): 24 | time.sleep(1.5) 25 | keyboard.press(Key.media_play_pause) 26 | keyboard.release(Key.media_play_pause) 27 | keyboard.press(Key.media_next) 28 | keyboard.release(Key.media_next) 29 | time.sleep(2.0) 30 | keyboard.press(Key.alt_l) 31 | keyboard.press(Key.tab) 32 | keyboard.release(Key.alt_l) 33 | keyboard.release(Key.tab) 34 | 35 | 36 | def restartSpotify(): 37 | closeSpotify() 38 | openSpotify() 39 | playSpotify() 40 | 41 | 42 | spotifyUsername = "#EnterUsernameHere" 43 | spotifyClientID = "#EnterClientIDHere" 44 | spotifyClientSecret = "#EnterClientSecretHere" 45 | spotifyAccessScope = "user-read-currently-playing user-modify-playback-state" 46 | spotifyRedirectURI = "http://google.com/" 47 | 48 | def setupSpotifyObject(username, scope, clientID, clientSecret, redirectURI): 49 | token = util.prompt_for_user_token(username, scope, clientID, clientSecret, redirectURI) 50 | return spotipy.Spotify(auth=token) 51 | 52 | 53 | def main(): 54 | global spotifyObject 55 | 56 | try: 57 | trackInfo = spotifyObject.current_user_playing_track() 58 | 59 | except: 60 | print("Token Expired") 61 | spotifyObject = setupSpotifyObject(spotifyUsername, spotifyAccessScope, spotifyClientID, spotifyClientSecret, 62 | spotifyRedirectURI) 63 | trackInfo = spotifyObject.current_user_playing_track() 64 | 65 | try: 66 | if trackInfo['currently_playing_type'] == 'ad': 67 | restartSpotify() 68 | except TypeError: 69 | pass 70 | 71 | #use print(trackInfo) here to get live data about the currently playing track 72 | 73 | 74 | spotifyObject = setupSpotifyObject(spotifyUsername, spotifyAccessScope, spotifyClientID, spotifyClientSecret, 75 | spotifyRedirectURI) 76 | 77 | while (True): 78 | main() 79 | time.sleep(1) 80 | 81 | 82 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SpotiByeBye 2 | ## How it works 3 | The program detects when an advertisement plays by monitoring the type of the track that is currently playing, using the Spotipy API. 4 | When an ad is detected, the program restarts Spotify by the os module and plays it via pynput. 5 | 6 | ## Setting up the Spotify API 7 | 1. Go to https://developer.spotify.com/dashboard and sign in with your Spotify account. 8 | 2. Click on the 'CREATE AN APP' option and provide an app name and app description as you'd like. 9 | 3. Go to 'EDIT SETTINGS' and **exactly** fill in the Redirect URIs placeholder with https://google.com/, and click on Save. 10 | 4. Copy the Client ID and Client Secret and paste it in the corresponding place holders in ByeAds.py. 11 | 12 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pynput==1.6.8 2 | spotipy==2.14.0 3 | --------------------------------------------------------------------------------