from urllib.parse import *
import requests
import os
import json
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36',
'referer': 'https://www.kugou.com/yy/html/search.html',
'cookie': 'kg_mid=54466227d384411d3637dfa321b337d6; kg_dfid=1Hvl060iZWHn0cXnq12YuJP5; kg_dfid_collect=d41d8cd98f00b204e9800998ecf8427e; Hm_lvt_aedee6983d4cfc62f509129360d6bb3d=1585209276,1585279988,1585380359; Hm_lpvt_aedee6983d4cfc62f509129360d6bb3d=1585380377',
}
def get_id(url):
r = requests.get(url, headers=headers).text
dict = json.loads(r[43:-2])
data = dict['data']['lists'] names = [] hashes = [] ids = [] for item in data:
names.append(item['FileName'].replace('', '').replace('', ''))
hashes.append(item['FileHash'])
ids.append(item['AlbumID'])
return names, hashes, ids
def download_music(name, hash, id):
url = f'https://wwwapi.kugou.com/yy/index.php?r=play/getdata&callback=jQuery19108859518011228213_1585286241467&hash={hash}&album_id={id}&dfid=1Hvl060iZWHn0cXnq12YuJP5&mid=54466227d384411d3637dfa321b337d6&platid=4&_=1585286241469'
r = requests.get(url, headers=headers).text
dict = json.loads(r[41:-2])
play_url = dict['data']['play_url'] try:
with open('%s.mp3' % name, 'wb') as f:
f.write(requests.get(play_url).content)
print("%s 下載下傳完成" % name)
except:
pass
def Kugou_Downloader():
music_name = input("輸入你要下載下傳的歌名或歌手>>>")
url = f'https://songsearch.kugou.com/song_search_v2?callback=jQuery1124001117916144825526_1585380377159&keyword={quote(music_name)}&page=1&pagesize=10&userid=-1&clientver=&platform=WebFilter&tag=em&filter=2&iscorrection=1&privilege_filter=0&_=1585380377161'
if not os.path.exists('。/music'):
os.mkdir('./music')
os.chdir('./music')
print("下載下傳位置:%s" % os.getcwd())
names = get_id(url)[0] hashes = get_id(url)[1] ids = get_id(url)[2] for i in range(len(names)):