removed user refresh by default, added URI instance checking
This commit is contained in:
parent
933e70ee44
commit
da8d65e8ba
1
alarm.py
1
alarm.py
@ -45,6 +45,7 @@ if __name__ == '__main__':
|
||||
network = Network(NetworkUser(os.environ['SPOTCLIENT'],
|
||||
os.environ['SPOTSECRET'],
|
||||
os.environ['SPOTREFRESH']))
|
||||
network.user.refresh_token()
|
||||
|
||||
found = False
|
||||
|
||||
|
@ -32,6 +32,7 @@ if __name__ == '__main__':
|
||||
network = Network(NetworkUser(os.environ['SPOTCLIENT'],
|
||||
os.environ['SPOTSECRET'],
|
||||
os.environ['SPOTREFRESH']))
|
||||
network.user.refresh_token()
|
||||
playlists = network.get_user_playlists()
|
||||
|
||||
for playlist in playlists:
|
||||
|
@ -125,9 +125,9 @@ def go():
|
||||
net = Network(NetworkUser(os.environ['SPOTCLIENT'],
|
||||
os.environ['SPOTSECRET'],
|
||||
os.environ['SPOTREFRESH']))
|
||||
net.user.refresh_token()
|
||||
|
||||
engine = PlaylistEngine(net)
|
||||
engine.load_user_playlists()
|
||||
|
||||
for super_playlist in to_execute:
|
||||
update_super_playlist(engine, super_playlist)
|
||||
|
@ -18,5 +18,6 @@ if __name__ == '__main__':
|
||||
network = Network(NetworkUser(os.environ['SPOTCLIENT'],
|
||||
os.environ['SPOTSECRET'],
|
||||
os.environ['SPOTREFRESH']))
|
||||
network.user.refresh_token()
|
||||
|
||||
print(network.user.access_token)
|
||||
|
@ -31,6 +31,7 @@ def go(playlist_name):
|
||||
net = Network(NetworkUser(os.environ['SPOTCLIENT'],
|
||||
os.environ['SPOTSECRET'],
|
||||
os.environ['SPOTREFRESH']))
|
||||
net.user.refresh_token()
|
||||
|
||||
engine = PlaylistEngine(net)
|
||||
engine.reorder_playlist_by_added_date(playlist_name)
|
||||
|
@ -15,6 +15,8 @@ class Context:
|
||||
self.uri = Uri(uri)
|
||||
else:
|
||||
self.uri = uri
|
||||
if self.uri.object_type not in [Uri.ObjectType.album, Uri.ObjectType.artist, Uri.ObjectType.playlist]:
|
||||
raise TypeError('context uri must be one of album, artist, playlist')
|
||||
self.object_type = object_type
|
||||
self.href = href
|
||||
self.external_spot = external_spot
|
||||
|
@ -86,6 +86,10 @@ class SpotifyTrack(Track):
|
||||
return Color.BOLD + Color.YELLOW + 'SpotifyTrack' + Color.END + \
|
||||
f': {self.name}, ({self.album}), {self.artists}, {self.uri}'
|
||||
|
||||
@staticmethod
|
||||
def get_uri_shell(uri):
|
||||
return SpotifyTrack(name=None, album=None, artists=None, uri=uri)
|
||||
|
||||
|
||||
class LibraryTrack(SpotifyTrack):
|
||||
def __init__(self,
|
||||
|
@ -5,6 +5,7 @@ from base64 import b64encode
|
||||
import logging
|
||||
import time
|
||||
from typing import Optional
|
||||
from datetime import datetime, timezone
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -20,8 +21,10 @@ class NetworkUser(User):
|
||||
self.client_id = client_id
|
||||
self.client_secret = client_secret
|
||||
|
||||
self.refresh_token()
|
||||
self.refresh_info()
|
||||
self.last_refreshed = None
|
||||
self.token_expiry = None
|
||||
|
||||
self.on_refresh = []
|
||||
|
||||
def __repr__(self):
|
||||
return Color.RED + Color.BOLD + 'NetworkUser' + Color.END + \
|
||||
@ -43,11 +46,17 @@ class NetworkUser(User):
|
||||
|
||||
data = {"grant_type": "refresh_token", "refresh_token": self.refreshtoken}
|
||||
|
||||
now = datetime.now(timezone.utc)
|
||||
req = requests.post('https://accounts.spotify.com/api/token', data=data, headers=headers)
|
||||
|
||||
if 200 <= req.status_code < 300:
|
||||
logger.debug('token refreshed')
|
||||
self.accesstoken = req.json()['access_token']
|
||||
resp = req.json()
|
||||
self.accesstoken = resp['access_token']
|
||||
self.token_expiry = resp['expires_in']
|
||||
self.last_refreshed = now
|
||||
for func in self.on_refresh:
|
||||
func(self)
|
||||
else:
|
||||
|
||||
if req.status_code == 429:
|
||||
|
Loading…
Reference in New Issue
Block a user