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'],
|
network = Network(NetworkUser(os.environ['SPOTCLIENT'],
|
||||||
os.environ['SPOTSECRET'],
|
os.environ['SPOTSECRET'],
|
||||||
os.environ['SPOTREFRESH']))
|
os.environ['SPOTREFRESH']))
|
||||||
|
network.user.refresh_token()
|
||||||
|
|
||||||
found = False
|
found = False
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ if __name__ == '__main__':
|
|||||||
network = Network(NetworkUser(os.environ['SPOTCLIENT'],
|
network = Network(NetworkUser(os.environ['SPOTCLIENT'],
|
||||||
os.environ['SPOTSECRET'],
|
os.environ['SPOTSECRET'],
|
||||||
os.environ['SPOTREFRESH']))
|
os.environ['SPOTREFRESH']))
|
||||||
|
network.user.refresh_token()
|
||||||
playlists = network.get_user_playlists()
|
playlists = network.get_user_playlists()
|
||||||
|
|
||||||
for playlist in playlists:
|
for playlist in playlists:
|
||||||
|
@ -125,9 +125,9 @@ def go():
|
|||||||
net = Network(NetworkUser(os.environ['SPOTCLIENT'],
|
net = Network(NetworkUser(os.environ['SPOTCLIENT'],
|
||||||
os.environ['SPOTSECRET'],
|
os.environ['SPOTSECRET'],
|
||||||
os.environ['SPOTREFRESH']))
|
os.environ['SPOTREFRESH']))
|
||||||
|
net.user.refresh_token()
|
||||||
|
|
||||||
engine = PlaylistEngine(net)
|
engine = PlaylistEngine(net)
|
||||||
engine.load_user_playlists()
|
|
||||||
|
|
||||||
for super_playlist in to_execute:
|
for super_playlist in to_execute:
|
||||||
update_super_playlist(engine, super_playlist)
|
update_super_playlist(engine, super_playlist)
|
||||||
|
@ -18,5 +18,6 @@ if __name__ == '__main__':
|
|||||||
network = Network(NetworkUser(os.environ['SPOTCLIENT'],
|
network = Network(NetworkUser(os.environ['SPOTCLIENT'],
|
||||||
os.environ['SPOTSECRET'],
|
os.environ['SPOTSECRET'],
|
||||||
os.environ['SPOTREFRESH']))
|
os.environ['SPOTREFRESH']))
|
||||||
|
network.user.refresh_token()
|
||||||
|
|
||||||
print(network.user.access_token)
|
print(network.user.access_token)
|
||||||
|
@ -31,6 +31,7 @@ def go(playlist_name):
|
|||||||
net = Network(NetworkUser(os.environ['SPOTCLIENT'],
|
net = Network(NetworkUser(os.environ['SPOTCLIENT'],
|
||||||
os.environ['SPOTSECRET'],
|
os.environ['SPOTSECRET'],
|
||||||
os.environ['SPOTREFRESH']))
|
os.environ['SPOTREFRESH']))
|
||||||
|
net.user.refresh_token()
|
||||||
|
|
||||||
engine = PlaylistEngine(net)
|
engine = PlaylistEngine(net)
|
||||||
engine.reorder_playlist_by_added_date(playlist_name)
|
engine.reorder_playlist_by_added_date(playlist_name)
|
||||||
|
@ -15,6 +15,8 @@ class Context:
|
|||||||
self.uri = Uri(uri)
|
self.uri = Uri(uri)
|
||||||
else:
|
else:
|
||||||
self.uri = uri
|
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.object_type = object_type
|
||||||
self.href = href
|
self.href = href
|
||||||
self.external_spot = external_spot
|
self.external_spot = external_spot
|
||||||
|
@ -86,6 +86,10 @@ class SpotifyTrack(Track):
|
|||||||
return Color.BOLD + Color.YELLOW + 'SpotifyTrack' + Color.END + \
|
return Color.BOLD + Color.YELLOW + 'SpotifyTrack' + Color.END + \
|
||||||
f': {self.name}, ({self.album}), {self.artists}, {self.uri}'
|
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):
|
class LibraryTrack(SpotifyTrack):
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
|
@ -5,6 +5,7 @@ from base64 import b64encode
|
|||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -20,8 +21,10 @@ class NetworkUser(User):
|
|||||||
self.client_id = client_id
|
self.client_id = client_id
|
||||||
self.client_secret = client_secret
|
self.client_secret = client_secret
|
||||||
|
|
||||||
self.refresh_token()
|
self.last_refreshed = None
|
||||||
self.refresh_info()
|
self.token_expiry = None
|
||||||
|
|
||||||
|
self.on_refresh = []
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return Color.RED + Color.BOLD + 'NetworkUser' + Color.END + \
|
return Color.RED + Color.BOLD + 'NetworkUser' + Color.END + \
|
||||||
@ -43,11 +46,17 @@ class NetworkUser(User):
|
|||||||
|
|
||||||
data = {"grant_type": "refresh_token", "refresh_token": self.refreshtoken}
|
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)
|
req = requests.post('https://accounts.spotify.com/api/token', data=data, headers=headers)
|
||||||
|
|
||||||
if 200 <= req.status_code < 300:
|
if 200 <= req.status_code < 300:
|
||||||
logger.debug('token refreshed')
|
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:
|
else:
|
||||||
|
|
||||||
if req.status_code == 429:
|
if req.status_code == 429:
|
||||||
|
Loading…
Reference in New Issue
Block a user