mirror of
https://github.com/jiojciojsioe3/a3cjroijsiojiorj.git
synced 2024-11-15 07:21:50 +08:00
Add preview time for tja files
This commit is contained in:
parent
4b986c62ec
commit
fc0e951491
29
app.py
29
app.py
@ -60,6 +60,26 @@ def get_osu_key(osu, section, key, default=None):
|
|||||||
return default
|
return default
|
||||||
|
|
||||||
|
|
||||||
|
def get_tja_preview(tja):
|
||||||
|
tja_lines = open(tja, 'r').read().replace('\x00', '').split('\n')
|
||||||
|
|
||||||
|
for line in tja_lines:
|
||||||
|
line = line.strip()
|
||||||
|
if ':' in line:
|
||||||
|
name, value = line.split(':', 1)
|
||||||
|
if name.lower() == 'demostart':
|
||||||
|
value = value.strip()
|
||||||
|
try:
|
||||||
|
value = float(value)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return int(value * 1000)
|
||||||
|
elif line.lower() == '#start':
|
||||||
|
break
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@app.teardown_appcontext
|
@app.teardown_appcontext
|
||||||
def close_connection(exception):
|
def close_connection(exception):
|
||||||
db = getattr(g, '_database', None)
|
db = getattr(g, '_database', None)
|
||||||
@ -85,6 +105,13 @@ def route_api_songs():
|
|||||||
categories[cat[0]] = {'title': cat[1], 'title_en': cat[2]}
|
categories[cat[0]] = {'title': cat[1], 'title_en': cat[2]}
|
||||||
songs_out = []
|
songs_out = []
|
||||||
for song in songs:
|
for song in songs:
|
||||||
|
type = song[9]
|
||||||
|
if type == "tja":
|
||||||
|
if os.path.isfile('public/songs/%s/main.tja' % song[0]):
|
||||||
|
preview = get_tja_preview('public/songs/%s/main.tja' % song[0])
|
||||||
|
else:
|
||||||
|
preview = 0
|
||||||
|
else:
|
||||||
osus = [osu for osu in os.listdir('public/songs/%s' % song[0]) if osu in ['easy.osu', 'normal.osu', 'hard.osu', 'oni.osu']]
|
osus = [osu for osu in os.listdir('public/songs/%s' % song[0]) if osu in ['easy.osu', 'normal.osu', 'hard.osu', 'oni.osu']]
|
||||||
if osus:
|
if osus:
|
||||||
osud = parse_osu('public/songs/%s/%s' % (song[0], osus[0]))
|
osud = parse_osu('public/songs/%s/%s' % (song[0], osus[0]))
|
||||||
@ -103,7 +130,7 @@ def route_api_songs():
|
|||||||
'preview': preview,
|
'preview': preview,
|
||||||
'category': category_out['title'],
|
'category': category_out['title'],
|
||||||
'category_en': category_out['title_en'],
|
'category_en': category_out['title_en'],
|
||||||
'type': song[9],
|
'type': type,
|
||||||
'offset': song[10]
|
'offset': song[10]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user