4
4
import re
5
5
import shutil
6
6
import zipfile
7
+ import configparser
7
8
8
9
def findEncoreRoot (listf ):
9
10
for path in listf :
10
11
if 'info.json' in path :
11
- return Path (path ).parent
12
+ return (Path (path ).parent , 0 )
13
+ elif 'song.ini' in path :
14
+ return (Path (path ).parent , 1 )
12
15
13
16
db = {
14
17
"encore" : True ,
@@ -32,7 +35,8 @@ def scan():
32
35
33
36
with zipfile .ZipFile (zipa , "r" ) as zip_ref :
34
37
file_list = zip_ref .namelist ()
35
- encoreRoot = str (findEncoreRoot (file_list ))
38
+ encoreRoot , fileFormat = findEncoreRoot (file_list )
39
+ encoreRt = str (encoreRoot )
36
40
37
41
diffs = {}
38
42
artist = None
@@ -41,21 +45,51 @@ def scan():
41
45
charters = []
42
46
length = 0
43
47
44
- isRootFirstDir = encoreRoot == '.'
45
- readableRoot = '' if isRootFirstDir else encoreRoot + '/'
48
+ isRootFirstDir = encoreRt == '.'
49
+ readableRoot = '' if isRootFirstDir else encoreRt + '/'
46
50
cover = None
47
51
48
- with zip_ref .open (readableRoot + 'info.json' ) as info :
49
- infod = json .load (info )
52
+ if fileFormat == 1 :
53
+ with zip_ref .open (readableRoot + 'song.ini' ) as info :
54
+ infod = configparser .ConfigParser ()
55
+ infotext = info .read ().decode ('utf-8' )
56
+ infod .read_string (infotext )
50
57
51
- artist = infod ['artist' ]
52
- title = infod ['title' ]
53
- diffs = infod ['diff' ]
54
- charters = infod .get ('charters' , [])
55
- length = infod .get ('length' , 0 )
56
- album = infod .get ('album' , None )
57
- cover = infod ['art' ]
58
- #print(infod)
58
+ artist = infod .get ('song' , 'artist' )
59
+ title = infod .get ('song' , 'name' )
60
+ diffs = {
61
+ "drums" : infod .getint ('song' , 'diff_drums_pad' , fallback = - 1 ),
62
+ "bass" : infod .getint ('song' , 'diff_bass_pad' , fallback = - 1 ),
63
+ "guitar" : infod .getint ('song' , 'diff_guitar_pad' , fallback = - 1 ),
64
+ "vocals" : infod .getint ('song' , 'diff_vocals_pad' , fallback = - 1 ),
65
+ "plastic_drums" : infod .getint ('song' , 'diff_drums' , fallback = - 1 ),
66
+ "plastic_bass" : infod .getint ('song' , 'diff_bass' , fallback = - 1 ),
67
+ "plastic_guitar" : infod .getint ('song' , 'diff_guitar' , fallback = - 1 ),
68
+ "pitched_vocals" : infod .getint ('song' , 'diff_vocals' , fallback = - 1 ),
69
+ }
70
+ charters = infod .get ('song' , 'charter' )
71
+ length = int (infod .getint ('song' , 'song_length' ) / 1000 )
72
+ album = infod .get ('song' , 'album' )
73
+
74
+ if 'album.png' in zip_ref .namelist ():
75
+ albumfile = 'album.png'
76
+ else :
77
+ albumfile = 'album.jpg'
78
+
79
+ cover = albumfile
80
+ else :
81
+ with zip_ref .open (readableRoot + 'info.json' ) as info :
82
+ infod = json .load (info )
83
+
84
+ artist = infod ['artist' ]
85
+ title = infod ['title' ]
86
+ diffs = infod ['diff' ]
87
+ charters = infod .get ('charters' , [])
88
+ length = infod .get ('length' , 0 )
89
+ album = infod .get ('album' , None )
90
+ cover = infod ['art' ]
91
+ #print(infod)
92
+
59
93
60
94
songid = re .sub ('-+' , '-' , re .sub ('[^a-zA-Z0-9]' , '-' , f'{ artist .replace (' ' , '-' )} -{ title .replace (' ' , '-' )} ' .lower ())).rstrip ('-' )
61
95
@@ -69,7 +103,7 @@ def scan():
69
103
db ['songs' ].append (
70
104
{
71
105
"zip" : zipa .replace ('Songs\\ ' , '' ).replace ('Songs/' , '' ),
72
- "root" : encoreRoot ,
106
+ "root" : encoreRt ,
73
107
"isRootFirstDir" : isRootFirstDir ,
74
108
"artist" : artist ,
75
109
"title" : title ,
@@ -84,4 +118,4 @@ def scan():
84
118
saveScan (db )
85
119
86
120
if __name__ == "__main__" :
87
- scan ()
121
+ scan ()
0 commit comments