QQMusic收费、高品质无损音乐下载工具Python3版

  • A+
所属分类:未分类

python版QQ music收费高品质无损音乐下载

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # home.php?mod=space&uid=238618]Time   : 2018/7/20 14:37
  4. # home.php?mod=space&uid=686208]AuThor : Bnightning
  5. #home.php?mod=space&uid=406162]site   : https://www.bnightning.cn
  6. # home.php?mod=space&uid=267492]file   : douqq.py
  7. # Software: PyCharm
  8. import requests
  9. import json
  10. headers = {
  11.     'Host': 'c.y.qq.com',
  12.     'Referer': 'http://c.y.qq.com/',
  13.     'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 '
  14.                   'Safari/537.36 '
  15. }
  16. def douqq_post(mid):
  17.     """
  18.     返回歌曲下载url
  19.     :param mid:歌曲mid
  20.     :return: 字典
  21.     """
  22.     post_url = 'http://www.douqq.com/qqmusic/qqapi.php'
  23.     data = {'mid': mid}
  24.     res = requests.post(post_url, data=data)
  25.     get_json = json.loads(res.text)
  26.     return eval(get_json)
  27. def download_file(src, file_path):
  28.     """
  29.     歌曲下载
  30.     :param src: 下载链接
  31.     :param file_path: 存储路径
  32.     :return: 文件路径
  33.     """
  34.     r = requests.get(src, stream=True)
  35.     f = open(file_path, "wb")
  36.     for chunk in r.iter_content(chunk_size=512):
  37.         if chunk:
  38.             f.write(chunk)
  39.     return file_path
  40. def choice_download(dic):
  41.     print('1. m4a视频')
  42.     print('2. mp3普通品质')
  43.     print('3. mp3高品质')
  44.     print('4. ape高品无损')
  45.     print('5. flac无损音频')
  46.     select = int(input("Please input your choice:"))
  47.     src = ''
  48.     postfix = ''
  49.     if select == 1:
  50.         src = dic['m4a']
  51.         postfix = '.m4a'
  52.     if select == 2:
  53.         src = dic['mp3_l']
  54.         postfix = '.mp3'
  55.     if select == 3:
  56.         src = dic['mp3_h']
  57.         postfix = '.mp3'
  58.     if select == 4:
  59.         src = dic['ape']
  60.         postfix = '.ape'
  61.     if select == 5:
  62.         src = dic['flac']
  63.         postfix = '.flac'
  64.     return postfix, src.replace('\/\/', '//').replace('\/', '/')
  65. def find_song(word):
  66.     """
  67.     查找歌曲
  68.     :param word: 歌曲名
  69.     :return: 返回歌曲mid
  70.     """
  71.     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' \
  72.               '=20&w=' + word
  73.     res1 = requests.get(get_url, headers=headers)
  74.     get_json = json.loads(res1.text.strip('callback()[]'))
  75.     jsons = get_json['data']['song']['list']
  76.     songmid = []
  77.     media_mid = []
  78.     song_singer = []
  79.     i = 1
  80.     for song in jsons:
  81.         # print(i, ':' + song['songname'], '---', song['singer'][0]['name'], song['songmid'], song['media_mid'])
  82.         print(i, ':' + song['songname'], '---', song['singer'][0]['name'])
  83.         songmid.append(song['songmid'])
  84.         media_mid.append(song['media_mid'])
  85.         song_singer.append(song['singer'][0]['name'])
  86.         i = i + 1
  87.     select = int(input("Please input your choice:")) - 1
  88.     return songmid[select], song_singer[select]
  89. if __name__ == '__main__':
  90.     # songname = '叹云兮'
  91.     songname = input("Please input the music name:")
  92.     song_mid, singer = find_song(songname)
  93.     dic = douqq_post(song_mid)
  94.     # {
  95.     # "mid":"004FjJo32TISsY",
  96.     # "m4a":"http:\/\/dl.stream.qqmusic.qq.com\/C400004FjJo32TISsY.m4a?guid=2095717240&vkey=0B599CA74745F8A27A33A1FED2C7F6925FFFE8ED040569FB3540EB011FE9C5A3D7F36EAE4BDBD450F25076A23EBAF95A5ECB54B22C5E8F10&uin=0&fromtag=38",
  97.     # "mp3_l":"http:\/\/dl.stream.qqmusic.qq.com\/M500004FjJo32TISsY.mp3?guid=2095717240&vkey=0B599CA74745F8A27A33A1FED2C7F6925FFFE8ED040569FB3540EB011FE9C5A3D7F36EAE4BDBD450F25076A23EBAF95A5ECB54B22C5E8F10&uin=0&fromtag=53",
  98.     # "mp3_h":"http:\/\/dl.stream.qqmusic.qq.com\/M800004FjJo32TISsY.mp3?guid=2095717240&vkey=0B599CA74745F8A27A33A1FED2C7F6925FFFE8ED040569FB3540EB011FE9C5A3D7F36EAE4BDBD450F25076A23EBAF95A5ECB54B22C5E8F10&uin=0&fromtag=53",
  99.     # "ape":"http:\/\/dl.stream.qqmusic.qq.com\/A000004FjJo32TISsY.ape?guid=2095717240&vkey=0B599CA74745F8A27A33A1FED2C7F6925FFFE8ED040569FB3540EB011FE9C5A3D7F36EAE4BDBD450F25076A23EBAF95A5ECB54B22C5E8F10&uin=0&fromtag=53",
  100.     # "flac":"http:\/\/dl.stream.qqmusic.qq.com\/F000004FjJo32TISsY.flac?guid=2095717240&vkey=0B599CA74745F8A27A33A1FED2C7F6925FFFE8ED040569FB3540EB011FE9C5A3D7F36EAE4BDBD450F25076A23EBAF95A5ECB54B22C5E8F10&uin=0&fromtag=53",
  101.     # "pic":"https:\/\/y.gtimg.cn\/music\/photo_new\/T002R300x300M000003NZyTh4eMMsp.jpg?max_age=2592000"
  102.     # }
  103.     # print('mid:'+dic['mid'])
  104.     postfix, url = choice_download(dic)
  105.     save_path = "H:\\Music\\"
  106.     download_file(url, save_path + songname + ' - ' + singer + postfix)
  107.     print('Download Successful')
weinxin
我的微信公众号
爱真理,得永生!          爱在灵灵久博客,网罗天下,福利大家!

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: