Skip to content

Commit

Permalink
support configuration files
Browse files Browse the repository at this point in the history
  • Loading branch information
tposejank committed Jan 9, 2025
1 parent e638346 commit 91d5f8e
Showing 1 changed file with 50 additions and 16 deletions.
66 changes: 50 additions & 16 deletions scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import re
import shutil
import zipfile
import configparser

def findEncoreRoot(listf):
for path in listf:
if 'info.json' in path:
return Path(path).parent
return (Path(path).parent, 0)
elif 'song.ini' in path:
return (Path(path).parent, 1)

db = {
"encore": True,
Expand All @@ -32,7 +35,8 @@ def scan():

with zipfile.ZipFile(zipa, "r") as zip_ref:
file_list = zip_ref.namelist()
encoreRoot = str(findEncoreRoot(file_list))
encoreRoot, fileFormat = findEncoreRoot(file_list)
encoreRt = str(encoreRoot)

diffs = {}
artist = None
Expand All @@ -41,21 +45,51 @@ def scan():
charters = []
length = 0

isRootFirstDir = encoreRoot == '.'
readableRoot = '' if isRootFirstDir else encoreRoot + '/'
isRootFirstDir = encoreRt == '.'
readableRoot = '' if isRootFirstDir else encoreRt + '/'
cover = None

with zip_ref.open(readableRoot + 'info.json') as info:
infod = json.load(info)
if fileFormat == 1:
with zip_ref.open(readableRoot + 'song.ini') as info:
infod = configparser.ConfigParser()
infotext = info.read().decode('utf-8')
infod.read_string(infotext)

artist = infod['artist']
title = infod['title']
diffs = infod['diff']
charters = infod.get('charters', [])
length = infod.get('length', 0)
album = infod.get('album', None)
cover = infod['art']
#print(infod)
artist = infod.get('song', 'artist')
title = infod.get('song', 'name')
diffs = {
"drums": infod.getint('song', 'diff_drums_pad', fallback=-1),
"bass": infod.getint('song', 'diff_bass_pad', fallback=-1),
"guitar": infod.getint('song', 'diff_guitar_pad', fallback=-1),
"vocals": infod.getint('song', 'diff_vocals_pad', fallback=-1),
"plastic_drums": infod.getint('song', 'diff_drums', fallback=-1),
"plastic_bass": infod.getint('song', 'diff_bass', fallback=-1),
"plastic_guitar": infod.getint('song', 'diff_guitar', fallback=-1),
"pitched_vocals": infod.getint('song', 'diff_vocals', fallback=-1),
}
charters = infod.get('song', 'charter')
length = int(infod.getint('song', 'song_length') / 1000)
album = infod.get('song', 'album')

if 'album.png' in zip_ref.namelist():
albumfile = 'album.png'
else:
albumfile = 'album.jpg'

cover = albumfile
else:
with zip_ref.open(readableRoot + 'info.json') as info:
infod = json.load(info)

artist = infod['artist']
title = infod['title']
diffs = infod['diff']
charters = infod.get('charters', [])
length = infod.get('length', 0)
album = infod.get('album', None)
cover = infod['art']
#print(infod)


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

Expand All @@ -69,7 +103,7 @@ def scan():
db['songs'].append(
{
"zip": zipa.replace('Songs\\', '').replace('Songs/', ''),
"root": encoreRoot,
"root": encoreRt,
"isRootFirstDir": isRootFirstDir,
"artist": artist,
"title": title,
Expand All @@ -84,4 +118,4 @@ def scan():
saveScan(db)

if __name__ == "__main__":
scan()
scan()

0 comments on commit 91d5f8e

Please sign in to comment.