下载网易音乐VIP歌曲

原创
08/28 00:22
阅读数 37

今天测试一个工具来听收费歌曲, 但不是特别好使,主要是因为原作者(unblock163.sh)弃更了 , 更主要的原因是因为netease的API升级了,  我也是在部署server的时候才发现日志有错误.  大概是这个样:

root:/root#more /usr/local/UnblockNeteaseMusic/UnblockNeteaseMusic.log
INFO: (app) HTTP Server running @ http://0.0.0.0:46857
ERROR: (provider/match) Unexpected end of JSON input
    SyntaxError: Unexpected end of JSON input
        at JSON.parse (<anonymous>)
        at /usr/local/UnblockNeteaseMusic/precompiled/app.js:294:408
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async CacheStorage.cache (/usr/local/UnblockNeteaseMusic/precompiled/app.js:13:22)
        at async getAudioFromSource (/usr/local/UnblockNeteaseMusic/precompiled/app.js:201:17)
        at async Promise.any (index 4)
        at async module.exports (/usr/local/UnblockNeteaseMusic/precompiled/app.js:221:234)
        at async Promise.all (index 0)
INFO: (provider/match) Replaced: [185906] 发如雪
    audioId: 185906
    songName: "发如雪"
    url: "http://other.player.ra01.sycdn.kuwo.cn/e4bf138bad28d4ad7cc5fd7f8b6ac1cf/6309ac80/resource/n2/128/80/42/480803359.mp3"
INFO: (provider/match) Replaced: [185906] 发如雪
    audioId: 185906
    songName: "发如雪"
    url: "http://other.player.ra01.sycdn.kuwo.cn/2a33be4610e54939eece0aee9f56bfa1/6309ac91/resource/n2/128/80/42/480803359.mp3"
INFO: (provider/match) Replaced: [354601] 你的微笑
    audioId: 354601
    songName: "你的微笑"
    url: "http://ct.sycdn.kuwo.cn/175fb6fba28cef62939b4be4b8ba96a4/6309ac9b/resource/n2/68/13/52033952.mp3"
INFO: (provider/match) Replaced: [238693] 珊瑚颂
    audioId: 238693
    songName: "珊瑚颂"
    url: "http://other.player.rh01.sycdn.kuwo.cn/b58c55ec04f42aee61da4e4e58ea9b54/6309ac9e/resource/n2/92/86/2484233733.mp3"

没办法我也不太会调试nodejs, 主要是懒, 所以就准备用shell+python下载一下这些歌曲吧

shell主要是拼接JSON字符串:

#root:/root/shell#cat get_errr_music.sh

FILE=/usr/local/UnblockNeteaseMusic/UnblockNeteaseMusic.log
SONG=/tmp/songName.list  
URL=/tmp/url.list
ALL=/tmp/neteast.lst

grep 'songName:' $FILE  > $SONG
grep 'url:' $FILE  > $URL

echo "songName: `wc $SONG`" 
echo "url: `wc $URL`" 

test -f $ALL && rm -rf $ALL
paste  -d','  $SONG  $URL |while read f; do echo "{$f},">>$ALL; done

echo "[`cat $ALL` {songName:'',url:''] }" >$ALL

echo "all: `wc $ALL`" 

python是用来下载:

# -*- coding: utf-8 -*-
#!python
import os
import json
import requests

dir = "~/CloudMusic"
jsonFile = "/tmp/netease.list"
headers = {
    'User-Agent' 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'}


def exists(name):
    f = dir+"/"+name+".mp3"
    e = os.path.isfile(f)
    return e, f


def download(u, f):
    r = requests.get(url=u, headers=headers).content
    with open(f, 'wb') as f:
        f.write(r)
        print("download", f, u)


def do(x):
    e, f = exists(x['songName'])
    if e:
        print("exists",  f)
    else:
        download(x['url'], f)


with open(jsonFile, 'r', encoding='utf8') as fp:
    json_data = json.load(fp)
    print('这是文件中的json数据:', json_data)
    print('这是读取到文件数据的数据类型:', type(json_data))
fp.close()


if not os.path.isdir(dir):
    os.mkdir(dir)


for x in json_data:
    try:
        print("开始处理", x)
        do(x)
    except Exception:
        print("error ", x)
    finally:
        pass

为什么用python呢, 主要是不是特别熟悉,就练练手吧. 

 

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部