def request_token_spotty(spotty):
'''request token by using the spotty binary'''
token_info = None
if spotty.playback_supported:
try:
args = ["-t", "--client-id", CLIENTID, "--scope", ",".join(SCOPE), "-n", "temp"]
spotty = spotty.run_spotty(arguments=args)
stdout, stderr = spotty.communicate()
result = None
log_msg(stdout, xbmc.LOGDEBUG)
for line in stdout.split():
line = line.strip()
if line.startswith("{\"accessToken\""):
result = eval(line)
# transform token info to spotipy compatible format
if result:
token_info = {}
token_info["access_token"] = result["accessToken"]
token_info["expires_in"] = result["expiresIn"]
token_info["token_type"] = result["tokenType"]
token_info["scope"] = ' '.join(result["scope"])
token_info['expires_at'] = int(time.time()) + token_info['expires_in']
token_info['refresh_token'] = result["accessToken"]
log_msg("Token from spotty: %s" % token_info, xbmc.LOGDEBUG)
except Exception as exc:
log_exception(__name__, exc)
return token_info
评论列表
文章目录