-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathspotify_pause.py
29 lines (28 loc) · 932 Bytes
/
spotify_pause.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import pyautogui
import os
import pickle
import spotipy
from spotipy.oauth2 import SpotifyOAuth
from spotipy.oauth2 import SpotifyClientCredentials
def spotify_pause():
# Load spotify credentials
credentials_path = './credentials/spotify/token.pickle'
if os.path.exists(credentials_path):
with open(credentials_path, 'rb') as token_file:
spotify_token = pickle.load(token_file)
else:
raise FileNotFoundError("Spotify token file not found.")
token_info = SpotifyOAuth(token=spotify_token)
# Initialization
if not token_info:
print("No account found")
return None
else:
sp = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials())
if sp is None:
return None
# Check to see if a song is currently playing
if sp.currently_playing:
pyautogui.press('stop')
else:
print("No song currently playing")