py是用python编写的spotify的异步api包装器。
spotif的Python项目详细描述
spotify.py
spotify客户端的api库和用python编写的spotifywebapi。
py是一个主要的异步库(到http客户端的所有东西都是异步友好的)。
同步支持
库还支持syncronous与spotify.sync
importspotify.syncasspotify# Nothing requires async/await now!
示例
- 按流行程度排序播放列表
importspotifyplaylist_uri=# Playlist uri hereclient_id=# App client id heresecret=# App secret heretoken=# User token hereclient=spotify.Client(client_id,secret)asyncdefmain():user=awaitspotify.User.from_token(client,token)playlist=next(filter((lambdaplaylist:playlist.uri==playlist_uri),awaituser.get_playlists()))tracks=awaitplaylist.get_all_tracks()sorted_tracks=sorted(tracks,reverse=True,key=(lambdatrack:track.popularity))awaituser.replace_tracks(playlist,sorted_tracks)if__name__=='__main__':client.loop.run_until_complete(main())
安装
要安装库,只需克隆它并运行setup.py
git clone https://github.com/mental32/spotify.py
python3 setup.py install
或者使用pypi
pip3 install spotify
(最新稳定)pip3 install -U git+https://github.com/mental32/spotify.py
(每晚)