码迷,mamicode.com
首页 > 编程语言 > 详细

python下载酷狗音乐源码

时间:2018-06-28 00:57:21      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:lte   att   pytho   eth   ssi   下载链接   user   file   ges   

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下载酷狗音乐源码

标签:lte   att   pytho   eth   ssi   下载链接   user   file   ges   

原文地址:https://www.cnblogs.com/chif/p/9236596.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!