Linux下用Shell编写一键下载网上音乐的脚本

2019年10月21日

关键词:网易云音乐解析 百度音乐解析 酷我音乐解析 酷狗音乐解析 QQ音乐解析

这个脚本是在Linux下用Shell写的,如果哪个朋友想要源码的话,请在我的博客上留言或关注我的今日头条号私信给我。

这个脚本是利用网易云音乐,百度音乐,酷我音乐,酷狗音乐,QQ音乐等平台的解析api写的,可以获取歌曲链接,歌曲演唱者,唱片logo,歌曲名称。因为脚本太长了,所以就不是文章里贴出来了,如果哪个朋友想要的话,请关注我的头条号私信我并留下您常用的邮箱,我会将源码发送给您。


音乐地址格式:

#http://music.163.com/song?id=171405

#http://www.kuwo.cn/yinyue/6236961

#http://www.kugou.com/song/#hash=662C370D670257321463C9079D281D44

#http://music.baidu.com/song/7273909

#https://y.qq.com/n/yqq/song/002w9K2u0OlxrK.html

Shell源码

#!/usr/bin/env bash
# !/bin/bash
. /etc/profile
############################################################################################################################################
#
# This is a lottery number automatic generation tool
# Autor: RucLinux
# Web: http://www.myzhenai.com.cn/ http://www.myzhenai.com/ http://www.haikou-china.com/ http://jiayu.mybabya.com/ http://www.0898-shop.com/
#  说明:转载引用请保留这段,谢谢
#
#############################################################################################################################################
pw="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

###########################################################################################################
function unicodename() {
#shi=$(echo ${1} |grep -o "\u" | wc -l)
OLD_IFS="$IFS"
IFS="\\u"
arr=(${name})
for i in ${arr[@]}
do
un=$(perl -CS -le "print \"\x{${i}}\"")
um=($un)
yname=${yname}$(echo ${um[@]}|sed 's/:/ /g')
done
}
###########################################################################################################

###########################################################################################################
function unicodeauto() {
OLD_IFD="$IFD"
IFD="\\u"
aar=(${auto})
for ii in ${aar[@]}
do
uun=$(perl -CS -le "print \"\x{${ii}}\"")
uum=($uun)
yauto=${yauto}$(echo ${uum[@]}|sed 's/:/ /g')
done
}
###########################################################################################################

