从genius.com下载歌词和元数据
lyricsgenius的Python项目详细描述
lyricsgenius:genius.com api的python客户机
lyricsgenius
为存储在Genius.com上的歌曲、艺术家和歌词数据提供了一个简单的界面。
设置
在使用此软件包之前,您需要注册一个(免费)帐户,授权访问the Genius API。genius帐户提供包所需的client_access_token
。有关示例,请参见下面的Usage section。
安装
lyricsgenius
需要python 3。
使用pip
从pypi安装包:
pip install lyricsgenius
或者,从github安装最新版本的软件包:
pip install git+https://github.com/johnwmillr/LyricsGenius.git
用法
导入包并搜索给定艺术家的歌曲:
importlyricsgeniusgenius=lyricsgenius.Genius("my_client_access_token_here")artist=genius.search_artist("Andy Shauf",max_songs=3,sort="title")print(artist.songs)
搜索同一艺术家的单曲:
song=genius.search_song("To You",artist.name)print(song.lyrics)
将歌曲添加到艺术家对象:
artist.add_song(song)
将艺术家的歌曲保存到json文件:
artist.save_lyrics()
在Genius
类中有多种可配置为参数的选项:
genius.verbose=False# Turn off status messagesgenius.remove_section_headers=True# Remove section headers (e.g. [Chorus]) from lyrics when searchinggenius.skip_non_songs=False# Include hits thought to be non-songs (e.g. track lists)genius.excluded_terms=["(Remix)","(Live)"]# Exclude songs with these words in their title
您也可以从命令行调用包:
exportGENIUS_CLIENT_ACCESS_TOKEN="my_client_access_token_here" python3 -m lyricsgenius --help
搜索并保存给定歌曲的歌词:
python3 -m lyricsgenius song "Begin Again""Andy Shauf" --save
搜索“披头士”的五首歌曲并保存歌词:
python3 -m lyricsgenius artist "The Beatles" --max-songs 5 --save
示例项目
- Trucks and Beer: A textual analysis of popular country music
- Neural machine translation: Explaining the Meaning Behind Lyrics
- What makes some blink-182 songs more popular than others?
- Sentiment analysis on hip-hop lyrics
- Does Country Music Drink More Than Other Genres?
- 49 Years of Lyrics: Why So Angry?
贡献
请贡献!如果你想修复一个bug,提出改进建议,或者在项目中添加新功能,只需open an issue或者给我发送一个pull请求。