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
45373863
Commit
45373863
authored
Aug 27, 2018
by
Bui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use osu's previewtime
parent
53610808
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
18 deletions
+63
-18
app.py
app.py
+56
-12
src/js/songselect.js
src/js/songselect.js
+7
-6
No files found.
app.py
View file @
45373863
#!/usr/bin/env python2
#!/usr/bin/env python2
import
sqlite3
import
sqlite3
import
re
import
os
from
flask
import
Flask
,
g
,
jsonify
from
flask
import
Flask
,
g
,
jsonify
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
...
@@ -21,6 +23,42 @@ def query_db(query, args=(), one=False):
...
@@ -21,6 +23,42 @@ def query_db(query, args=(), one=False):
return
(
rv
[
0
]
if
rv
else
None
)
if
one
else
rv
return
(
rv
[
0
]
if
rv
else
None
)
if
one
else
rv
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
@
app
.
teardown_appcontext
@
app
.
teardown_appcontext
def
close_connection
(
exception
):
def
close_connection
(
exception
):
db
=
getattr
(
g
,
'_database'
,
None
)
db
=
getattr
(
g
,
'_database'
,
None
)
...
@@ -30,19 +68,25 @@ def close_connection(exception):
...
@@ -30,19 +68,25 @@ def close_connection(exception):
@
app
.
route
(
'/api/songs'
)
@
app
.
route
(
'/api/songs'
)
def
route_api_songs
():
def
route_api_songs
():
songs
=
query_db
(
'select * from songs where enabled = 1'
)
songs
=
query_db
(
'select * from songs where enabled = 1'
)
songs_out
=
[]
songs_out
=
[]
for
song
in
songs
:
for
song
in
songs
:
print
song
osus
=
[
osu
for
osu
in
os
.
listdir
(
'songs/
%
s'
%
song
[
0
])
if
osu
in
[
'easy.osu'
,
'normal.osu'
,
'hard.osu'
,
'oni.osu'
]]
songs_out
.
append
(
if
osus
:
{
'id'
:
song
[
0
],
'title'
:
song
[
1
],
'title_en'
:
song
[
2
],
'stars'
:
{
osud
=
parse_osu
(
'songs/
%
s/
%
s'
%
(
song
[
0
],
osus
[
0
]))
'easy'
:
song
[
3
],
'normal'
:
song
[
4
],
preview
=
int
(
get_osu_key
(
osud
,
'General'
,
'PreviewTime'
,
0
))
'hard'
:
song
[
5
],
'oni'
:
song
[
6
]
else
:
}}
preview
=
0
)
songs_out
.
append
(
{
'id'
:
song
[
0
],
'title'
:
song
[
1
],
'title_en'
:
song
[
2
],
'stars'
:
{
'easy'
:
song
[
3
],
'normal'
:
song
[
4
],
'hard'
:
song
[
5
],
'oni'
:
song
[
6
]
},
'preview'
:
preview
}
)
return
jsonify
(
songs_out
)
return
jsonify
(
songs_out
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
app
.
run
(
port
=
34801
)
app
.
run
(
port
=
34801
)
src/js/songselect.js
View file @
45373863
...
@@ -7,7 +7,7 @@ function SongSelect(){
...
@@ -7,7 +7,7 @@ function SongSelect(){
var
_preview
;
var
_preview
;
var
_preview_to
;
var
_preview_to
;
this
.
startPreview
=
function
(
id
,
first_open
=
true
)
{
this
.
startPreview
=
function
(
id
,
prvtime
,
first_open
=
true
)
{
var
start
=
Date
.
now
();
var
start
=
Date
.
now
();
setTimeout
(
function
(){
setTimeout
(
function
(){
bgm
.
pause
();
bgm
.
pause
();
...
@@ -19,11 +19,11 @@ function SongSelect(){
...
@@ -19,11 +19,11 @@ function SongSelect(){
var
delay
=
end
-
start
;
var
delay
=
end
-
start
;
var
no_delay
=
first_open
?
0
:
300
;
var
no_delay
=
first_open
?
0
:
300
;
_preview
.
currentTime
=
_preview
.
duration
/
2
-
1
0
;
_preview
.
currentTime
=
prvtime
/
100
0
;
_preview
.
volume
=
0.5
;
_preview
.
volume
=
0.5
;
_preview
.
addEventListener
(
'
ended
'
,
function
(){
_preview
.
addEventListener
(
'
ended
'
,
function
(){
this
.
currentTime
=
this
.
duration
/
2
-
1
0
;
this
.
currentTime
=
prvtime
/
100
0
;
this
.
play
();
this
.
play
();
},
false
);
},
false
);
...
@@ -99,7 +99,7 @@ function SongSelect(){
...
@@ -99,7 +99,7 @@ function SongSelect(){
if
(
!
$
(
'
.opened
'
).
length
)
{
if
(
!
$
(
'
.opened
'
).
length
)
{
_this
.
startPreview
(
$
(
this
).
data
(
'
song-id
'
));
_this
.
startPreview
(
$
(
this
).
data
(
'
song-id
'
)
,
$
(
this
).
data
(
'
preview
'
)
);
assets
.
sounds
[
"
don
"
].
play
();
assets
.
sounds
[
"
don
"
].
play
();
assets
.
sounds
[
"
song-select
"
].
pause
();
assets
.
sounds
[
"
song-select
"
].
pause
();
assets
.
sounds
[
"
song-select
"
].
currentTime
=
0
;
assets
.
sounds
[
"
song-select
"
].
currentTime
=
0
;
...
@@ -113,7 +113,7 @@ function SongSelect(){
...
@@ -113,7 +113,7 @@ function SongSelect(){
});
});
}
else
{
}
else
{
_preview
.
pause
();
_preview
.
pause
();
_this
.
startPreview
(
$
(
this
).
data
(
'
song-id
'
),
false
);
_this
.
startPreview
(
$
(
this
).
data
(
'
song-id
'
),
$
(
this
).
data
(
'
preview
'
),
false
);
assets
.
sounds
[
"
ka
"
].
play
();
assets
.
sounds
[
"
ka
"
].
play
();
}
}
};
};
...
@@ -146,8 +146,9 @@ function SongSelect(){
...
@@ -146,8 +146,9 @@ function SongSelect(){
var
songID
=
song
.
id
;
var
songID
=
song
.
id
;
var
songTitle
=
song
.
title
;
var
songTitle
=
song
.
title
;
var
songTitleSpace
=
songTitle
.
replace
(
/ /g
,
'
'
);
var
songTitleSpace
=
songTitle
.
replace
(
/ /g
,
'
'
);
var
songPreview
=
song
.
preview
;
_code
+=
"
<div id='song-
"
+
songID
+
"
' class='song' data-title='
"
+
songTitle
+
"
' data-song-id='
"
+
songID
+
"
'><div class='song-title'>
"
;
_code
+=
"
<div id='song-
"
+
songID
+
"
' class='song' data-title='
"
+
songTitle
+
"
' data-song-id='
"
+
songID
+
"
'
data-preview='
"
+
songPreview
+
"
'
><div class='song-title'>
"
;
for
(
var
c
=
0
;
c
<
songTitle
.
length
;
c
++
)
{
for
(
var
c
=
0
;
c
<
songTitle
.
length
;
c
++
)
{
var
ch
=
songTitle
.
charAt
(
c
)
==
'
'
?
'
'
:
songTitle
.
charAt
(
c
);
var
ch
=
songTitle
.
charAt
(
c
)
==
'
'
?
'
'
:
songTitle
.
charAt
(
c
);
var
cl
=
ch
==
'
'
?
'
song-title-char song-title-space
'
:
'
song-title-char
'
;
var
cl
=
ch
==
'
'
?
'
song-title-char song-title-space
'
:
'
song-title-char
'
;
...
...
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