闲着无聊, 写了一个音乐爬虫, 可以播放大多数付费的音乐
import requests
import json
def beautifulJSON(value):
return json.dumps(value, ensure_ascii=False, sort_keys=True, indent=4, separators=(",", ": "))
def searchAll(name, pageNo=1):
url = f"https://c.musicapp.migu.cn/v1.0/content/search_all.do?text={name}&pageNo={pageNo}&pageSize=20&isCopyright=1&sort=1&searchSwitch=%7B%22song%22%3A1%2C%22album%22%3A0%2C%22singer%22%3A0%2C%22tagSong%22%3A1%2C%22mvSong%22%3A0%2C%22bestShow%22%3A1%7D"
headers = {
"content-type": "application/json",
"channel": "0140210",
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 15_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.31(0x18001f2a) NetType/WIFI Language/zh_CN",
"Referer": "https://servicewechat.com/",
}
res_data = json.loads(requests.get(url=url, headers=headers).text)
if not res_data.get("songResultData"):
return
if len(res_data.get("songResultData").get("result")) == 0:
return
song_list = res_data.get("songResultData").get("result")
for i in range(len(song_list)):
item = song_list[i]
singers = ""
imgItems = []
for j in item.get("singers"):
singers += j.get("name") + " / "
for j in item.get("imgItems"):
imgItems.append(j.get("img"))
url = analysis_url(contentId=item.get("contentId"), copyrightId=item.get("copyrightId"), resourceType=item.get("resourceType"))
song_list[i] = {"name": item.get("name"), "singers": singers[:-3], "lyricUrl": item.get("lyricUrl"), "imgItems": imgItems, "url": url}
print(beautifulJSON(song_list))
def analysis_url(contentId, copyrightId, resourceType):
url = f"https://app.c.nf.migu.cn/strategy/listen-url/v2.4?contentId={contentId}©rightId={copyrightId}&lowerQualityContentId=600902000006889010&resourceType={resourceType}&toneFlag=PQ"
headers = {"User-Agent": "MGMobileMusic/7.20.2 (iPhone; iOS 15.6.1; Scale/3.00)", "channel": "0140070"}
res_data = json.loads(requests.get(url=url, headers=headers).text)
if res_data.get("code") == "000000":
return res_data.get("data").get("url")
print(res_data.get("info"))
return ""
if __name__ == "__main__":
searchAll("周杰伦")