Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ssokolow
Created February 22, 2015 08:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssokolow/2e3748af264c70cf32c2 to your computer and use it in GitHub Desktop.
Save ssokolow/2e3748af264c70cf32c2 to your computer and use it in GitHub Desktop.
Script to generate a Desktop Dungeons soundtrack for you if you can rip the audio files from the Unity resource file you paid for
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""Script to convert ripped Desktop Dungeons unity resources to an OST
Usage: Place inside the same folder as your extracted .ogg files and run.
Requirements:
- Python 2.7 (3.x may work if you change the shebang)
- SoX
- oggvideotools
"""
from __future__ import (absolute_import, division, print_function,
with_statement, unicode_literals)
__author__ = "Stephan Sokolow (deitarion/SSokolow)"
__version__ = "0.0pre1"
__license__ = "MIT"
import glob, os, re, subprocess
camelcase_re = re.compile(r'((?<=[a-z])[A-Z0-9]|(?<!\A)[A-Z](?=[a-z]))')
files = glob.glob("*.ogg")
files.sort()
# Group the files into tracks
songs = {}
for fname, match in [(x, re.match(r'(.*)(Intro|Loop)_?(\d)?\.ogg', x))
for x in files]:
songs.setdefault(match.group(1) + (match.group(3) or ''), []).append(fname)
try:
os.makedirs('output')
except OSError, err:
if not err.errno == 17:
raise # Race-less check for "already exists"
for key, files in sorted(songs.items()):
print(', '.join(files), '->', key + '.ogg')
# Determine the final filename
name = camelcase_re.sub(r' \1', key)
# Generate a fade-out so the track doesn't just abruptly stop
assert 'loop' in files[-1].lower()
fade_base, fade_ext = os.path.splitext(files[-1])
fadename = fade_base + '_fade' + fade_ext
subprocess.check_call(['sox', files[-1], '-C', '5', fadename,
'fade', 'h', '0', '6', '6'])
# Losslessly concatenate the files
subprocess.check_call(['oggCat', os.path.join('output', name + '.ogg')] +
files + [fadename])
# Delete the temporary fade file
os.remove(fadename)
# vim: set sw=4 sts=4 expandtab :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment