-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_songs.py
49 lines (44 loc) · 1.36 KB
/
get_songs.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
45
46
47
48
49
import json
import urllib
import os
import requests
'''
json
[
{
"id":"",
"songLink":"",
"lrcLink":"",
"songPicSmall":"",
"songName":"",
"tag":[ "","",""]
},
...
]
'''
json_file = "songs.json"
with open(json_file) as data_file:
data = json.load(data_file)
err_songs = []
for item in data:
try:
sid = item["id"]
print sid
link = "http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.song.play&songid="+sid
directory = "./music/songs/"+sid
if not os.path.exists(directory):
os.makedirs(directory)
response = json.loads(requests.get(link,verify=False, auth=('user', 'pass')).text)
file_link =response['bitrate']['file_link']
print item["songName"], response["songinfo"]["title"]
print file_link
urllib.urlretrieve(file_link, directory+"/"+sid+".mp3")
# response2 = requests.get(file_link,verify=False, auth=('user', 'pass'))
# with open(directory+"/"+sid+".mp3",'wb') as fout:
# fout.write(response2.text)
with open(directory+"/info.json", "w") as info_file:
json.dump(item, info_file)
except Exception, e:
err_songs.append(item)
print "====================== End of Downloading ======================="
print err_songs