python下载酷狗音乐源码

Posted chif

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python下载酷狗音乐源码相关的知识,希望对你有一定的参考价值。

import requests
import re

#获取hush值和AlbumID
def gethush():
    global musicname
    musicname = input(请输入您要下载的歌曲名字:)
    url = http://songsearch.kugou.com/song_search_v2?callback=jQuery1910026785707623246724_1490845878865&keyword={}&page=1&pagesize=30&userid=-1&%20%20clientver=&platform=WebFilter&tag=em&filter=2&iscorrection=1&privilege_filter=0&_=1490845878887.format(musicname)
    response = requests.get(url)
    html = response.text
    pattern = "FileHash":"(.*?)","SQPayType".*?"AlbumID":"(.*?)"
    hush = re.search(pattern,html).group(1)
    album = re.search(pattern,html).group(2)
    return hush

#获取音乐下载链接
def getmusicurl(hush):

    url = http://www.kugou.com/yy/index.php?r=play/getdata&hash={}.format(hush)
    response = requests.get(url)
    html = response.text
    pattern = "play_url":"(.*?)","authors"
    music_url = re.search(pattern,html).group(1)
    return music_url

#下载音乐
def downloadmusic(url):
    session = requests.Session()
    url = url.replace(\,‘‘)
    r = requests.get(url)
    with open(rd:mp3\%s.mp3 % musicname, "wb") as f:
        for chunk in r.iter_content(chunk_size=512):
            if chunk:
                print(正在下载:%s% musicname)
                f.write(chunk)


def main():
    downloadmusic(getmusicurl(gethush()))

if __name__ == __main__:
    main()

 

以上是关于python下载酷狗音乐源码的主要内容,如果未能解决你的问题,请参考以下文章

Python下载酷狗音乐

python使用beautifulsoup4爬取酷狗音乐

酷狗音乐展示滚动歌词效果的控件实现

Python实例---获取酷狗音乐Top100

一篇文章教会你使用Python网络爬虫下载酷狗音乐

Python PyQt5 | Hi音乐 v0.1.0 正式版发布