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
1a2753c4
Commit
1a2753c4
authored
Oct 18, 2018
by
Bui
Committed by
GitHub
Oct 18, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #59 from bui/make-preview
Generate previews for songs
parents
d6a42c0f
0b757c09
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
21 deletions
+74
-21
app.py
app.py
+56
-13
public/src/js/songselect.js
public/src/js/songselect.js
+18
-8
No files found.
app.py
View file @
1a2753c4
#!/usr/bin/env python2
#!/usr/bin/env python2
from
__future__
import
division
import
json
import
json
import
sqlite3
import
sqlite3
import
re
import
re
import
os
import
os
from
flask
import
Flask
,
g
,
jsonify
,
render_template
from
flask
import
Flask
,
g
,
jsonify
,
render_template
,
request
,
abort
,
redirect
from
ffmpy
import
FFmpeg
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
DATABASE
=
'taiko.db'
DATABASE
=
'taiko.db'
...
@@ -60,6 +63,21 @@ def get_osu_key(osu, section, key, default=None):
...
@@ -60,6 +63,21 @@ def get_osu_key(osu, section, key, default=None):
return
default
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
):
def
get_tja_preview
(
tja
):
tja_lines
=
open
(
tja
,
'r'
)
.
read
()
.
replace
(
'
\x00
'
,
''
)
.
split
(
'
\n
'
)
tja_lines
=
open
(
tja
,
'r'
)
.
read
()
.
replace
(
'
\x00
'
,
''
)
.
split
(
'
\n
'
)
...
@@ -95,6 +113,24 @@ def route_index():
...
@@ -95,6 +113,24 @@ def route_index():
return
render_template
(
'index.html'
,
version
=
version
)
return
render_template
(
'index.html'
,
version
=
version
)
@
app
.
route
(
'/api/preview'
)
def
route_api_preview
():
song_id
=
request
.
args
.
get
(
'id'
,
None
)
if
not
song_id
or
not
re
.
match
(
'^[0-9]+$'
,
song_id
):
abort
(
400
)
song_row
=
query_db
(
'select * from songs where id = ? and enabled = 1'
,
(
song_id
,))
if
not
song_row
:
abort
(
400
)
song_type
=
song_row
[
0
][
10
]
prev_path
=
make_preview
(
song_id
,
song_type
)
if
not
prev_path
:
return
redirect
(
''
.
join
([
request
.
host_url
,
'/songs/
%
s/main.mp3'
%
song_id
]))
return
redirect
(
''
.
join
([
request
.
host_url
,
'/songs/
%
s/preview.mp3'
%
song_id
]))
@
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'
)
...
@@ -107,18 +143,7 @@ def route_api_songs():
...
@@ -107,18 +143,7 @@ def route_api_songs():
for
song
in
songs
:
for
song
in
songs
:
song_id
=
song
[
0
]
song_id
=
song
[
0
]
song_type
=
song
[
10
]
song_type
=
song
[
10
]
if
song_type
==
"tja"
:
preview
=
get_preview
(
song_id
,
song_type
)
if
os
.
path
.
isfile
(
'public/songs/
%
s/main.tja'
%
song_id
):
preview
=
get_tja_preview
(
'public/songs/
%
s/main.tja'
%
song_id
)
else
:
preview
=
0
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
))
else
:
preview
=
0
category_out
=
categories
[
song
[
9
]]
if
song
[
9
]
in
categories
else
def_category
category_out
=
categories
[
song
[
9
]]
if
song
[
9
]
in
categories
else
def_category
songs_out
.
append
({
songs_out
.
append
({
...
@@ -138,5 +163,23 @@ def route_api_songs():
...
@@ -138,5 +163,23 @@ def route_api_songs():
return
jsonify
(
songs_out
)
return
jsonify
(
songs_out
)
def
make_preview
(
song_id
,
song_type
):
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
print
'Making preview.mp3 for song #
%
s'
%
song_id
ff
=
FFmpeg
(
inputs
=
{
song_path
:
'-ss
%
s'
%
preview
},
outputs
=
{
prev_path
:
'-codec:a libmp3lame -ar 32000 -b:a 92k -y -loglevel panic'
})
ff
.
run
()
return
prev_path
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
app
.
run
(
port
=
34801
)
app
.
run
(
port
=
34801
)
public/src/js/songselect.js
View file @
1a2753c4
...
@@ -1263,29 +1263,39 @@ class SongSelect{
...
@@ -1263,29 +1263,39 @@ class SongSelect{
}
}
var
songObj
=
assets
.
songs
.
find
(
song
=>
song
.
id
==
id
)
var
songObj
=
assets
.
songs
.
find
(
song
=>
song
.
id
==
id
)
if
(
songObj
.
sound
){
if
(
songObj
.
preview_
sound
){
if
(
!
loadOnly
){
if
(
!
loadOnly
){
this
.
preview
=
songObj
.
sound
this
.
preview
=
songObj
.
preview_
sound
this
.
preview
.
gain
=
snd
.
previewGain
this
.
preview
.
gain
=
snd
.
previewGain
this
.
previewLoaded
(
startLoad
,
prvT
ime
)
this
.
previewLoaded
(
startLoad
,
songObj
.
preview_t
ime
)
}
}
}
else
{
}
else
{
snd
.
previewGain
.
load
(
"
/songs/
"
+
id
+
"
/main.mp3
"
).
then
(
sound
=>
{
var
previewFilename
=
prvTime
>
0.1
?
"
/preview.mp3
"
:
"
/main.mp3
"
var
loadPreview
=
previewFilename
=>
{
return
snd
.
previewGain
.
load
(
"
/songs/
"
+
id
+
previewFilename
)
}
songObj
.
preview_time
=
0
loadPreview
(
previewFilename
).
catch
(()
=>
{
songObj
.
preview_time
=
prvTime
return
loadPreview
(
"
/main.mp3
"
)
}).
then
(
sound
=>
{
if
(
currentId
===
this
.
previewId
){
if
(
currentId
===
this
.
previewId
){
songObj
.
sound
=
sound
songObj
.
preview_
sound
=
sound
this
.
preview
=
sound
this
.
preview
=
sound
this
.
previewLoaded
(
startLoad
,
prvT
ime
)
this
.
previewLoaded
(
startLoad
,
songObj
.
preview_t
ime
)
}
}
})
})
}
}
}
}
}
}
previewLoaded
(
startLoad
,
prv
t
ime
){
previewLoaded
(
startLoad
,
prv
T
ime
){
var
endLoad
=
this
.
getMS
()
var
endLoad
=
this
.
getMS
()
var
difference
=
endLoad
-
startLoad
var
difference
=
endLoad
-
startLoad
var
minDelay
=
300
var
minDelay
=
300
var
delay
=
minDelay
-
Math
.
min
(
minDelay
,
difference
)
var
delay
=
minDelay
-
Math
.
min
(
minDelay
,
difference
)
this
.
preview
.
playLoop
(
delay
/
1000
,
false
,
prv
t
ime
/
1000
)
this
.
preview
.
playLoop
(
delay
/
1000
,
false
,
prv
T
ime
/
1000
)
}
}
endPreview
(){
endPreview
(){
this
.
previewId
++
this
.
previewId
++
...
...
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