resources.py 文件源码

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

项目:Harmonbot 作者: Harmon758 项目源码 文件源码
def spotifyinfo(self, ctx, url : str):
        '''Information about a Spotify track'''
        path = urllib.parse.urlparse(url).path
        if path[:7] != "/track/":
            await self.bot.embed_reply(":no_entry: Syntax error")
            return
        trackid = path[7:]
        api_url = "https://api.spotify.com/v1/tracks/" + trackid
        async with clients.aiohttp_session.get(api_url) as resp:
            data = await resp.json()
        # tracknumber = str(data["track_number"])
        description = "Artist: [{}]({})\n".format(data["artists"][0]["name"], data["artists"][0]["external_urls"]["spotify"])
        description += "Album: [{}]({})\n".format(data["album"]["name"], data["album"]["external_urls"]["spotify"])
        description += "Duration: {}\n".format(utilities.secs_to_colon_format(data["duration_ms"] / 1000))
        description += "[Preview]({})".format(data["preview_url"])
        await self.bot.embed_reply(description, title = data["name"], title_url = url, thumbnail_url = data["album"]["images"][0]["url"])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号