This repository has been archived on 2024-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
RustedIronRing/scripts/kf4-group-sounds.py
dece eff19f5551 scripts: add dir
Add 2 scripts that I just used, could be useful.
2020-05-26 01:04:57 +02:00

49 lines
1.3 KiB
Python
Executable file

#!/usr/bin/env python3
"""Group KF4 sound files together in named dirs for later use w/ mkpsf2.
Some tools to handle sounds have issues with PS2 sounds split as HD/BD/SQ, so
grouping them with this script makes it easier to batch process them with mkspf2
so you can process them later as PSF2.
Example:
```bash
$ ./kf4-group-sounds.py workspace/dat/snd/ workspace/soundgroups
$ cd workspace/soundgroups
$ ls -lF
bgm000/
bgm001/
...
$ fd -t d -x wine mkpsf2 {}.psf2 {}
```
"""
import argparse
import glob
import os
import shutil
from pathlib import Path
def main():
argparser = argparse.ArgumentParser()
argparser.add_argument("snd_dir")
argparser.add_argument("output_dir")
args = argparser.parse_args()
copy_files(Path(args.snd_dir), Path(args.output_dir))
def copy_files(snd_path, output_path):
filenames = set([os.path.splitext(f)[0] for f in os.listdir(snd_path)])
for filename in filenames:
subfiles = glob.glob(str(snd_path / "{}.*".format(filename)))
files_output_path = output_path / filename
if not files_output_path.exists():
files_output_path.mkdir(parents=True)
for f in subfiles:
shutil.copyfile(f, files_output_path / os.path.basename(f))
if __name__ == "__main__":
main()