This commit is contained in:
jaydee
2022-12-14 02:09:37 +01:00
parent 2a4cb0dad3
commit 67c49df791
47 changed files with 20836 additions and 0 deletions

38
spotify copy.py Normal file
View File

@@ -0,0 +1,38 @@
import spotipy
from spotipy.oauth2 import SpotifyOAuth
import time
USERNAME = '...'
CLIENT_ID = '...'
CLIENT_SECRET = '...'
SCOPE = 'user-read-currently-playing'
def create_spotify():
auth_manager = SpotifyOAuth(
scope='user-read-playback-state',
username='jaydee',
redirect_uri='https://ha.sectorq.eu/auth/external/callback',
client_id='6a37229fc9a04878a608d519ea4b1d22',
client_secret='6569f6f876234093983920de2966ff84')
spotify = spotipy.Spotify(auth_manager=auth_manager)
return auth_manager, spotify
def refresh_spotify(auth_manager, spotify):
token_info = auth_manager.cache_handler.get_cached_token()
if auth_manager.is_token_expired(token_info):
auth_manager, spotify = create_spotify()
return auth_manager, spotify
if __name__ == '__main__':
auth_manager, spotify = create_spotify()
while True:
auth_manager, spotify = refresh_spotify(auth_manager, spotify)
playing = spotify.currently_playing()
if playing:
print(playing['item']['name'])
else:
print('Nothing is playing.')
time.sleep(30)