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

2019年10月21日

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

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

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


音乐地址格式:

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

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

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

#https://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: https://www.myzhenai.com.cn/ https://www.myzhenai.com/ https://www.haikou-china.com/ https://jiayu.mybabya.com/ https://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
}
###########################################################################################################

#https://music.163.com/#/song?id=310449
###########################################################################################################
function wangyi() {
id=$(echo "${1}" | awk -F "=" '{ print $2 }')
d=$(curl -s https://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 "https://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" "https://music.163.com/song/media/outer/url?id=${id}.mp3"
}
###########################################################################################################

#https://www.kuwo.cn/yinyue/24720751
###########################################################################################################
function kuwo() {
id=$(echo "${1}" | awk -F "yinyue/" '{ print $2 }')
d=$(curl -s https://player.kuwo.cn/webmusic/st/getNewMuiseByRid?rid=MUSIC_${id})
name=$(echo ${d} | awk -F "" '{ print $2 }' | awk -F "" '{ print $1 }')
auto=$(echo ${d} | awk -F "" '{ print $2 }' | awk -F "" '{ print $1 }')
ico=$(echo ${d} | awk -F "" '{ print $2 }' | awk -F "" '{ print $1 }')
m=$(echo ${d} | awk -F "" '{ print $2 }' | awk -F "" '{ print $1 }')
p=$(echo ${d} | awk -F "" '{ print $2 }' | awk -F "" '{ print $1 }')
mp=$(echo "https://${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}
}
###########################################################################################################

#https://www.kugou.com/song/#hash=D48ADEC6EA77DEFFF7337F57DC9B4121
###########################################################################################################
function kugou() {
id=$(echo "${1}" | awk -F "#hash=" '{ print $2 }')
d=$(curl -s https://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}
}
###########################################################################################################

#https://music.baidu.com/song/5915242
###########################################################################################################
function baidu() {
id=$(echo "${1}" | awk -F "song/" '{ print $2 }')
d=$(curl -s https://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 "https://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 ---------------------------------------------------------------------
I P 地 址: 18.119.127.230
区 域 位 置: 美国马萨诸塞
系 统 信 息: 美国
Original content, please indicate the source:
同福客栈论坛 | 蟒蛇科普海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source https://myzhenai.com.cn/post/2895.html

6条评论

发表回复

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