吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4276|回复: 31
收起左侧

[Python 转载] 哈哈我又来了,改良版,能下载,生成云词图。[QQ音乐]

[复制链接]
从零学习的歪经小 发表于 2020-7-24 14:27
上次发了一个半成品,发现有挺多人看,但是又是个半成品就完善了一下,(⊙o⊙)…
最近在研究和打lol没弄什么优化,然后差不多每个功能要用的headers我都重新获取了一下怕弄不出来很麻烦,然后代码就很长,那个云词库从早上10点弄到现在,感觉和想象中的不一样还很麻烦
安装的库比较多,而且可能还不能直接cmd弄要去下载安装,弄完我感觉还能凑合。

云词图

云词图

2.png
我英语那是真tm的一塌糊涂,然后变量就用中文了,我看了知乎的一个帖子吧,感觉那个一楼说的还挺好的   https://www.zhihu.com/question/393691308
有些已经用拼音的我也懒的改。就先这样吧。我也没弄太多注释,但一般还是能看懂的。
那个付费音乐有点难搞。我昨天弄了一个晚上,弄到头晕就睡觉了,一觉醒来都不知道怎么开始弄就不弄了。

~

~

因为那个云词图要的很多,我后面弄了一个没云词图的。(要弄云词图,库怎么安百度都能找到。素材等下我一起打包发)
[Python] 纯文本查看 复制代码
import requests
import os
import json
#进度条要的库
import time
import sys

headers = {
    'authority': 'c.y.qq.com',
    'method': 'GET',
    'path': '/soso/fcgi-bin/client_search_cp?ct=24&qqmusic_ver=1298&new_json=1&remoteplace=txt.yqq.song&searchid=64361863091094477&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p=1&n=10&w=%E7%A0%B4%E8%8C%A7&g_tk_new_20200303=57712389&g_tk=57712389&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=0',
    'scheme': 'https',
    'accept': 'application/json, text/javascript, */*; q=0.01',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'zh-CN,zh;q=0.9',
    'origin': 'https://y.qq.com',
    'referer': 'https://y.qq.com/portal/search.html',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-site',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36'
}

def sj():   #读取搜索数据
    ge = input('请输入歌名: ')
    req = requests.get('https://c.y.qq.com/soso/fcgi-bin/client_search_cp?ct=24&qqmusic_ver=1298&new_json=1&remoteplace=txt.yqq.song&searchid=59254584347080480&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p=1&n=10&w='+ge+'&g_tk_new_20200303=1646128606&g_tk=1646128606&loginUin=123456&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=0').json()
    #print(req)
    return req

def Time_1():  #进度条函数
    for i in range(1,51):
        sys.stdout.write('\r')
        sys.stdout.write('{0}% |{1}'.format(int(i%51)*2,int(i%51)*'■'))
        sys.stdout.flush()
        time.sleep(0.125)
    sys.stdout.write('\n')


def gd(list):   #打印歌单
    xh=1
    print('\033[5;32m*  歌曲                                                歌手                专辑\033[0m')
    for m in list:
        print('%-3s'%xh,end='')
        歌曲长度1=len(m['title'])
        歌曲长度2=len(m['title'].encode('utf-8'))
        歌曲长=int((歌曲长度2-歌曲长度1)/2+歌曲长度1)
        歌曲格=int(52-歌曲长)
        歌手长度1=len(m['singer'][0]['name'])
        歌手长度2=len(m['singer'][0]['name'].encode('utf-8'))
        歌手长=int((歌手长度2-歌手长度1)/2+歌手长度1)
        歌手格=int(20-歌手长)
        专辑长度1=len(m['album']['name'])
        专辑长度2=len(m['album']['name'].encode('utf-8'))
        专辑长=int((专辑长度2-专辑长度1)/2+专辑长度1)
        print(m['title']+' '*歌曲格,end='')
        print(m['singer'][0]['name']+' '*歌手格,end='')
        print(m['album']['name'])
        xh+=1