#http://music.163.com/#/song?id=310449
###########################################################################################################
function wangyi() {
id=$(echo "${1}" | awk -F "=" '{ print $2 }')
d=$(curl -s http://music.163.com/api/song/detail/"?id=${id}&ids=%5B${id}%5D&csrf_token=")
name=$(echo ${d} | awk -F "songs" '{ print $2 }' | awk -F "id" '{ print $1 }' | awk -F "\"name\":\"" '{ print $2 }' | awk -F "\",\"" '{ print $1 }')
auto=$(echo ${d} | awk -F "artists" '{ print $2 }' | awk -F "id" '{ print $1 }' | awk -F "\"name\":\"" '{ print $2 }' | awk -F "\",\"" '{ print $1 }')
ico=$(echo ${d} | awk -F "\"blurPicUrl\":\"" '{ print $2 }' | awk -F "\",\"" '{ print $1 }')
mp=$(echo "http://music.163.com/song/media/outer/url?id=${id}.mp3")
one="			{\n"
two="				title : "
three="				singer :"
four="				cover  :"
fives="				src    : "
six="			},\r"
echo -e "${one}${two}'${name}',\r${three}'${auto}',\r${four}'${ico}',\r${fives}'${mp}'\r${six}" >> ${pw}/in.log
wget -p ${p} -O "${name}.mp3" "http://music.163.com/song/media/outer/url?id=${id}.mp3"
}
###########################################################################################################

#http://www.kuwo.cn/yinyue/24720751
###########################################################################################################
function kuwo() {
id=$(echo "${1}" | awk -F "yinyue/" '{ print $2 }')
d=$(curl -s http://player.kuwo.cn/webmusic/st/getNewMuiseByRid?rid=MUSIC_${id})
name=$(echo ${d} | awk -F "<name>" '{ print $2 }' | awk -F "</name>" '{ print $1 }')
auto=$(echo ${d} | awk -F "<singer>" '{ print $2 }' | awk -F "</singer>" '{ print $1 }')
ico=$(echo ${d} | awk -F "<artist_pic240>" '{ print $2 }' | awk -F "</artist_pic240>" '{ print $1 }')
m=$(echo ${d} | awk -F "<mp3dl>" '{ print $2 }' | awk -F "</mp3dl>" '{ print $1 }')
p=$(echo ${d} | awk -F "<mp3path>" '{ print $2 }' | awk -F "</mp3path>" '{ print $1 }')
mp=$(echo "http://${m}/resource/${p}")
one="			{\n"
two="				title : "
three="				singer :"
four="				cover  :"
fives="				src    : "
six="			},\r"
echo -e "${one}${two}'${name}',\r${three}'${auto}',\r${four}'${ico}',\r${fives}'${mp}'\r${six}" >> ${pw}/in.log
wget -p ${pw} -O "${name}.mp3" ${mp}
}
###########################################################################################################

#http://www.kugou.com/song/#hash=D48ADEC6EA77DEFFF7337F57DC9B4121
###########################################################################################################
function kugou() {
id=$(echo "${1}" | awk -F "#hash=" '{ print $2 }')
d=$(curl -s http://m.kugou.com/app/i/getSongInfo.php?hash=${id}"&cmd=playInfo")
name=$(echo ${d} | awk -F "songName\":\"" '{ print $2 }' | awk -F "\",\"req_hash" '{ print $1 }')
auto=$(echo ${d} | awk -F "singerName\":\"" '{ print $2 }' | awk -F "\",\"ctype" '{ print $1 }')
ico=$(echo ${d} | awk -F "album_img\":\"" '{ print $2 }' | awk -F "\",\"privilege" '{ print $1 }' | sed -e 's/\\//g')
mp=$(echo ${d} | awk -F "url\":\"" '{ print $2 }' | awk -F "\",\"time" '{ print $1 }' | sed -e 's/\\//g')
one="			{\n"
two="				title : "
three="				singer :"
four="				cover  :"
fives="				src    : "
six="			},\r"
echo -e "${one}${two}'${name}',\r${three}'${auto}',\r${four}'${ico}',\r${fives}'${mp}'\r${six}" >> ${pw}/in.log
wget -p ${pw} -O "${name}.mp3" ${mp}
}
###########################################################################################################

#http://music.baidu.com/song/5915242
###########################################################################################################
function baidu() {
id=$(echo "${1}" | awk -F "song/" '{ print $2 }')
d=$(curl -s http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.song.playAAC"&songid="${id})
name=$(echo ${d} | awk -F "title\":\"" '{ print $2 }' | awk -F "\",\"ting" '{ print $1 }')
auto=$(echo ${d} | awk -F "author\":\"" '{ print $2 }' | awk -F "\",\"album" '{ print $1 }')
ico=$(echo ${d} | awk -F "pic_big\":\"" '{ print $2 }' | awk -F "@" '{ print $1 }' | sed -e 's/\\//g')
mp=$(echo ${d} | awk -F "file_link\":\"" '{ print $2 }' | awk -F "\",\"file" '{ print $1 }' | sed -e 's/\\//g')
unicodename ${name}
unicodeauto ${auto}
one="			{\n"
two="				title : "
three="				singer :"
four="				cover  :"
fives="				src    : "
six="			},\r"
echo -e "${one}${two}'${yname}',\r${three}'${yauto}',\r${four}'${ico}',\r${fives}'${mp}'\r${six}" >> ${pw}/in.log
wget -p ${pw} -O "${yname}.mp3" ${mp}
}
###########################################################################################################

#https://y.qq.com/n/yqq/song/0016I6cj2dkNzQ.html
###########################################################################################################
function qq() {
d=$(curl -s "${1}")
name=$(echo ${d} | awk -F "songname\":\"" '{ print $2 }' | awk -F "\",\"songtitle" '{ print $1 }')
auto=$(echo ${d} | awk -F "\"name\":\"" '{ print $2 }' | awk -F "\",\"title" '{ print $1 }')
iico=$(echo ${d} | awk -F "albummid\":\"" '{ print $2 }' | awk -F "\",\"albumname" '{ print $1 }' | sed -e 's/\\//g')
id=$(echo ${d} | awk -F "\"songid\":" '{ print $2 }' | awk -F ",\"songmid\"" '{ print $1 }' | sed -e 's/\\//g')
mp=$(echo "http://ws.stream.qqmusic.qq.com/${id}.m4a?fromtag=46")
ico=$(echo "https://y.gtimg.cn/music/photo_new/T002R300x300M00${iico}.jpg")
one="			{\n"
two="				title : "
three="				singer :"
four="				cover  :"
fives="				src    : "
six="			},\r"
echo -e "${one}${two}'${name}',\r${three}'${auto}',\r${four}'${ico}',\r${fives}'${mp}'\r${six}" >> ${pw}/in.log
wget -p ${pw} -O "${name}.mp3" ${mp}
}
###########################################################################################################

###########################################################################################################
function music() {
if [[ "${1}" =~ "163" ]]; then
wangyi ${1}
fi
if [[ "${1}" =~ "kuwo" ]]; then
kuwo ${1}
fi
if [[ "${1}" =~ "kugou" ]]; then
kugou ${1}
fi
if [[ "${1}" =~ "baidu" ]]; then
baidu ${1}
fi
if [[ "${1}" =~ "qq" ]]; then
qq ${1}
fi

printf "
title=${name}\n
singer=${auto}\n
cover=${ico}\n
scr=${mp}
"
}
###########################################################################################################
music ${1}


sicnature ---------------------------------------------------------------------
Your current IP address is: 3.226.254.115
Your IP address location: 美国弗吉尼亚阿什本
Your IP address country and region: 美国 美国
Your current browser is:
Your current system is:
Original content, please indicate the source:
同福客栈论坛 | 海南仙岛海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source http://www.myzhenai.com.cn/post/2895.html

没有评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注