-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdownLRCofPlaylist.py
More file actions
59 lines (51 loc) · 1.53 KB
/
Copy pathdownLRCofPlaylist.py
File metadata and controls
59 lines (51 loc) · 1.53 KB
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
import requests
import json
import os
def getPlaylistInfoByHibaiAPI(id):
id = str(id)
#header = {'user-agent':'Mozilla/5.0'}
data1 = {"TransCode": "020111", "OpenId": "Test", "Body": {"SongListId": id}}
url = 'https://api.hibai.cn/api/index/index'
req = requests.post(url,json=data1)
#print(req.url)
return req.json()
def getLyricsByNetEaseAPI(songid):
songid = str(songid)
url = "http://music.163.com/api/song/lyric?os=pc&id="+songid+"&lv=-1&kv=-1&tv=-1"
req = requests.get(url)
return req.json()
def getLyricByHabaiAPI(songid):
songid = str(songid)
url = "https://api.hibai.cn/music/Music/Music?id="+songid+"&type=lrc"
req = requests.get(url)
return req.json()
def writeToFile(s, filename):
i = 0
if not os.path.exists(filename):
g = open(filename,"a",encoding='utf-8')
g.close()
# filesize = os.path.getsize(filename)
# while filesize > tmax:
# i = i+1
# filename = filenameList[i]
# filesize = os.path.getsize(filename)
f = open(filename,"a",encoding='utf-8')
f.write(s)
f.close()
return
def downloadLyricsOfAPlayList(playlistid,filename):
raw = getPlaylistInfoByHibaiAPI(playlistid)
raw = raw['Body']['songs']
print(raw)
lrcURL = []
count = 0
for item in raw:
Aurl = item['lrc']
#lrcURL.append(Aurl)
print(Aurl)
req = requests.get(Aurl)
s = req.text
writeToFile(s,filename)
count+=1
print("Processing Song %d" %count)
return