def cd(list):   #获取菜单
    while True:
        print(' '*30+'\033[1;37;41m*\033[0m\033[1;37;41m—————————————====选择操作====—————————————\033[0m\033[1;37;41m*\033[0m\n'+' '*30+'\033[1;37;41m│\033[0m1.进行下载      2.进行播放      3.获取评论\033[1;37;41m│\033[0m\n'+' '*30+'\033[1;37;41m│\033[0m4.获取歌词      5.生成云图      6.重新开始\033[1;37;41m│\033[0m\n'+' '*30+'\033[1;37;41m*===============按任意键退出===============*\033[0m')
        菜单=input('>>>>>  ')
        if 菜单==str(1):
            xzyy(list)
        elif 菜单==str(2):
            bfyy(list)
        elif 菜单==str(3):
            hqpl(list)
        elif 菜单==str(4):
            hqgc(list)
        elif 菜单==str(5):
            print('想屁吃??')
        elif 菜单==str(6):
            req=sj()
            gd(req['data']['song']['list'])
            list=req['data']['song']['list']
            continue
        else:
            break
        print('----------操作已完成----------')
        yhxz = input('请选择下次操作')


#读取单个音乐的mid和uid
def id(list):
    选择歌曲=int(input("请输入歌曲的序号>>>  "))-1
    原id=str(list[选择歌曲]['id'])
    return 原id
def id_mid(list):
    选择歌曲=int(input("请输入歌曲的序号>>>  "))-1
    歌曲mid=str(list[选择歌曲]['mid'])
    曲名 = str(list[选择歌曲]['title']+'——'+list[选择歌曲]['singer'][0]['name'])
    return 歌曲mid,曲名
def id_uid(list):
    选择歌曲=int(input("请输入歌曲的序号>>>  "))-1
    歌曲uid=str(list[选择歌曲]['id'])
    return 歌曲uid



def xzyy(list):   #下载音乐
    歌曲mid,曲名=id_mid(list)
    headers={
        'authority':'u.y.qq.com',
        'method':'GET',
        'path':'/cgi-bin/musicu.fcg?format=json&data={%22req%22:{%22module%22:%22CDN.SrfCdnDispatchServer%22,%22method%22:%22GetCdnDispatch%22,%22param%22:{%22guid%22:%226503543428%22,%22calltype%22:0,%22userip%22:%22%22}},%22req_0%22:{%22module%22:%22vkey.GetVkeyServer%22,%22method%22:%22CgiGetVkey%22,%22param%22:{%22guid%22:%226503543428%22,%22songmid%22:[%22001Y7zXa1p0ryF%22],%22songtype%22:[0],%22uin%22:%220%22,%22loginflag%22:1,%22platform%22:%2220%22}},%22comm%22:{%22uin%22:0,%22format%22:%22json%22,%22ct%22:24,%22cv%22:0}}',
        'scheme':'https',
        'accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
        'accept-encoding':'gzip, deflate, br',
        'accept-language':'zh-CN,zh;q=0.9',
        'cache-control':'max-age=0',
        'sec-fetch-dest':'document',
        'sec-fetch-mode':'navigate',
        'sec-fetch-site':'none',
        'sec-fetch-user':'?1',
        'upgrade-insecure-requests':'1',
        'user-agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36',
    }
    url='https://u.y.qq.com/cgi-bin/musicu.fcg?format=json&data={"req":{"module":"CDN.SrfCdnDispatchServer","method":"GetCdnDispatch","param":{"guid":"6503543428","calltype":0,"userip":""}},"req_0":{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{"guid":"6503543428","songmid":["'+歌曲mid+'"],"songtype":[0],"uin":"0","loginflag":1,"platform":"20"}},"comm":{"uin":0,"format":"json","ct":24,"cv":0}}'
    音频数据=requests.get(url=url,headers=headers).json()
    #print(音频数据)
    网址前段 = 音频数据['req']['data']['freeflowsip'][0]
    网址后段 = 音频数据['req_0']['data']['midurlinfo'][0]['purl']
    全网址 = str(网址前段+网址后段)
    全网址 =requests.get(全网址,headers=headers).content
    下载路径 = os.getcwd()   #返回程序的当前路径
    try:
        下载路径=os.path.join(下载路径,"qq音乐")
        if  not os.path.exists(下载路径):
            os.mkdir(下载路径)
        os.chdir(下载路径)
        with open(曲名+'.m4a','wb') as f:
            f.write(全网址)
        print('下载中···')
        Time_1()
        print('下载成功')
    except:
        print('对不起,下载失败,可能无版权,或收费歌。')


def bfyy(list):   #播放音乐
    歌曲mid,曲名=id_mid(list)
    headers={
        'authority':'u.y.qq.com',
        'method':'GET',
        'path':'/cgi-bin/musicu.fcg?format=json&data={%22req%22:{%22module%22:%22CDN.SrfCdnDispatchServer%22,%22method%22:%22GetCdnDispatch%22,%22param%22:{%22guid%22:%226503543428%22,%22calltype%22:0,%22userip%22:%22%22}},%22req_0%22:{%22module%22:%22vkey.GetVkeyServer%22,%22method%22:%22CgiGetVkey%22,%22param%22:{%22guid%22:%226503543428%22,%22songmid%22:[%22001Y7zXa1p0ryF%22],%22songtype%22:[0],%22uin%22:%220%22,%22loginflag%22:1,%22platform%22:%2220%22}},%22comm%22:{%22uin%22:0,%22format%22:%22json%22,%22ct%22:24,%22cv%22:0}}',
        'scheme':'https',
        'accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
        'accept-encoding':'gzip, deflate, br',
        'accept-language':'zh-CN,zh;q=0.9',
        'cache-control':'max-age=0',
        'sec-fetch-dest':'document',
        'sec-fetch-mode':'navigate',
        'sec-fetch-site':'none',
        'sec-fetch-user':'?1',
        'upgrade-insecure-requests':'1',
        'user-agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36',
    }
    url = 'https://u.y.qq.com/cgi-bin/musicu.fcg?format=json&data={"req":{"module":"CDN.SrfCdnDispatchServer","method":"GetCdnDispatch","param":{"guid":"6503543428","calltype":0,"userip":""}},"req_0":{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{"guid":"6503543428","songmid":["'+歌曲mid+'"],"songtype":[0],"uin":"0","loginflag":1,"platform":"20"}},"comm":{"uin":0,"format":"json","ct":24,"cv":0}}'
    音频数据=requests.get(url=url,headers=headers).json()
    #print(音频数据)
    网址前段 = 音频数据['req']['data']['freeflowsip'][0]
    网址后段 = 音频数据['req_0']['data']['midurlinfo'][0]['purl']
    全网址 = str(网址前段+网址后段)
    print('播放地址:'+全网址)


def hqpl(list):   #获取评论
    print('默认获取前15条热门评论')
    歌曲uid=id_uid(list)
    pl =requests.get('https://c.y.qq.com/base/fcgi-bin/fcg_global_comment_h5.fcg?g_tk_new_20200303=57712389&g_tk=57712389&loginUin=2079898547&hostUin=0&format=json&inCharset=utf8&outCharset=GB2312¬ice=0&platform=yqq.json&needNewCode=0&cid='+歌曲uid+'&reqtype=2&biztype=1&topid='+歌曲uid+'&cmd=6&needmusiccrit=0&pagenum=1&pagesize=15&lasthotcommentid=song_253511781_1762308377_1590307612_2634401830_1590308001&domain=qq.com&ct=24&cv=10101010').json()
    pld = pl['comment']['commentlist']
    #print(pld)
    序号2 = 1
    for plhq in pld:
        if plhq['middlecommentcontent'] == None :
            print(str(序号2)+': '+plhq['nick']+': '+plhq['rootcommentcontent']+'\n\n')
        else:
            print(str(序号2)+': '+plhq['nick']+'回复了'+plhq['middlecommentcontent'][0]['replyednick']+':'+plhq['rootcommentcontent']+'\n'+plhq['middlecommentcontent'][0]['subcommentcontent']+'\n\n')
        序号2 +=1


