utils.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:plugin.audio.spotify 作者: marcelveldt 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号