Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
T
Taiko Web
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Taiko Web
Commits
3a28d967
Commit
3a28d967
authored
Feb 20, 2019
by
Bui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move song previews to the database
parent
13ca5e36
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
77 deletions
+5
-77
app.py
app.py
+5
-77
No files found.
app.py
View file @
3a28d967
...
...
@@ -40,10 +40,10 @@ def get_config():
try
:
config
=
json
.
load
(
open
(
'config.json'
,
'r'
))
except
ValueError
:
print
'WARNING: Invalid config.json, using default values'
print
(
'WARNING: Invalid config.json, using default values'
)
config
=
{}
else
:
print
'WARNING: No config.json found, using default values'
print
(
'WARNING: No config.json found, using default values'
)
config
=
{}
if
not
config
.
get
(
'songs_baseurl'
):
...
...
@@ -55,77 +55,6 @@ def get_config():
return
config
def
parse_osu
(
osu
):
osu_lines
=
open
(
osu
,
'r'
)
.
read
()
.
replace
(
'
\x00
'
,
''
)
.
split
(
'
\n
'
)
sections
=
{}
current_section
=
(
None
,
[])
for
line
in
osu_lines
:
line
=
line
.
strip
()
secm
=
re
.
match
(
'^
\
[(
\
w+)
\
]$'
,
line
)
if
secm
:
if
current_section
:
sections
[
current_section
[
0
]]
=
current_section
[
1
]
current_section
=
(
secm
.
group
(
1
),
[])
else
:
if
current_section
:
current_section
[
1
]
.
append
(
line
)
else
:
current_section
=
(
'Default'
,
[
line
])
if
current_section
:
sections
[
current_section
[
0
]]
=
current_section
[
1
]
return
sections
def
get_osu_key
(
osu
,
section
,
key
,
default
=
None
):
sec
=
osu
[
section
]
for
line
in
sec
:
ok
=
line
.
split
(
':'
,
1
)[
0
]
.
strip
()
ov
=
line
.
split
(
':'
,
1
)[
1
]
.
strip
()
if
ok
.
lower
()
==
key
.
lower
():
return
ov
return
default
def
get_preview
(
song_id
,
song_type
):
preview
=
0
if
song_type
==
"tja"
:
if
os
.
path
.
isfile
(
'public/songs/
%
s/main.tja'
%
song_id
):
preview
=
get_tja_preview
(
'public/songs/
%
s/main.tja'
%
song_id
)
else
:
osus
=
[
osu
for
osu
in
os
.
listdir
(
'public/songs/
%
s'
%
song_id
)
if
osu
in
[
'easy.osu'
,
'normal.osu'
,
'hard.osu'
,
'oni.osu'
]]
if
osus
:
osud
=
parse_osu
(
'public/songs/
%
s/
%
s'
%
(
song_id
,
osus
[
0
]))
preview
=
int
(
get_osu_key
(
osud
,
'General'
,
'PreviewTime'
,
0
))
return
preview
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
def
get_version
():
version
=
{
'commit'
:
None
,
'commit_short'
:
''
,
'version'
:
None
,
'url'
:
DEFAULT_URL
}
if
os
.
path
.
isfile
(
'version.json'
):
...
...
@@ -168,7 +97,7 @@ def route_api_preview():
abort
(
400
)
song_type
=
song_row
[
0
][
12
]
prev_path
=
make_preview
(
song_id
,
song_type
)
prev_path
=
make_preview
(
song_id
,
song_type
,
song_row
[
0
][
15
]
)
if
not
prev_path
:
return
redirect
(
get_config
()[
'songs_baseurl'
]
+
'
%
s/main.mp3'
%
song_id
)
...
...
@@ -195,7 +124,7 @@ def route_api_songs():
for
song
in
songs
:
song_id
=
song
[
0
]
song_type
=
song
[
12
]
preview
=
get_preview
(
song_id
,
song_type
)
preview
=
song
[
15
]
category_out
=
categories
[
song
[
11
]]
if
song
[
11
]
in
categories
else
def_category
song_skin_out
=
song_skins
[
song
[
14
]]
if
song
[
14
]
in
song_skins
else
None
...
...
@@ -226,12 +155,11 @@ def route_api_config():
return
jsonify
(
config
)
def
make_preview
(
song_id
,
song_type
):
def
make_preview
(
song_id
,
song_type
,
preview
):
song_path
=
'public/songs/
%
s/main.mp3'
%
song_id
prev_path
=
'public/songs/
%
s/preview.mp3'
%
song_id
if
os
.
path
.
isfile
(
song_path
)
and
not
os
.
path
.
isfile
(
prev_path
):
preview
=
get_preview
(
song_id
,
song_type
)
/
1000
if
not
preview
or
preview
<=
0.1
:
print
(
'Skipping #
%
s due to no preview'
%
song_id
)
return
False
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment