admin管理员组

文章数量:1530936

2023年12月12日发(作者:)

Python酷我音乐解析

Python版本3.9

目录下需要'下载音乐'文件夹

#!/usr/bin/env python

# -*- coding: utf-8 -*-

# 创建时间 : 2021/4/26 20:12

# 创建人 : 空城旧念

# 文件 : 下载音乐.py

# 平台: PyCharm

import requests

import jsonpath

from t import urlretrieve

import

def get_csrf(keyword, s):

header = {

'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',

'Accept - Language': 'zh - CN, zh;q = 0.9',

'Cache - Control': 'max - age = 0',

'Connection': 'keep - alive',

# 'Cookie': '_ga = GA1.2.1157256760.1619264212;_gid =

# GA1.2.572513955.1619264212;Hm_lvt_cdb524f42f0ce19b169a8071123a4797 = 1619264212, 1619264427,

# 1619267361;_gat = 1;Hm_pvt_cdb524f42f0ce19b169a8071123a4797 = 1619269262;kw_token = 5ASAP1Y703',

'Host': '',

'If - None - Match': '"34446-xe3aVUY1idCm93W9EK4AU7RIIkk"',

'Upgrade - Insecure - Requests': '1',

'User - Agent': 'Mozilla / 5.0(WindowsNT10.0;WOW64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / '

'84.0.4147.89Safari / 537.36SLBrowser / 7.0.0.2261SLBChan / 30 '

}

url = "/"

(url, headers=header)

# print("kw_token" + "-" * 10)

# print(_dict())

# print("kw_token"+"-"*10)

heads = {

'Accept': 'application/json, text/plain, */*',

'Accept-Encoding': 'gzip, deflate',

'Accept-Language': 'zh-CN,zh;q=0.9',

'Connection': 'keep-alive',

# 'Cookie': '_ga=GA1.2.1157256760.1619264212; _gid=GA1.2.572513955.1619264212;

# Hm_lvt_cdb524f42f0ce19b169a8071123a4797=1619264212,1619264427,1619267361;

# Hm_lpvt_cdb524f42f0ce19b169a8071123a4797=1619267443; kw_token=J9LYV05NY',

'csrf': _dict()['kw_token'],

'Host': '',

'Referer': f'/search/list?key={keyword}',

'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) '

'Chrome/84.0.4147.89 Safari/537.36 SLBrowser/7.0.0.2261 SLBChan/30 '

}

# print("请求头"+"-"*10)

# print(heads)

# print("请求头" + "-" * 10)

urls = f"/api/www/search/searchMusicBykeyWord?key={keyword}&pn=1&rn=30&httpsStatus=1&reqId"

f"=ec84e110-a4fb-11eb-a1fc-5fd89c65d88b "

# html = (url, headers=head).text

r = (urls, headers=heads)

# print()

rids = th((), '$..rid')[0]

# print(rids)

return rids

def get_music_url(rids, keyword, s):

url = f'/url?format=mp3&rid={rids}&response=url&type=convert_url3&br=128kmp3&from=web&t'

f'=10&httpsStatus=1 '

head = {

head = {

'Accept': 'application / json, text / plain, * / *',

'Accept - Encoding': 'gzip, deflate',

'Accept - Language': 'zh - CN, zh;q = 0.9',

'Connection': 'keep - alive',

# 'Cookie': '_ga = GA1.2.1157256760.1619264212;_gid =

# GA1.2.572513955.1619264212;Hm_lvt_cdb524f42f0ce19b169a8071123a4797 = 1619264212, 1619264427,

# 1619267361;Hm_lpvt_cdb524f42f0ce19b169a8071123a4797 = 1619269271;_gat = 1;kw_token = WMZ5EQS5F9G',

'Host': '',

'Referer': f'http: // / search / list?key = {keyword}',

'User - Agent': 'Mozilla / 5.0(WindowsNT10.0;WOW64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / '

'84.0.4147.89Safari / 537.36SLBrowser / 7.0.0.2261SLBChan / 30 '

}

# print((url, headers=head).text)

music_url = (url, headers=head).json()['url']

return music_url

def get_music(music_url, keyword):

file = '下载音乐/' + e(keyword) + '.mp3'

urlretrieve(music_url, file)

print("下载完成")

# 调用rid获取, url解析, 音乐下载, 模块

def run(keyword, s):

try:

rid = get_csrf(keyword, s) # rid获取

music_url = get_music_url(rid, keyword, s) # url获取

get_music(music_url, keyword) # 下载音乐

except Exception as re:

print(re)

print("查询失败")

return "查询失败了"

# 定义主函数

# if __name__ == "__main__":

def download(keyword):

s = n()

# print("rid:"+_dict()['kw_token'])

# print("rid:" + _dict())

# keyword = input("请输入你需要下载的音乐:")

keyword = (keyword)

pd = run(keyword, s)

if pd == "查询失败了":

return "查询失败了呀"

song = input("歌名:")

download(song)

本文标签: 下载音乐空城解析需要