下载Spotify歌曲和播放列表(使用YouTube)
spotify-onthego的Python项目详细描述
从Spotify下载歌曲和播放列表。曲目下载自 YouTube视频并转换为MP3文件。
更改日志
- 2017-08-31 v1.0.4:为YouTube结果选择引入互动模式
- 2017-07-13 v1.0.3版:
- 跳过受版权保护的视频
- 修复python 3中的unicode参数解析
- 2017-07-06:v1.0.0发布!spotify onthego现在与python 3+兼容。
- 2016-07-09:添加播放列表名称通配符匹配
- 2016-04-17:-将相册艺术添加到MP3文件ID3标记(由@xabixab贡献)
- 2016-03-15:现在可以从“您的音乐”下载曲目!详情见下文。
安装
pip install spotify-onthego
请注意,您将需要有效的Spotify应用程序凭据。如果你没有 有效的客户端id/密钥对,您可以创建spotify应用程序here。
创建spotify应用程序后,还必须添加重定向uri 对于此应用程序(“添加uri”)。
在第一次运行cli工具之后,验证令牌和凭据 将存储在本地配置文件中。
要求
如果你想把下载的文件转换成MP3格式,你需要 安装AVCONV。
对于debian/ubuntu安装:
sudo apt-get install libav-tools
对于OSX安装,需要从源代码编译 安装GCC:
mkdir avconv cd avconv wget https://libav.org/releases/libav-11.tar.xz tar xjf libav-11.tar.xz cd libav-11 ./configure --disable-yasm make install
用法
$ spotify-playlist -h usage: spotify-playlist [-h] [-i] [-S] [-a {webm,ogg,m4a}] [-C] playlist dst Download the tracks of a Spotify playlist from YouTube positional arguments: playlist Name of playlist. E.g: 'Road music' dst Destination directory optional arguments: -h, --help show this help message and exit -i, --interactive Interactively select the song to download from Youtube. -S, --no-skip Don't skip files that were already downloaded. -a {webm,ogg,m4a}, --audio {webm,ogg,m4a} Preferred audio format to download. By default, the best quality audio format will be downloaded. On some platforms (e.g: Debian Wheezy), the default avconv utility does not support audio conversion from webm, so you should specify a different value here. Note that this audio file will eventually be converted to mp3 (unless you specify --no-convert) -C, --no-convert Don't convert audio files to mp3 format.
$ spotify-mymusic -h usage: spotify-mymusic [-h] [-l LIMIT] [-i] [-S] [-a {webm,ogg,m4a}] [-C] dst Download the songs from 'Your Music' positional arguments: dst Destination directory optional arguments: -h, --help show this help message and exit -l LIMIT, --limit LIMIT Limit to top N songs -i, --interactive Interactively select the song to download from Youtube. -S, --no-skip Don't skip files that were already downloaded. -a {webm,ogg,m4a}, --audio {webm,ogg,m4a} Preferred audio format to download. By default, the best quality audio format will be downloaded. On some platforms (e.g: Debian Wheezy), the default avconv utility does not support audio conversion from webm, so you should specify a different value here. Note that this audio file will eventually be converted to mp3 (unless you specify --no-convert) -C, --no-convert Don't convert audio files to mp3 format.
下载播放列表
从“我的播放列表”下载所有歌曲并将其另存为MP3:
spotify-playlist "My Playlist" ./music/myspotifyplaylist/
创建一个cronjob,以便每周一早上7点下载“发现每周”播放列表:
0 7 * * 1 /home/username/venv/bin/spotify-playlist "Discover Weekly" /home/username/music/discoverweekly
也支持通配符:
spotify-playlist "Mixtape*" ./music/
下载喜爱的歌曲
从“我的音乐”下载您最近的30首曲目:
spotify-mymusic -l 30 ./music/mytracks/
交互模式
默认情况下,spotify-onthego下载在youtube上找到的第一个匹配项 搜索"<song title> <artist name>"(歌曲和艺术家由 空位)。如果要手动选择要下载的youtube结果, 使用-i选项在交互模式下运行:
$ spotify-mymusic -i mymusic/ ++ Processing Porcupine Tree - Deadwing [1] Porcupine Tree - DeadWing https://www.youtube.com/watch?v=GMEwM3YHiME [2] Porcupine Tree - Deadwing https://www.youtube.com/watch?v=-Rwp-yvmcRM [3] Porcupine Tree - Deadwing [Lyrics on Video] https://www.youtube.com/watch?v=dDepB1mwPhc [4] Making of Deadwing https://www.youtube.com/watch?v=ZuYjGfaixDM [5] Porcupine Tree- Mellotron Scratch https://www.youtube.com/watch?v=Ag2zXiiuF5Q [6] Porcupine Tree - Shesmovedon (Deadwing ver.) https://www.youtube.com/watch?v=OtfJcTBklh8 [7] Porcupine Tree - Shallow (lyrics) https://www.youtube.com/watch?v=7_8UmXv5Xac [8] Porcupine Tree - Arriving Somewhere But Not Here (lyrics on screen) https://www.youtube.com/watch?v=f2ROFnA4HRA [9] Porcupine Tree - Deadwing (Lyrics) https://www.youtube.com/watch?v=tMMlEZCaQTY [10] Deadwing- Porcupine Tree(Drum Cover) https://www.youtube.com/watch?v=Zb5KTnXGiNU Select song to download (default: 1, next=n):
当然,交互模式不应该用于自动cron作业。
故障排除
在401错误的情况下,这可能是由于以前的授权令牌
没有正确的范围。只需移除
~/.local/share/spotify-onthego/spotify.token
文件并启动命令
再一次。
如果MP3生成失败并显示与Eyed3相关的错误消息,请检查 Eyed3的安装版本至少为0.8:
$ pip freeze | grep eyeD3 eyeD3==0.8
开发
看到不适合你的东西,或者你想看到的东西 包括在内?只要用代码打开一个pull request,或者 Github issue你在哪里 描述你想要的功能。
许可证
这个项目是根据GNU General Public License v3.0授权的。