lfmxtractplus是一个用于提取last.fm scrobbles和spotify音频功能的库,可用于熊猫
lfmxtractplus的Python项目详细描述
lfmxtractplus
说明
lfmxtractplus是一个用于提取Last.fmscrobbles和spotifyaudio features的库,用于Pandas
工作
使用带有user.getRecentTracks端点的last.fm的api检索用户的scrobble。 因为last.fm的api没有提供直接检索spotifyaudio features的方法 我们使用sp.search()方法搜索spotify以查找曲目的spotifyid(trackid),并使用spotifyid使用sp.audio_features()方法检索每个曲目的音频特性。
安装
如果您的系统上已经有Python了,您可以通过下载发行版来安装库,将其解包并以通常的方式安装:
更改日志
1.2版
- 在类中封装方法
- 为get_playlist()添加了令牌刷新功能
- 优化导入
1.1版
- 添加了对将日志输出到文件而不是控制台的支持
- 固定进度条
- 将时区移出config.yaml
1.0版
- 初始版本
python setup.py install
您还可以使用流行的软件包管理器安装
pip install lfmxtractplus
或
easy_install lfmxtractplus
依赖关系
- spotipy>;=2.4.4
- pandas>;=0.22.0
- PyYAML>;=5.1.1
- numpy>;=1.14.0
- requests>;=2.22.0
- tqdm>;=4.31.1
快速启动
要开始,只需安装lfmxtractplus,使用config.yaml初始化,访问显示的链接并使用spotify帐户登录,复制重定向url并将其粘贴回python提示符 调用方法:
importlfmxtractplusaslxpimportpandasaspdlf=lxp.lfmxtractplus('config.yaml')#path to config.yamlscrobbles_dict=lf.generate_dataset(lfusername='madhan_001',pages=0)scrobbles_df=scrobbles_dict['complete']
配置yaml
此文件必须包含last.fm和spotify的api密钥。
#spotify api credentials (visit https://developer.spotify.com)sp_cid:#spotify client IDsp_secret:#spotify client secret#last.fm api key (visit https://www.last.fm/api)lf_key:#last.fm API key#filepath for log filelog_path:'\logs\\output.log'#path for output.log
文档
初始化(cfgpath)
调用初始化所需的函数,处理加载配置文件, 初始化记录器对象,初始化spotipy对象。
访问显示的链接并使用spotify帐户登录,复制重定向url并将其粘贴回python提示符。
在调用其他函数之前被调用。
:param cfgPath: filepath for config.yaml
生成数据集(lfusername,时区='asia/kolkata',pages=0)
获取用户的收听历史并使用Spotify音频功能丰富它。
:param lfusername: last.fm username
:param timezone: timezone of the user (must correspond with the timezone in user's settings)
:param pages: number of pages to retrieve, use pages = 0 to retrieve full listening history
:return scrobblesDFdict: dictionary with two dataframes ('complete' with timestamps and 'library' with library contents)
警告:不支持多个时区浏览
获取播放列表(user='billboard.com',playlist='6uesakyzhiet4nb3uad6nq')
检索播放列表的音频功能(默认播放列表为Billboard Hot 100)
:param user: username of the playlist owner
:param playlist_id: playlist id (found at the end of a playlist url)
:return: a dataframe with audio features of a playlist
未映射的轨迹(scrobblesdf)
返回无法映射到Spotify的数据帧跟踪。
:param scrobblesDF: dataframe with scrobbled tracks and trackIDs
:return scrobblesDF: dataframe containing tracks with no trackIDs
示例
报告问题
如果您有特定于此库的建议、错误或其他问题,请在github上提交问题。或者给我一个请求。