-
Notifications
You must be signed in to change notification settings - Fork 11
/
getDownloadUrl.py
44 lines (32 loc) · 1.2 KB
/
getDownloadUrl.py
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
import requests
import json
import sys
import time
BASE_URL = " https://www.ximalaya.com/revision/play/album?albumId=%s&pageNum=%s&sort=0&pageSize=30"
HEADERS = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) \
Gecko/20100101 Firefox/58.0',
'Referer':'https://www.ximalaya.com'
}
resultJson = []
albumId = input("[~] Enter your albumId: ")
pageStartNum = int(input("[~] Enter startPage: "))
pageEndNum = int(input("[~] Enter endPage: "))
for page in range(pageStartNum, pageEndNum):
url = BASE_URL%(albumId, page)
response = requests.get(url, headers=HEADERS)
response = response.json()
for musicData in response["data"]["tracksAudioPlay"]:
musicUrl = musicData["src"]
musicIndex = musicData["index"]
resultJson.append({
"musicUrl":musicUrl,
"musicIndex":musicIndex,
})
done = int(pageEndNum * page / pageEndNum)
sys.stdout.write("\r[%s%s]下载进度: %s%%" % ('█' * done, ' ' * (pageEndNum - done), float(page/pageEndNum*100)))
sys.stdout.flush()
time.sleep(1)
fp = open("result-json-{}.txt".format(albumId), "w+", encoding="UTF-8")
fp.write(json.dumps(resultJson))
fp.close()