updated variable names, added to auth process, added device_name to player
This commit is contained in:
parent
0a72b4678f
commit
59d073f666
@ -33,12 +33,8 @@ def play(username=None):
|
|||||||
net = database.get_authed_network(username)
|
net = database.get_authed_network(username)
|
||||||
|
|
||||||
player = Player(net)
|
player = Player(net)
|
||||||
device = None
|
player.play(context=context, device_name=request_json.get('device_name', None))
|
||||||
if 'device_name' in request_json:
|
|
||||||
devices = net.get_available_devices()
|
|
||||||
device = next((i for i in devices if i.name == request_json['device_name']), None)
|
|
||||||
|
|
||||||
player.play(context=context, device=device)
|
|
||||||
logger.info(f'played {uri}')
|
logger.info(f'played {uri}')
|
||||||
return jsonify({'message': 'played', 'status': 'success'}), 200
|
return jsonify({'message': 'played', 'status': 'success'}), 200
|
||||||
else:
|
else:
|
||||||
@ -53,12 +49,8 @@ def play(username=None):
|
|||||||
|
|
||||||
if playlist_to_play is not None:
|
if playlist_to_play is not None:
|
||||||
player = Player(net)
|
player = Player(net)
|
||||||
device = None
|
player.play(context=Context(playlist_to_play.uri), device_name=request_json.get('device_name', None))
|
||||||
if 'device_name' in request_json:
|
|
||||||
devices = net.get_available_devices()
|
|
||||||
device = next((i for i in devices if i.name == request_json['device_name']), None)
|
|
||||||
|
|
||||||
player.play(context=Context(playlist_to_play.uri), device=device)
|
|
||||||
logger.info(f'played {request_json["playlist_name"]}')
|
logger.info(f'played {request_json["playlist_name"]}')
|
||||||
return jsonify({'message': 'played', 'status': 'success'}), 200
|
return jsonify({'message': 'played', 'status': 'success'}), 200
|
||||||
else:
|
else:
|
||||||
@ -74,12 +66,8 @@ def play(username=None):
|
|||||||
net = database.get_authed_network(username)
|
net = database.get_authed_network(username)
|
||||||
|
|
||||||
player = Player(net)
|
player = Player(net)
|
||||||
device = None
|
player.play(tracks=uris, device_name=request_json.get('device_name', None))
|
||||||
if 'device_name' in request_json:
|
|
||||||
devices = net.get_available_devices()
|
|
||||||
device = next((i for i in devices if i.name == request_json['device_name']), None)
|
|
||||||
|
|
||||||
player.play(tracks=uris, device=device)
|
|
||||||
logger.info(f'played tracks')
|
logger.info(f'played tracks')
|
||||||
return jsonify({'message': 'played', 'status': 'success'}), 200
|
return jsonify({'message': 'played', 'status': 'success'}), 200
|
||||||
else:
|
else:
|
||||||
|
@ -178,6 +178,8 @@ def token():
|
|||||||
user_reference.update({
|
user_reference.update({
|
||||||
'access_token': resp['access_token'],
|
'access_token': resp['access_token'],
|
||||||
'refresh_token': resp['refresh_token'],
|
'refresh_token': resp['refresh_token'],
|
||||||
|
'last_refreshed': datetime.datetime.now(datetime.timezone.utc),
|
||||||
|
'token_expiry': resp['expires_in'],
|
||||||
'spotify_linked': True
|
'spotify_linked': True
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -200,6 +202,8 @@ def deauth():
|
|||||||
user_reference.update({
|
user_reference.update({
|
||||||
'access_token': None,
|
'access_token': None,
|
||||||
'refresh_token': None,
|
'refresh_token': None,
|
||||||
|
'last_refreshed': datetime.datetime.now(datetime.timezone.utc),
|
||||||
|
'token_expiry': None,
|
||||||
'spotify_linked': False
|
'spotify_linked': False
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -17,7 +17,8 @@ def refresh_token_database_callback(user):
|
|||||||
user_ref = get_user_doc_ref(user.user_id)
|
user_ref = get_user_doc_ref(user.user_id)
|
||||||
|
|
||||||
user_ref.update({
|
user_ref.update({
|
||||||
'access_token': user.accesstoken,
|
'access_token': user.access_token,
|
||||||
|
'refresh_token': user.refresh_token,
|
||||||
'last_refreshed': user.last_refreshed,
|
'last_refreshed': user.last_refreshed,
|
||||||
'token_expiry': user.token_expiry
|
'token_expiry': user.token_expiry
|
||||||
})
|
})
|
||||||
@ -44,7 +45,7 @@ def get_authed_network(username):
|
|||||||
|
|
||||||
if user_dict['last_refreshed'] + timedelta(seconds=user_dict['token_expiry'] - 1) \
|
if user_dict['last_refreshed'] + timedelta(seconds=user_dict['token_expiry'] - 1) \
|
||||||
< datetime.now(timezone.utc):
|
< datetime.now(timezone.utc):
|
||||||
user_obj.refresh_token()
|
user_obj.refresh_access_token()
|
||||||
|
|
||||||
user_obj.refresh_info()
|
user_obj.refresh_info()
|
||||||
return Network(user_obj)
|
return Network(user_obj)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from spotframework.util.console import Color
|
||||||
from spotframework.net.user import NetworkUser
|
from spotframework.net.user import NetworkUser
|
||||||
|
|
||||||
|
|
||||||
@ -7,3 +8,7 @@ class DatabaseUser(NetworkUser):
|
|||||||
super().__init__(client_id=client_id, client_secret=client_secret,
|
super().__init__(client_id=client_id, client_secret=client_secret,
|
||||||
refresh_token=refresh_token, access_token=access_token)
|
refresh_token=refresh_token, access_token=access_token)
|
||||||
self.user_id = user_id
|
self.user_id = user_id
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return Color.RED + Color.BOLD + 'DatabaseUser' + Color.END + \
|
||||||
|
f': {self.user_id}, {self.username}, {self.display_name}, {self.uri}'
|
||||||
|
Loading…
Reference in New Issue
Block a user