豆瓣红心歌曲导出方法
发表于:
2017-9-23 15:06
4136
目录
提出需求:将豆瓣红心歌曲导出 豆瓣大范围下架能听的本来有一百多首,都是这么多年的“精华”,现在只剩下二十首不到了,蓝瘦、香菇。
君逼臣反,臣不得不反!是时候全面迁移到网易云音乐了!
寻找解决方案 歌曲列表导出到网易云音乐搜索一下发现这样的需求还是非常庞大的,尤其是最近豆瓣为了上市 而更加注重版权保护,然鹅又不去买版权的这个时代,只放水,不进水,水塘迟早是要枯竭的。
这篇文章 :https://zhuanlan.zhihu.com/p/27395665
列出了详细地操作步骤,本来顺着这波操作就应该万事大吉的,可是想不到网易云音乐Mac客户端不支持歌单导入?!
WTF
操作了很久,就是不支持导入。
既然提供了下载链接,那就自己来下载吧!Chrome插件导出的文件是这样的格式:
$ cat 豆瓣红心歌曲备份下载地址.txt
1.流光 http://mr1.doubanio.com/fc71b56bd54cdc553e76d55232655f71/0/fm/song/p1388552_128k.mp3
2.Forever Now http://mr1.doubanio.com/e0f8ef4af2500adbdf288a20f3e16168/0/fm/song/p253711_128k.mp3
3.Rainbow http://mr1.doubanio.com/2105e12e4ebd2467c6cf3fcf738cd4bb/0/fm/song/p1909083_128k.mp3
4.Soak http://mr3.doubanio.com/88480293742702a77788c1cb6a93adb6/0/fm/song/p1471489_128k.mp3
5.Eisbrecher http://mr1.doubanio.com/5fae3b60fd4968485e8ddf509fa51d75/0/fm/song/p601721_128k.mp3
6.D City Rock http://mr3.doubanio.com/f46dfb3f3af881b0a31ddb7adaa4e0b9/2/fm/song/p1807226_128k.mp3
7.Flower Dance http://mr1.doubanio.com/e01ad01b50f9e592864298ed20ba5e9b/0/fm/song/p1695491_128k.mp3
8.オレンジ (トーマ) http://mr3.doubanio.com/0c8af003cbc3012b2d70d209ead5a1a7/0/fm/song/p1954984_128k.mp3
9.일어나 (Stand Up) http://mr3.doubanio.com/bcd2e1a933d93e05f7930eb39a50bd25/0/fm/song/p1934457_128k.mp3
10.今は昔 http://mr1.doubanio.com/76bda89aa62af28d69403d3a40da1264/0/fm/song/p729383_128k.mp3
11.Banjo Laura (Radio Edit) (Naujas) http://mr3.doubanio.com/f6476d3f1acd560c385b15ea312c1822/0/fm/song/p1905449_128k.mp3
12.小河淌水 http://mr3.doubanio.com/7d0efd0a7493387e1ddd05d24c23a843/0/fm/song/p2235469_128k.mp3
13.三寸天堂 http://mr3.doubanio.com/affbb3c9d9f234a77d358c5c8d74ff0a/0/fm/song/p1700409_128k.mp3
14.Yesterday http://mr1.doubanio.com/b6b798a87f01048cbd6c84bc313ec865/1/fm/song/p978603_128k.mp3
...
...
还是非常规律的,解析起来也不麻烦,可以直接用awk来解析,分隔符为五个空格。
这是剥离出第一列:
$ awk -F ' ' '{printf"%s\n",$1}' 豆瓣红心歌曲备份下载地址.txt
1.流光
2.Forever Now
3.Rainbow
4.Soak
5.Eisbrecher
6.D City Rock
7.Flower Dance
8.オレンジ (トーマ)
9.일어나 (Stand Up)
10.今は昔
11.Banjo Laura (Radio Edit) (Naujas)
12.小河淌水
13.三寸天堂
14.Yesterday
...
...
这是剥离出最后一列。
$ awk -F ' ' '{printf"%s\n",$NF}' 豆瓣红心歌曲备份下载地址.txt
http://mr1.doubanio.com/fc71b56bd54cdc553e76d55232655f71/0/fm/song/p1388552_128k.mp3
http://mr1.doubanio.com/e0f8ef4af2500adbdf288a20f3e16168/0/fm/song/p253711_128k.mp3
http://mr1.doubanio.com/2105e12e4ebd2467c6cf3fcf738cd4bb/0/fm/song/p1909083_128k.mp3
http://mr3.doubanio.com/88480293742702a77788c1cb6a93adb6/0/fm/song/p1471489_128k.mp3
http://mr1.doubanio.com/5fae3b60fd4968485e8ddf509fa51d75/0/fm/song/p601721_128k.mp3
http://mr3.doubanio.com/f46dfb3f3af881b0a31ddb7adaa4e0b9/2/fm/song/p1807226_128k.mp3
http://mr1.doubanio.com/e01ad01b50f9e592864298ed20ba5e9b/0/fm/song/p1695491_128k.mp3
http://mr3.doubanio.com/0c8af003cbc3012b2d70d209ead5a1a7/0/fm/song/p1954984_128k.mp3
http://mr3.doubanio.com/bcd2e1a933d93e05f7930eb39a50bd25/0/fm/song/p1934457_128k.mp3
http://mr1.doubanio.com/76bda89aa62af28d69403d3a40da1264/0/fm/song/p729383_128k.mp3
http://mr3.doubanio.com/f6476d3f1acd560c385b15ea312c1822/0/fm/song/p1905449_128k.mp3
http://mr3.doubanio.com/7d0efd0a7493387e1ddd05d24c23a843/0/fm/song/p2235469_128k.mp3
http://mr3.doubanio.com/affbb3c9d9f234a77d358c5c8d74ff0a/0/fm/song/p1700409_128k.mp3
http://mr1.doubanio.com/b6b798a87f01048cbd6c84bc313ec865/1/fm/song/p978603_128k.mp3
...
...
派森(Python)大法好! 话不多说,直接上代码!#!/usr/bin/python
#coding:utf-8
import urllib
import os
#显示下载进度的模块
def Schedule(a,b,c):
'''''
a:已经下载的数据块
b:数据块的大小
c:远程文件的大小
'''
per = 100.0 * a * b / c
if per > 100 :
per = 100
print '%.2f%%' % per
file_object = open('豆瓣红心歌曲备份下载地址.txt')
try:
for line in file_object:
print '开始下载'+line
url = line.split(' ')[1]
local = os.path.join('/Users/jialinchen/tmp/豆瓣红心',line.split(' ')[0]+'.mp3')
urllib.urlretrieve(url,local,Schedule)
finally:
file_object.close( )
又可以愉快地听红心歌曲了!
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!