Skip to content

Commit 91d5f8e

Browse files
committed
support configuration files
1 parent e638346 commit 91d5f8e

File tree

1 file changed

+50
-16
lines changed

1 file changed

+50
-16
lines changed

scan.py

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
import re
55
import shutil
66
import zipfile
7+
import configparser
78

89
def findEncoreRoot(listf):
910
for path in listf:
1011
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)
1215

1316
db = {
1417
"encore": True,
@@ -32,7 +35,8 @@ def scan():
3235

3336
with zipfile.ZipFile(zipa, "r") as zip_ref:
3437
file_list = zip_ref.namelist()
35-
encoreRoot = str(findEncoreRoot(file_list))
38+
encoreRoot, fileFormat = findEncoreRoot(file_list)
39+
encoreRt = str(encoreRoot)
3640

3741
diffs = {}
3842
artist = None
@@ -41,21 +45,51 @@ def scan():
4145
charters = []
4246
length = 0
4347

44-
isRootFirstDir = encoreRoot == '.'
45-
readableRoot = '' if isRootFirstDir else encoreRoot + '/'
48+
isRootFirstDir = encoreRt == '.'
49+
readableRoot = '' if isRootFirstDir else encoreRt + '/'
4650
cover = None
4751

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)
5057

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+
5993

6094
songid = re.sub('-+', '-', re.sub('[^a-zA-Z0-9]', '-', f'{artist.replace(' ', '-')}-{title.replace(' ', '-')}'.lower())).rstrip('-')
6195

@@ -69,7 +103,7 @@ def scan():
69103
db['songs'].append(
70104
{
71105
"zip": zipa.replace('Songs\\', '').replace('Songs/', ''),
72-
"root": encoreRoot,
106+
"root": encoreRt,
73107
"isRootFirstDir": isRootFirstDir,
74108
"artist": artist,
75109
"title": title,
@@ -84,4 +118,4 @@ def scan():
84118
saveScan(db)
85119

86120
if __name__ == "__main__":
87-
scan()
121+
scan()

0 commit comments

Comments
 (0)