吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 5107|回复: 48
上一主题 下一主题
收起左侧

[Python 转载] 音乐爬虫-酷狗

  [复制链接]
跳转到指定楼层
楼主
哈_喽 发表于 2020-10-30 14:13 回帖奖励
发完这个不发了,qq音乐有人已经发过了
酷狗涉及到了对于时间的验证,MD5加密。
[Python] 纯文本查看 复制代码
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[ip]
        singer = self.singer[ip]
        FileHash = self.FileHash[ip]
        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()

免费评分

参与人数 2吾爱币 +8 热心值 +2 收起 理由
dreambird1314 + 1 + 1 热心回复!
苏紫方璇 + 7 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

推荐
 楼主| 哈_喽 发表于 2020-11-1 10:26 |楼主
shqvc 发表于 2020-10-31 23:24
我晚看了20分钟   看来是和这个无缘了  错过了就是错过了  不过  谢谢你

复制这段内容后打开百度网盘App,操作更方便哦。&#160;链接:https://pan.baidu.com/s/1DL8KTyx9M_wmzYLRyB7kAw&#160;提取码:1v23
再分享一天吧
推荐
 楼主| 哈_喽 发表于 2020-10-30 14:34 |楼主
云烟成雨 发表于 2020-10-30 14:20
QQ 音乐的在哪儿,可以下载高音质的吗

qq音乐的你在吾爱搜应该能搜到,我的都是默认音质,也就是低音质。不过有的可以改高音质,比如酷狗之类的。低音乐的歌多一些,我就直接低音质了,高音质没有的话还要加判断改下低音质,嫌麻烦就放弃了
沙发
woniu214 发表于 2020-10-30 14:17
3#
shqvc 发表于 2020-10-30 14:18
完全看不懂呀
4#
shqvc 发表于 2020-10-30 14:19
老大  能发就发呗   给我们这些小白多造点福利   这个怎么用呀    我看不出来呀  是不是外挂程序  可以装在酷狗上面的插件呀
5#
xpmg 发表于 2020-10-30 14:20
谢谢大神,这东西可以傲
6#
云烟成雨 发表于 2020-10-30 14:20
QQ 音乐的在哪儿,可以下载高音质的吗
7#
kiopc 发表于 2020-10-30 14:21
shqvc 发表于 2020-10-30 14:19
老大  能发就发呗   给我们这些小白多造点福利   这个怎么用呀    我看不出来呀  是不是外挂程序  可以装在 ...

这是python脚本,在pycharm里面运行就行
8#
kiopc 发表于 2020-10-30 14:26
咋说呢,有简单的办法获取到一些必要参数,不用这么麻烦的去自己验证加密一些东西,个人练习js逆向还是不错的!
纯个人观点,谢谢分享!
10#
 楼主| 哈_喽 发表于 2020-10-30 14:36 |楼主
shqvc 发表于 2020-10-30 14:19
老大  能发就发呗   给我们这些小白多造点福利   这个怎么用呀    我看不出来呀  是不是外挂程序  可以装在 ...

运行这个需要一点python基础
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-25 22:09

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表