forked from KawaiiLab/azusa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cm_structure.py
86 lines (58 loc) · 1.85 KB
/
cm_structure.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
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
import sqlite3
import os
import json
import config
import re
localAppData = os.getenv("LOCALAPPDATA")
dbPath = os.path.normpath(localAppData + '\\Netease\\CloudMusic\\Library\\webdb.dat')
con = sqlite3.connect(dbPath)
class PlayList:
pid = None
playlist = None
class SongDetail:
detail = None
relative_path = None
real_suffix = None
class FailedRecords:
tid = None
reason = None
def __init__(self, tid, reason):
self.tid = tid
self.reason = reason
def FetchPlaylist():
onlyUser = config.parseCfg("onlyUserPlaylist")
userId = config.parseCfg("userId")
ret = []
CommandText = "SELECT * FROM web_playlist"
rows = con.execute(CommandText)
for row in rows:
elem = PlayList()
elem.pid = int(row[0])
elem.playlist = json.loads(row[1])
if onlyUser == "True" and elem.playlist["creator"]["userId"] != int(userId):
continue
ret.append(elem)
return ret
def FetchPlaylistSongs(pid):
ret = []
CommandText = "SELECT tid, pid FROM web_playlist_track WHERE pid = " + str(pid) + " ORDER BY `order`"
rows = con.execute(CommandText)
for row in rows:
ret.append(row[0])
return ret
def FetchSongDetial(tid):
ret = SongDetail()
CountText = "SELECT COUNT(*) FROM web_offline_track WHERE track_id =" + str(tid)
count = con.execute(CountText)
(number_of_rows,) = count.fetchone()
if number_of_rows == 0:
return None
CommandText = "SELECT detail, relative_path, real_suffix FROM web_offline_track WHERE track_id =" + str(tid)
rows = con.execute(CommandText)
for row in rows:
ret.detail = json.loads(row[0])
ret.relative_path = row[1]
ret.real_suffix = row[2]
return ret
def GetSafeFilename(filename):
return re.sub('[^\w\-_\. ]', '_', filename)