From 78fe7062dcc08db131fd4f273f7b3ac8b2a4241d Mon Sep 17 00:00:00 2001 From: Bui Date: Fri, 18 Feb 2022 16:17:12 +0000 Subject: [PATCH] allow ogg to be used for previews --- app.py | 3 ++- config.example.py | 3 +++ public/src/js/loader.js | 2 +- tools/generate_previews.py | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100755 tools/generate_previews.py diff --git a/app.py b/app.py index 639c25e..29067f3 100644 --- a/app.py +++ b/app.py @@ -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 diff --git a/config.example.py b/config.example.py index f954121..311827b 100644 --- a/config.example.py +++ b/config.example.py @@ -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'], diff --git a/public/src/js/loader.js b/public/src/js/loader.js index 7fa203d..f57960e 100644 --- a/public/src/js/loader.js +++ b/public/src/js/loader.js @@ -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 diff --git a/tools/generate_previews.py b/tools/generate_previews.py new file mode 100755 index 0000000..6847410 --- /dev/null +++ b/tools/generate_previews.py @@ -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')