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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| import music_tool as mt import requests import time import hashlib
search_url = 'https://music.91q.com/v1/search'
search_headers = { 'cookie': 'Hm_lvt_d0ad46e4afeacf34cd12de4c9b553aa6=1652356550; cuid=bb25b798-46c6-5585-a57d-bccaf5d75418; Hm_lpvt_d0ad46e4afeacf34cd12de4c9b553aa6=1652366280', 'referer': 'https://music.91q.com/proxy', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36' }
appid = '16073360'
search_timestamp = int(time.time())
word = '薛之谦'
pageNo = '2'
r = f"appid={appid}&pageNo={pageNo}&pageSize=20×tamp={search_timestamp}&type=1&word={word}0b50b02fd0d73a9c4c8c3a781c30845f"
sign = hashlib.md5(r.encode('utf-8')).hexdigest()
search_params = { 'sign': sign, 'word': word, 'type': '1', 'pageNo': pageNo, 'pageSize': '20', 'appid': appid, 'timestamp': search_timestamp }
search_response = requests.get(url=search_url, params=search_params, headers=search_headers)
list_music = search_response.json()['data']['typeTrack']
i = 1
for music in list_music: i += 1 TSID = music['id'] timestamp = int(time.time()) url = "https://music.91q.com/v1/song/tracklink" r = f"TSID={TSID}&appid={appid}×tamp={timestamp}0b50b02fd0d73a9c4c8c3a781c30845f" sign = hashlib.md5(r.encode('utf-8')).hexdigest() params = { 'sign': sign, 'appid': appid, 'TSID': TSID, 'timestamp': timestamp } headers = { 'cookie': 'Hm_lvt_d0ad46e4afeacf34cd12de4c9b553aa6=1652356550; cuid=bb25b798-46c6-5585-a57d-bccaf5d75418; Hm_lpvt_d0ad46e4afeacf34cd12de4c9b553aa6=1652366280', 'referer': 'https://music.91q.com/proxy', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36' } list_res = requests.get(url=url, params=params, headers=headers) music_url = list_res.json()['data']['path'] music_name = list_res.json()['data']['title'] singer_name = list_res.json()['data']['artist'][0]['name'] music_lyric = list_res.json()['data']['lyric'] music_pic = list_res.json()['data']['pic']
music_data = requests.get(music_url).content music_pic_data = requests.get(music_pic).content music_lyric_data = requests.get(music_lyric).content with open(f"music_list/{music_name}-{singer_name}.mp3", mode='wb') as f: f.write(music_data) with open(f"music_list/{music_name}-{singer_name}.jpg", mode='wb') as f: f.write(music_pic_data) with open(f"music_list/{music_name}-{singer_name}.lrc", mode='wb') as f: f.write(music_lyric_data) msg = mt.edit_music_message(f"music_list/{music_name}-{singer_name}.mp3", music_name, singer_name, singer_name, music_name) print(i, singer_name, music_name, msg)
|