def hqgc(list):   #获取歌词
    歌曲uid=id_uid(list)
    url ='https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_yqq.fcg?nobase64=1&musicid='+歌曲uid+'&-=jsonp1&g_tk_new_20200303=57712389&g_tk=57712389&loginUin=2079898547&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=0'
    gc =requests.get(url=url,headers=headers).json()
    去杂=str(gc['lyric'])
    纯1=去杂.replace('[','').replace(']','').replace('ti:','').replace(' (','————').replace(')][ar:','\n').replace('','\n').replace(' ',' ').replace(');','').replace('ar:','').replace('al:','').replace('by:\noffset:0','').replace(')','').replace('-','').replace('@','  ').replace('/C.vo/','  ').replace('','').replace(';','')
    纯2=纯1.splitlines()
    del 纯2[1]
    del 纯2[1]
    歌词引用序号=0
    for 纯3 in 纯2:
        if 歌词引用序号 >= 2:
            纯3 = 纯3[16:]
            print(纯3)
        else:
            print(纯3)
        歌词引用序号+=1



if __name__ == "__main__":
    req=sj()
    list=req['data']['song']['list']
    gd(list)
    cd(list)
    print('\033[1;31;43m感谢使用~\033[0m')


链接: https://pan.baidu.com/s/1HSXUQjUhO9IPg4ersjlkWw 提取码: 6666
要云词图的去网盘下吧。。。
我本来还想做个有界面的,发现还是太年轻就先算了
暂定UI.png

评论别发那种谢谢什么的,那还不如评个分。我无聊就看看评论一般都回。

欢迎学习交流。
3.png

免费评分

参与人数 12吾爱币 +8 热心值 +12 收起 理由
阿基米德啊 + 1 我很赞同!
long-han + 1 我很赞同!
Jet_Chou + 1 热心回复!
我是俊飞 + 1 + 1 鼓励转贴优秀软件安全工具和文档!
zq283314616 + 1 + 1 谢谢@Thanks!
18252042364 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
桀兄3712 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
14境左右 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
5045915 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
watertian + 1 热心回复!
wxs513 + 2 + 1 还要装PY,算了吧。封装下呗
cschyzlj + 1 + 1 用心讨论,共获提升!

查看全部评分

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

 楼主| 从零学习的歪经小 发表于 2020-7-24 14:32
OY0G)`O2@KU1Z[IE40SF6DF.png

**要不是电脑坏了,我肯定没这么无聊。现在lol一登直接死机,死机过后磁盘都黑了,用了6-7年机械硬盘,我觉得还能再拯救一下
7.20号帮朋友打宝典,还死机4次,把他号封了7天,O(∩_∩)O~
Ldfd 发表于 2020-7-24 14:51
2079898548 发表于 2020-7-24 14:32
**要不是电脑坏了,我肯定没这么无聊。现在lol一登直接死机,死机过后磁盘都黑了,用了6-7年机械硬盘, ...

同古董机械硬盘,已经扔了,换了ssd一身轻松
cschyzlj 发表于 2020-7-24 14:34
吾爱子然 发表于 2020-7-24 14:34
新人表示看不懂
吾爱小六 发表于 2020-7-24 14:38
膜拜大佬
watertian 发表于 2020-7-24 14:39
楼主辛苦了
山中老叟 发表于 2020-7-24 14:41
大佬大佬
randomk 发表于 2020-7-24 14:46
这个是做啥用的?最后生成一个图片?
班长的男人 发表于 2020-7-24 14:49
膜拜大佬
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

快速回复 收藏帖子 返回列表 搜索

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

GMT+8, 2024-9-20 07:56

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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