音乐爬虫-酷狗
发完这个不发了,qq音乐有人已经发过了酷狗涉及到了对于时间的验证,MD5加密。
import os
import hashlib
import requests
import time
class KuGoumusic():
def __init__(self):
self.headers2 = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36',
}
self.headers = {
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
'Accept': '*/*',
'Referer': 'https://www.kugou.com/yy/html/search.html',
'Connection': 'keep-alive',
'TE' : 'Trailers',
'Host' : 'complexsearch.kugou.com',
'cookie' : 'kg_mid=61fe1880c589517a9747d456c1c78519; kg_dfid=0hoVrE4EHqxb0nNjS13230j2; kg_dfid_collect=d41d8cd98f00b204e9800998ecf8427e; kg_mid_temp=61fe1880c589517a9747d456c1c78519'
}# 请求头
self.song = []
self.singer = []
self.FileHash = []
self.SQFileHash = []
self.HQFileHash = []
self.Duration = []
self.ct = int(time.time()*1000)
def get_signature(self,keyword):
o = {
0: "NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt",
1: "bitrate=0",
3: "clienttime={0}".format(self.ct),
4: "clientver=2000",
5: "dfid=-",
6: "inputtype=0",
7: "iscorrection=1",
8: "isfuzzy=0",
9: "keyword={}".format(keyword),
10: "mid={0}".format(self.ct),
11: "page=1",
12: "pagesize=30",
13: "platform=WebFilter",
14: "privilege_filter=0",
15: "srcappid=2919",
16: "tag=em",
17: "userid=-1",
18: "uuid={0}".format(self.ct),
19: "NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt"
}
date = ''
for li in o.values():
date = date + li
md5 = hashlib.md5()
md5.update(date.encode('utf-8'))
return md5.hexdigest()
def search(self):
keyword = input("请输入想要听的歌:")
url_0 = 'https://complexsearch.kugou.com/v2/search/song?&keyword={0}&page=1&pagesize=30&bitrate=0&isfuzzy=0&tag=em&inputtype=0&platform=WebFilter&userid=-1&clientver=2000&iscorrection=1&privilege_filter=0&srcappid=2919&clienttime={1}&mid={1}&uuid={1}&dfid=-&signature={2}'.format(keyword,self.ct,self.get_signature(keyword))
response = requests.get(url_0,headers=self.headers)
dict_0 = response.json()
music_list = dict_0['data']['lists']
for music in music_list:
song = music['SongName']
song = song.replace('<em>','').replace('</em>','')
singer = music['SingerName']
FileHash = music['FileHash']
SQFileHash = music['SQFileHash']
HQFileHash = music['HQFileHash']
Duration = music['Duration']
self.song.append(song)
self.singer.append(singer)
self.FileHash.append(FileHash)
self.SQFileHash.append(SQFileHash)
self.HQFileHash.append(HQFileHash)
self.Duration.append(Duration)
self.select()
def select(self):
ip = 0
for song, singer, FileHash, SQFileHash, HQFileHash, Duration in zip(self.song, self.singer, self.FileHash,
self.SQFileHash, self.HQFileHash,
self.Duration):
min = int(int(Duration)/60)
seconds = int(Duration)%60
time = str(min)+":"+str(seconds)
print(ip,song,singer,time)
ip +=1
ip = input("请输入序号:")
ip = int(ip)
song = self.song
singer = self.singer
FileHash = self.FileHash
self.download(song,singer,FileHash)
def download(self,song,singer,FileHash):
headers = {
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
'Accept': '*/*',
'Referer': 'https://www.kugou.com/',
'cookie': 'kg_mid=d2d37972966d97ed632044391f136e5b; kg_dfid=2mBPAo3OCSYx0tOVPh3CkjnP; kg_dfid_collect=d41d8cd98f00b204e9800998ecf8427e; kg_mid_temp=d2d37972966d97ed632044391f136e5b'
}# 请求头
url = 'https://wwwapi.kugou.com/yy/index.php?r=play/getdata&hash={0}'.format(
FileHash)
response = requests.get(url, headers=headers)
dict = response.json()
url = dict['data']['play_url']
music = requests.get(url, headers=self.headers2).content
dir = os.getcwd()
dir = os.path.join(dir, "酷狗音乐 ")
if not os.path.exists(dir):
os.mkdir(dir)# 构造文件夹
os.chdir(dir)# 将下载的歌曲存储在该文件夹
print(song, singer)
file_name = song + '-' + singer + '.mp3'# 文件名
with open(file_name, 'wb') as f:
f.write(music)
print("下载成功!")
if __name__ =='__main__':
music = KuGoumusic()
music.search() shqvc 发表于 2020-10-31 23:24
我晚看了20分钟 看来是和这个无缘了错过了就是错过了不过谢谢你
复制这段内容后打开百度网盘App,操作更方便哦。 链接:https://pan.baidu.com/s/1DL8KTyx9M_wmzYLRyB7kAw 提取码:1v23
再分享一天吧 云烟成雨 发表于 2020-10-30 14:20
QQ 音乐的在哪儿,可以下载高音质的吗
qq音乐的你在吾爱搜应该能搜到,我的都是默认音质,也就是低音质。不过有的可以改高音质,比如酷狗之类的。低音乐的歌多一些,我就直接低音质了,高音质没有的话还要加判断改下低音质,嫌麻烦就放弃了 谢谢大神 完全看不懂呀 老大能发就发呗 给我们这些小白多造点福利 这个怎么用呀 我看不出来呀是不是外挂程序可以装在酷狗上面的插件呀 谢谢大神,这东西可以傲 QQ 音乐的在哪儿,可以下载高音质的吗
shqvc 发表于 2020-10-30 14:19
老大能发就发呗 给我们这些小白多造点福利 这个怎么用呀 我看不出来呀是不是外挂程序可以装在 ...
这是python脚本,在pycharm里面运行就行 咋说呢,有简单的办法获取到一些必要参数,不用这么麻烦的去自己验证加密一些东西,个人练习js逆向还是不错的!
纯个人观点,谢谢分享! shqvc 发表于 2020-10-30 14:19
老大能发就发呗 给我们这些小白多造点福利 这个怎么用呀 我看不出来呀是不是外挂程序可以装在 ...
运行这个需要一点python基础