首页 编程教程正文

学习python总结 - 下载网易云音乐单首歌曲

piaodoo 编程教程 2020-02-22 22:16:44 1466 0 python教程

本文来源吾爱破解论坛

安装几个包就可以使用了

也没什么技术含量

有个窗口,输入连接就可以下载了

微信截图_20200220195803.png (14.06 KB, 下载次数: 1)

下载附件  保存到相册

2020-2-20 19:58 上传



import re
import requests
import tkinter as tk
import tkinter.messagebox

# http://music.163.com/song/media/outer/url?id=436514312.mp3网易云音乐下载的链接


def getid(url):
    print(url)
    compile_id=re.compile(r'song.(.*?)',re.S)#正则匹配链接里面的id
    id_url = re.split(compile_id,url)#分割出来匹配的内容
    return id_url[2]
def get_url(songid):
    url = 'http://music.163.com/song/media/outer/url?'+songid+'.mp3'
    return  url
def parse_url(url):
    headers={
        'User-Agent': 'Mozilla / 5.0(Windows NT 10.0;Win64;x64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 78.0.3904.97Safari / 537.36'
    }
    response = requests.get(url,headers=headers)
    return response.content
def parse_name(url):
    url = url.replace('/#','')
    headers = {
    'accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
    'accept-encoding':'gzip, deflate, br',
    'accept-language':'zh-CN,zh;q=0.9',
    'cookie':'_iuqxldmzr_=32; _ntes_nnid=c59ed51e9697ed4642b646942b46bbc8,1576941133686; _ntes_nuid=c59ed51e9697ed4642b646942b46bbc8; WM_NI=DSZ%2FGkHxi32BLrNlcwnPq4U0J5GaDb%2FANMPMGU5oI4iK9%2FfRowFCLelDRiwcM1INriNDxTE7uEU1Q1s6rvmtS69epv054SZJkohIat3Xol%2FIdIYdSgojP1ACHpS4QoM2Y1U%3D; WM_NIKE=9ca17ae2e6ffcda170e2e6ee82c254ba9eaf99d945a68e8eb6c85e839b9baff37ff3b38db7db5ba1efa8d4ef2af0fea7c3b92a888d96d0c6618ca8a7d4b14a90ae828de27dae90bfd5d83c8aeb8982c76aed9f82aed347858bfb90cc40ab95f7d0e55aada98aa4cf6fb09c9e8af6698fef87aff1638e9cb8b5c83db79b9bd2d43bb1eabe97f08091eaf786f37ef4ebfcb4d942a9b1a8aae480f188a18dae43a8979785d26dadb6a0d2c4498cb09dd5d4658fee97d2d837e2a3; WM_TID=d6p47C9W01lBVEVFUVY97ljXVHVZx1mg; JSESSIONID-WYYY=D%2BESH1p5kzoAHro%2F1G5EPti7bkikxreSa8EuhynyhAH6jpnF2aRm%2F%2BtlPBov8cf0jPSknfI5z2em8nnMgq4AhopgQKJg2rXnZqqwDzKsHaGHXd5Je%2FFXyU9CG29kDKxDUZFnnfHAZ%5CybbOS7ZRvSaO49WNX%2FMlmq9szk2nwgCD8xierj%3A1576991817201',
    'referer': 'https://music.163.com/',
    'sec-fetch-mode': 'nested-navigate',
    'sec-fetch-site': 'same-origin',
    'upgrade-insecure-requests': '1',
    'user-agent': 'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14'
    }
    response = requests.get(url, headers=headers)
    data = response.text
    pattern = re.compile('<title>(.*?)-(.*?)-',re.S)
    names = re.findall(pattern,data)
    for name in names:
        name =name[0]+'-'+name[1]+'.mp3'
        return name

def save_mp3(data,name):
    with open(name,'wb') as f:
        f.write(data)
        f.close()

def mian():
    url = e.get()

    name = parse_name(url)

    songid= getid(str(url))
    mp3_url = get_url(songid)

    data = parse_url(mp3_url)
    save_mp3(data,name)
    tk.messagebox.askokcancel(title = '注意~',message='下载完成')



# 设置窗口
window = tk.Tk()
window.title('下载网易云音乐')
window.geometry('400x100')
# 设置输入窗口
e = tk.Entry(width=50)
e.pack()
# 设置两个插入按钮
b1 = tk.Button(text='开始下载', width=10, height=1, command=mian)
b1.pack()


window.mainloop()

版权声明:

本站所有资源均为站长或网友整理自互联网或站长购买自互联网,站长无法分辨资源版权出自何处,所以不承担任何版权以及其他问题带来的法律责任,如有侵权或者其他问题请联系站长删除!站长QQ754403226 谢谢。

有关影视版权:本站只供百度云网盘资源,版权均属于影片公司所有,请在下载后24小时删除,切勿用于商业用途。本站所有资源信息均从互联网搜索而来,本站不对显示的内容承担责任,如您认为本站页面信息侵犯了您的权益,请附上版权证明邮件告知【754403226@qq.com】,在收到邮件后72小时内删除。本文链接:https://www.piaodoo.com/8081.html

搜索