Rework s3p_to_2dx, add args for IIDX 31 to ep_bm2dxnix (now named bm2dnix), update readme
This commit is contained in:
parent
dc46a5bc2a
commit
b8a6ffa486
140
s3p_to_2dx
140
s3p_to_2dx
@ -1,38 +1,119 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Set the directory containing sound files
|
# Set the directory containing sound files, typically found in /data/sound in the games "contents"
|
||||||
# This is usually ./sound if youre running the script out of the games data directory
|
SOUND_DIR=""
|
||||||
SOUND_DIR="please-set-this"
|
|
||||||
|
|
||||||
# Extract .ifs file and descend into its directory
|
# Set alternative paths to external binaries (s3p_extract, 2dxBuild (apart of 2dxTools), ifstools, and ffmpeg)
|
||||||
# Sound data doesn't need to be repacked into .ifs - easier for the sake of managing future updates
|
# Otherwise, default to /usr/bin
|
||||||
extract_cleanup_ifs() {
|
S3P_EXTRACT_BIN="${S3P_EXTRACT_BIN:-s3p_extract}"
|
||||||
local ifs_file="$1"
|
BUILD_2DX_BIN="${TWO_DX_BUILD_BIN:-2dxBuild}"
|
||||||
echo "Extracting $ifs_file..."
|
IFSTOOLS_BIN="${IFSTOOLS_BIN:-ifstools}"
|
||||||
ifstools "$ifs_file" || { echo "Failed to extract $ifs_file"; return 1; }
|
FFMPEG_BIN="${FFMPEG_BIN:-ffmpeg}"
|
||||||
local extracted_dir="${ifs_file%.*}_ifs"
|
|
||||||
[ -d "$extracted_dir" ] && cd "$extracted_dir" || { echo "Directory $extracted_dir not found"; return 1; }
|
# Print basic usage if required args are missing
|
||||||
|
usage() {
|
||||||
|
echo "Usage: $0 [-s </path/to/sound/dir>] [-e </path/to/s3p_extract>] [-b </path/to/2dxBuild>] [-i </path/to/ifstools>] [-f </path/to/ffmpeg>]"
|
||||||
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Options for sound directory and custom paths
|
||||||
|
while getopts ":s:e:b:i:f:" opt; do
|
||||||
|
case $opt in
|
||||||
|
s) SOUND_DIR="$OPTARG" ;;
|
||||||
|
e) S3P_EXTRACT_BIN="$OPTARG" ;;
|
||||||
|
b) BUILD_2DX_BIN="$OPTARG" ;;
|
||||||
|
i) IFSTOOLS_BIN="$OPTARG" ;;
|
||||||
|
f) FFMPEG_BIN="$OPTARG" ;;
|
||||||
|
*) usage ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
# Extract and convert .s3p files
|
# Check if $SOUND_DIR is set
|
||||||
extract_convert_s3p() {
|
if [ -z "$SOUND_DIR" ]; then
|
||||||
local s3p_file="$1"
|
echo "Error: SOUND_DIR is not set. Use -s to specify the sound directory."
|
||||||
echo "Processing $s3p_file..."
|
usage
|
||||||
s3p_extract "$s3p_file" || { echo "Failed to extract $s3p_file"; return 1; }
|
fi
|
||||||
local s3p_out_dir="${s3p_file}.out"
|
|
||||||
[ -d "$s3p_out_dir" ] && cd "$s3p_out_dir" || { echo "Directory $s3p_out_dir not found"; return 1; }
|
|
||||||
|
|
||||||
for wma_file in *.wma; do
|
# Extract .ifs file and descend into its directory
|
||||||
[ -e "$wma_file" ] || continue
|
extract_ifs() {
|
||||||
echo -ne "Converting $wma_file..."\\r
|
local ifs_file="$1"
|
||||||
ffmpeg -loglevel error -i "$wma_file" -acodec adpcm_ms -b:a 256k "${wma_file%.*}.wav" && rm -f "$wma_file" # Writes to log instead
|
echo "Extracting $ifs_file..."
|
||||||
|
|
||||||
|
# Ensure the path is correct by making it absolute if necessary
|
||||||
|
if [[ "$ifs_file" != /* ]]; then
|
||||||
|
ifs_file="$ifs_file"
|
||||||
|
fi
|
||||||
|
|
||||||
|
"IFSTOOLS_BIN" --super-disable "$ifs_file" || { echo "Failed to extract $ifs_file"; return 1; } # super-disable arg required for processing p0 .ifs without their parent .ifs
|
||||||
|
}
|
||||||
|
|
||||||
|
# ifstools outputs its files into a nested directory, with its parent dir being the song id, with the _ifs or -p0_ifs suffix
|
||||||
|
# This needs to be cleaned up before contents are moved into $SOUND_DIR, which is why this silly function exists
|
||||||
|
cleanup_ifs() {
|
||||||
|
for dir in *_ifs *-p0_ifs; do
|
||||||
|
if [ -d "$dir" ]; then
|
||||||
|
if [[ "$dir" == *"-p0_ifs" ]]; then
|
||||||
|
|
||||||
|
# If the directory ends with "-p0_ifs", strip the "_ifs" suffix but retain the "-p0" when moving to $SOUND_DIR
|
||||||
|
# -p0.ifs are children to full .ifs files and appear to be chart updates (black another/leggendaria/etc?)
|
||||||
|
# Need to exist as their own ifs file or directory
|
||||||
|
|
||||||
|
base_name=$(basename "$dir" _ifs)
|
||||||
|
inner_base_name="${base_name%-p0}"
|
||||||
|
inner_dir="$dir/$inner_base_name"
|
||||||
|
move_dir="$SOUND_DIR/$base_name" # Keeps the -p0 when moving
|
||||||
|
|
||||||
|
else
|
||||||
|
# Otherwise, strip just _ifs for standard ifs files
|
||||||
|
base_name=$(basename "$dir" _ifs)
|
||||||
|
inner_dir="$dir/$base_name"
|
||||||
|
move_dir="$SOUND_DIR/$base_name" # Moves normally without -p0, since these are full song containers
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if the inner directory exists
|
||||||
|
if [ -d "$inner_dir" ]; then
|
||||||
|
echo "Moving $inner_dir to $move_dir"
|
||||||
|
|
||||||
|
# Move the inner directory to $SOUND_DIR with the correct naming
|
||||||
|
mv "$inner_dir" "$move_dir"
|
||||||
|
|
||||||
|
# Remove the now empty parent directory
|
||||||
|
rmdir "$dir"
|
||||||
|
else
|
||||||
|
echo "Inner directory $inner_dir not found in $dir"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Repack .wav files into .2dx
|
# Extracts and converts .s3p files
|
||||||
|
extract_convert_s3p() {
|
||||||
|
local s3p_file="$1"
|
||||||
|
echo "Processing $s3p_file..."
|
||||||
|
|
||||||
|
# Check if the directory contains .2dx files while ignoring preview files (_pre.2dx)
|
||||||
|
if find . -maxdepth 1 -type f -name "*.2dx" ! -name "*_pre.2dx" | grep -q .; then
|
||||||
|
echo "Directory contains .2dx (excluding preview files) - skipping."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Proceed with extraction
|
||||||
|
"S3P_EXTRACT_BIN" "$s3p_file" || { echo "Failed to extract $s3p_file"; return 1; }
|
||||||
|
local s3p_out_dir="${s3p_file}.out"
|
||||||
|
[ -d "$s3p_out_dir" ] && cd "$s3p_out_dir" || { echo "Directory $s3p_out_dir not found"; return 1; }
|
||||||
|
|
||||||
|
# Convert .wma files to .wav
|
||||||
|
for wma_file in *.wma; do
|
||||||
|
[ -e "$wma_file" ] || continue
|
||||||
|
echo -ne "Converting $wma_file..."\\r
|
||||||
|
"FFMPEG_BIN" -loglevel error -i "$wma_file" -acodec adpcm_ms -b:a 256k "${wma_file%.*}.wav" && rm -f "$wma_file"
|
||||||
|
# Remove loglevel argument if you want to see what ffmpeg is doing
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Repacks .wav files into .2dx
|
||||||
repack_to_2dx() {
|
repack_to_2dx() {
|
||||||
echo "Repacking files to .2dx..."
|
echo "Repacking song/chart data to .2dx..."
|
||||||
|
|
||||||
# Get the current working directory name
|
# Get the current working directory name
|
||||||
dir_name=$(basename "$OLDPWD")
|
dir_name=$(basename "$OLDPWD")
|
||||||
@ -40,23 +121,24 @@ repack_to_2dx() {
|
|||||||
# Remove the ".out" suffix from the directory name if it exists
|
# Remove the ".out" suffix from the directory name if it exists
|
||||||
output_name="${dir_name%.out}"
|
output_name="${dir_name%.out}"
|
||||||
|
|
||||||
2dxBuild "$output_name".2dx || { echo "Failed to repack files"; return 1; }
|
"BUILD_2DX_BIN" "$output_name".2dx || { echo "Failed to repack files"; return 1; }
|
||||||
mv "$output_name".2dx ..
|
mv "$output_name".2dx ..
|
||||||
cd ..
|
cd ..
|
||||||
rm -rf *s3p*
|
rm -rf *s3p*
|
||||||
}
|
}
|
||||||
|
|
||||||
# Iterate through directories and .ifs in $SOUND_DIR
|
# Iterates through directories and .ifs in $SOUND_DIR
|
||||||
process_sound_files() {
|
process_sound_files() {
|
||||||
if [ ! -d "$SOUND_DIR" ]; then
|
if [ ! -d "$SOUND_DIR" ]; then
|
||||||
echo "Directory $SOUND_DIR does not exist."
|
echo "Directory $SOUND_DIR does not exist."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Unpack.ifs files into directories
|
# Unpack.ifs files into directories, do not repack into .ifs - easier for the sake of managing future updates
|
||||||
for ifs_file in "$SOUND_DIR"/*.ifs; do
|
for ifs_file in "$SOUND_DIR"/*.ifs; do
|
||||||
echo "Processing IFS file: $ifs_file"
|
echo "Processing .ifs file: $ifs_file"
|
||||||
(cd "$SOUND_DIR" && extract_cleanup_ifs "$ifs_file")
|
(extract_ifs "$ifs_file")
|
||||||
|
cleanup_ifs
|
||||||
done
|
done
|
||||||
|
|
||||||
# Convert all directories
|
# Convert all directories
|
||||||
|
Loading…
Reference in New Issue
Block a user