1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
   | import requests import pprint
  import prettytable as pt import os import re
  if not os.path.exists('kuwo'):     os.mkdir('kuwo') key=input("请输入你想查找的歌手or歌曲:")
  url=f"https://www.kuwo.cn/api/www/search/searchMusicBykeyWord?key={key}&pn=1&rn=30"
 
  headers={     'Accept':'application/json, text/plain, */*',     'Accept-Encoding':'gzip, deflate',     'Accept-Language':'zh-CN,zh;q=0.9',     'Connection':'keep-alive',     'Cookie':'Hm_lvt_cdb524f42f0ce19b169a8071123a4797=1663154581; _ga=GA1.2.567394232.1663154581; _gid=GA1.2.2123499681.1663154581; _gat=1; Hm_lpvt_cdb524f42f0ce19b169a8071123a4797=1663156972; kw_token=XATF666NGJP',     'csrf':'XATF666NGJP',     'Host':'www.kuwo.cn',     'Referer':'http://www.kuwo.cn/search/list?key=%E5%91%A8%E6%9D%B0%E4%BC%A6',     'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36', } response=requests.get(url=url,headers=headers)
 
 
  json=response.json()
  json_data=json['data']['list']
  count=0 table=pt.PrettyTable()
  table.field_names=['专辑','歌手','歌曲','rid']
  info_list=[]
  for list in json_data:          album=list['album']          artist=list['artist']          name=list['name']          rid=list['rid']          table.add_row([album,artist,name,count])     info_list.append([album,artist,name,rid])     count+=1 print(table)
 
  while True:     index=eval(input("请输入你想要下载的歌曲rid:"))     if index == -1:         break          download_info=info_list[index]          rid=download_info[3]          song_url=f"https://www.kuwo.cn/api/v1/www/music/playUrl?mid={rid}&type=convert_url&httpsStatus=1"                    song_info=requests.get(url=song_url).json()['data']['url']               music=requests.get(url=song_info).content     title=re.sub(r'[\\/:*?"<>|]','',download_info[2])          with open(f"kuwo/{title}-{download_info[1]}.mp3",'wb')as f:         f.write(music)     print(f"{title},下载成功")
   |