From d30ee1df37c2b0f38768ba452ca1ffae9a3ea628 Mon Sep 17 00:00:00 2001 From: BLooperZ Date: Fri, 8 Nov 2019 01:34:35 +0200 Subject: TOON: add create subtitles tools --- devtools/create_toon/subtitles/pakdir.py | 56 ++++++++++++++++++++++++++++++ devtools/create_toon/subtitles/submaker.py | 52 +++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 devtools/create_toon/subtitles/pakdir.py create mode 100644 devtools/create_toon/subtitles/submaker.py diff --git a/devtools/create_toon/subtitles/pakdir.py b/devtools/create_toon/subtitles/pakdir.py new file mode 100644 index 0000000000..7e3ad9411b --- /dev/null +++ b/devtools/create_toon/subtitles/pakdir.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python + +""" +This script generates subtitles for Toonstrack cutscenes +in a single SUBTITLES.PAK file from given directory of .SBV subtitles + +Usage: +``` +pakdir.py SUBTITLES_DIR +```` +""" + +import struct +from itertools import chain + +from submaker import sbv2tss + +def write_uint32_le(number): + return struct.pack(' +''' +import io +import sys + +from datetime import datetime + +TIME_FORMAT = '%H:%M:%S.%f' +BASETIME = datetime(1900, 1, 1) +FPS = 15 + +def time2frame(time, fps=FPS): + return round(fps * (datetime.strptime('0' + time + '000', TIME_FORMAT) - BASETIME).total_seconds()) + +def sbv2tss(infile, fps=FPS): + with open(infile, 'r') as sub_file: + lines = sub_file.read().split('\n\n') + + # ignore empty lines + lines = [line for line in lines if line] + + for line in lines: + time_window, text = line.split('\n')[:2] + start, end = time_window.split(',') + start = time2frame(start, fps=fps) + end = time2frame(end[:-1], fps=fps) + + yield '{start} {end} {line}\n'.format(start=start, end=end, line=text) + +if __name__ == '__main__': + if len(sys.argv) < 3: + print('Usage: toon_submaker.py INFILE.sbv OUTFILE.tss') + exit(1) + + infile = sys.argv[1] + outfile = sys.argv[2] + + with open(outfile, 'w') as sub_file: + for line in sbv2tss(infile): + sub_file.write(line) -- cgit v1.2.3