★立即注册★

QQ登录

只需一步,快速开始

就爱江湖-应用库-技术分享资源网-Www.92Jh.Cn

查看: 412|回复: 1

[Python] Python 收费、高品质无损音乐下载【开源】

[复制链接]
发表于 2019-8-22 10:37:11 | 显示全部楼层
下午闲着无聊,看到了@丸子吃枣药丸 他发的文章, API采用QQMusic,我将Python 实现了他的功能,更方便大家下载
Python 收费、高品质无损音乐下载【开源】图片ID:4996

001

002

003

004

005

006

007

008

009

010

011

012

013

014

015

016

017

018

019

020

021

022

023

024

025

026

027

028

029

030

031

032

033

034

035

036

037

038

039

040

041

042

043

044

045

046

047

048

049

050

051

052

053

054

055

056

057

058

059

060

061

062

063

064

065

066

067

068

069

070

071

072

073

074

075

076

077

078

079

080

081

082

083

084

085

086

087

088

089

090

091

092

093

094

095

096

097

098

099

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/7/20 14:37
# @AuThor  : Bnightning
# @site    : https://www.bnightning.cn
# @file    : douqq.py
# @Software: PyCharm
import requests
import json

headers = {
    'Host': 'c.y.qq.com',
    'Referer': 'http://c.y.qq.com/',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 '
                  'Safari/537.36 '
}


def douqq_post(mid):
    """
    返回歌曲下载url
    :param mid:歌曲mid
    :return: 字典
    """
    post_url = 'http://www.douqq.com/qqmusic/qqapi.php'
    data = {'mid': mid}
    res = requests.post(post_url, data=data)
    get_json = json.loads(res.text)
    return eval(get_json)


def download_file(src, file_path):
    """
    歌曲下载
    :param src: 下载链接
    :param file_path: 存储路径
    :return: 文件路径
    """
    r = requests.get(src, stream=True)
    f = open(file_path, "wb")
    for chunk in r.iter_content(chunk_size=512):
        if chunk:
            f.write(chunk)
    return file_path


def choice_download(dic):
    print('1. m4a视频')
    print('2. mp3普通品质')
    print('3. mp3高品质')
    print('4. ape高品无损')
    print('5. flac无损音频')
    select = int(input("Please input your choice:"))
    src = ''
    postfix = ''
    if select == 1:
        src = dic['m4a']
        postfix = '.m4a'
    if select == 2:
        src = dic['mp3_l']
        postfix = '.mp3'
    if select == 3:
        src = dic['mp3_h']
        postfix = '.mp3'
    if select == 4:
        src = dic['ape']
        postfix = '.ape'
    if select == 5:
        src = dic['flac']
        postfix = '.flac'
    return postfix, src.replace('\/\/', '//').replace('\/', '/')


def find_song(word):
    """
    查找歌曲
    :param word: 歌曲名
    :return: 返回歌曲mid
    """
    get_url = 'https://c.y.qq.com/soso/fcgi-bin/client_search_cp?&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p=1&n' \
              '=20&w=' + word
    res1 = requests.get(get_url, headers=headers)
    get_json = json.loads(res1.text.strip('callback()[]'))
    jsons = get_json['data']['song']['list']
    songmid = []
    media_mid = []
    song_singer = []
    i = 1
    for song in jsons:
        # print(i, ':' + song['songname'], '---', song['singer'][0]['name'], song['songmid'], song['media_mid'])
        print(i, ':' + song['songname'], '---', song['singer'][0]['name'])
        songmid.append(song['songmid'])
        media_mid.append(song['media_mid'])
        song_singer.append(song['singer'][0]['name'])
        i = i + 1
    select = int(input("Please input your choice:")) - 1
    return songmid[select], song_singer[select]


if __name__ == '__main__':
    # songname = '叹云兮'
    songname = input("Please input the music name:")
    song_mid, singer = find_song(songname)
    dic = douqq_post(song_mid)
    # {
    # "mid":"004FjJo32TISsY",
    # "m4a":"http:\/\/dl.stream.qqmusic.qq.com\/C400004FjJo32TISsY.m4a?guid=2095717240&vkey=0B599CA74745F8A27A33A1FED2C7F6925FFFE8ED040569FB3540EB011FE9C5A3D7F36EAE4BDBD450F25076A23EBAF95A5ECB54B22C5E8F10&uin=0&fromtag=38",
    # "mp3_l":"http:\/\/dl.stream.qqmusic.qq.com\/M500004FjJo32TISsY.mp3?guid=2095717240&vkey=0B599CA74745F8A27A33A1FED2C7F6925FFFE8ED040569FB3540EB011FE9C5A3D7F36EAE4BDBD450F25076A23EBAF95A5ECB54B22C5E8F10&uin=0&fromtag=53",
    # "mp3_h":"http:\/\/dl.stream.qqmusic.qq.com\/M800004FjJo32TISsY.mp3?guid=2095717240&vkey=0B599CA74745F8A27A33A1FED2C7F6925FFFE8ED040569FB3540EB011FE9C5A3D7F36EAE4BDBD450F25076A23EBAF95A5ECB54B22C5E8F10&uin=0&fromtag=53",
    # "ape":"http:\/\/dl.stream.qqmusic.qq.com\/A000004FjJo32TISsY.ape?guid=2095717240&vkey=0B599CA74745F8A27A33A1FED2C7F6925FFFE8ED040569FB3540EB011FE9C5A3D7F36EAE4BDBD450F25076A23EBAF95A5ECB54B22C5E8F10&uin=0&fromtag=53",
    # "flac":"http:\/\/dl.stream.qqmusic.qq.com\/F000004FjJo32TISsY.flac?guid=2095717240&vkey=0B599CA74745F8A27A33A1FED2C7F6925FFFE8ED040569FB3540EB011FE9C5A3D7F36EAE4BDBD450F25076A23EBAF95A5ECB54B22C5E8F10&uin=0&fromtag=53",
    # "pic":"https:\/\/y.gtimg.cn\/music\/photo_new\/T002R300x300M000003NZyTh4eMMsp.jpg?max_age=2592000"
    # }
    # print('mid:'+dic['mid'])
    postfix, url = choice_download(dic)
    save_path = "H:\\Music\\"
    download_file(url, save_path + songname + ' - ' + singer + postfix)
    print('Download Successful')






上一篇:身份证号校验位讲解 转载
下一篇:【PHP】+恶搞图片生成器 在线生成图片【附源码 PSD分层 教程】

发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案,如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请在帖子回复【已解决】。

发表于 2019-8-23 01:42:30 | 显示全部楼层
……怎么又是你  谢谢了啊 辛苦
回复 支持 反对

使用道具 举报

游客
回复
您需要登录后才可以回帖 登录 | ★立即注册★

免责声明
就爱江湖所发布的一切软件逆向解密分析文章及视频、破解补丁、注册机和注册信息,仅限用于学习和研究目的。不得将上述内容用于商业或者非法途径!否则,一切后果请用户自负!
本站信息来自互联网,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请购买注册正版软件,获得正版优质服务!
如有侵权请邮件或QQ与我们联系处理。

联系QQ:2710763
邮箱:2710763@qq.com

手机版|小黑屋| 就爱江湖资源分享网 ( 粤ICP备2025451632号 ) |网站地图

GMT+8, 2025-8-4 09:12

Powered by Discuz!

© 2001-2020 Comsenz Inc.

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