allow ogg to be used for previews

This commit is contained in:
Bui 2022-02-18 16:17:12 +00:00
parent 4d27499108
commit 78fe7062dc
4 changed files with 44 additions and 2 deletions

3
app.py
View File

@ -121,7 +121,8 @@ def get_config(credentials=False):
'assets_baseurl': config.ASSETS_BASEURL,
'email': config.EMAIL,
'accounts': config.ACCOUNTS,
'custom_js': config.CUSTOM_JS
'custom_js': config.CUSTOM_JS,
'preview_type': config.PREVIEW_TYPE or 'mp3'
}
if credentials:
min_level = config.GOOGLE_CREDENTIALS['min_level'] or 0

View File

@ -13,6 +13,9 @@ ACCOUNTS = True
# Custom JavaScript file to load with the simulator.
CUSTOM_JS = ''
# Filetype to use for song previews. (mp3/ogg)
PREVIEW_TYPE = 'mp3'
# MongoDB server settings.
MONGO = {
'host': ['127.0.0.1:27017'],

View File

@ -167,7 +167,7 @@ class Loader{
song.lyricsFile = new RemoteFile(directory + "main.vtt")
}
if(song.preview > 0){
song.previewMusic = new RemoteFile(directory + "preview.mp3")
song.previewMusic = new RemoteFile(directory + "preview." + gameConfig.preview_type)
}
})
assets.songsDefault = songs

38
tools/generate_previews.py Executable file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env python3
# .ogg preview generator for use when app and songs are on two different machines
import argparse
import requests
import os.path
from ffmpy import FFmpeg
parser = argparse.ArgumentParser(description='Generate song previews.')
parser.add_argument('site', help='Instance URL, eg. https://taiko.bui.pm')
parser.add_argument('song_dir', help='Path to songs directory, eg. /srv/taiko/public/taiko/songs')
parser.add_argument('--overwrite', action='store_true', help='Overwrite existing previews')
args = parser.parse_args()
if __name__ == '__main__':
songs = requests.get('{}/api/songs'.format(args.site)).json()
for i, song in enumerate(songs):
print('{}/{} {} (id: {})'.format(i + 1, len(songs), song['title'], song['id']))
song_path = '{}/{}/main.{}'.format(args.song_dir, song['id'], song['music_type'] if 'music_type' in song else 'mp3')
prev_path = '{}/{}/preview.ogg'.format(args.song_dir, song['id'])
if os.path.isfile(song_path):
if not os.path.isfile(prev_path) or args.overwrite:
if not song['preview'] or song['preview'] <= 0:
print('Skipping due to no preview')
continue
print('Making preview.ogg')
ff = FFmpeg(inputs={song_path: '-ss %s' % song['preview']},
outputs={prev_path: '-codec:a libvorbis -b:a 64k -ar 32000 -y -loglevel panic'})
ff.run()
else:
print('Preview already exists')
else:
print('song file not found')