Skip to content

Instantly share code, notes, and snippets.

@Pysis868
Last active December 18, 2024 23:37
Show Gist options
  • Save Pysis868/f1a2c8e69a64e6e2dac7486eae56b7a8 to your computer and use it in GitHub Desktop.
Save Pysis868/f1a2c8e69a64e6e2dac7486eae56b7a8 to your computer and use it in GitHub Desktop.
SatisfactoryAudioRenamer updated convert scripts for batch/mass parsing WWISER audio file metadata to extra to rename FModel-extracted wem audio files.
#!/usr/bin/env fish
# SatisfactoryAudioRenamer alternative convert script for batch/mass parsing
# WWISER audio file metadata to rename FModel-extracted wem audio files.
# Sample wem file reference lines:
# Other's (WWISER v20240526):
# wem/218091215.wem
#
# Mine (WWISER v20241210):
# ../Media/10/1072608286.wem
# Fixing and Conversion example:
# if pushd "$dir"
# find 'out' -mindepth 1 -maxdepth 1 -iname '*.wav' -printf '%f\n' \
# | while read fileName
# test ! -e 'out2'; and mkdir 'out2';
# set fileFixed 'out2/'(filenameAddSuffix "$fileName" '-fixed');
# if test ! -e "$fileFixed"
# '.../FModel Exports/Exports/.data/vgmstream-cli.exe' \
# "out/$fileName" \
# -o "$fileFixed" \
# ;
# end
#
# test ! -e 'out3'; and mkdir 'out3';
# set fileConverted 'out3/'(removeExtension (basename "$fileFixed"))'.opus';
# if test ! -e "$fileConverted"
# ffmpeg \
# -i "$fileFixed" \
# "$fileConverted" \
# < /dev/null \
# ;
# end
# end
# end
set infoExt 'txtp' ;
set infoDir "$infoExt";
set mediaDir 'Media' ;
set outDir 'out' ;
# | head -n 2 \
find "$infoDir" -type f -iname "*.$infoExt" \
| while read infoFile
echo "Processing infoFile \"$infoFile\"...";
set wemFiles (
grep -oiP '^\s*(../.+?\.wem)' "$infoFile" \
| string trim \
| sed -r 's/^..\///'
);
# debugPrint "wemFiles: $wemFiles";
# debugPrint -n 'count wemFiles: '; and altPrint (count $wemFiles);
set index '0';
for wemFile in $wemFiles
if test ! -f "$wemFile"
echo "$wemFile not found.";
echo "$wemFile not found." >> 'errors.log';
set index (echo "$index + 1" | bc);
# exit 1;
continue;
end
set wavFile "$outDir/"(
basename "$infoFile" \
| sed -r "s/\.$infoExt\$//"
)"_$index.wav";
set index (echo "$index + 1" | bc);
if test -f "$wavFile"
echo "Wav file $wavFile already exists.";
continue;
end
if cp "$wemFile" "$wavFile"
echo "Copied $wemFile to $wavFile.";
else
echo "Failed to copy $wemFile to $wavFile.";
exit 2;
end
# Just use vgmstream to recognize non-standard wav header metadata
# and convert from the Audiokinetic Wwise RIFF format.
# audioFormat
# begin
if false
set audioFormat (
dd if="$wavFile" \
bs=1 count=2 \
skip=20 \
status=none \
| xxd -p
);
if test "$audioFormat" = 'feff'
if echo '0100' \
| xxd -p -r \
| dd of="$wavFile" \
bs=1 count=2 \
seek=20 \
status=none \
conv=notrunc
echo 'Fixed wav file\'s audio format by setting to PCM Integer.';
else
echo 'Could not fix wav file\'s audio format by setting to PCM Integer.';
end
end
end
# bytes
# begin
if false
set bytePerSec (
dd if="$wavFile" \
bs=1 count=4 \
skip=28 \
status=none \
| xxd -p
);
set bytePerBloc (
dd if="$wavFile" \
bs=1 count=2 \
skip=32 \
status=none \
| xxd -p
);
set bitsPerSample (
dd if="$wavFile" \
bs=1 count=2 \
skip=34 \
status=none \
| xxd -p
);
if test "$bytePerBloc" = '0000'
if echo '0400' \
| xxd -p -r \
| dd of="$wavFile" \
bs=1 count=2 \
seek=32 \
status=none \
conv=notrunc
echo 'Fixed wav file\'s BytePerBloc by setting to 4.';
else
echo 'Could not fix wav file\'s BytePerBloc by setting to 4.';
end
end
if test "$bitsPerSample" = '0000'
if echo '1000' \
| xxd -p -r \
| dd of="$wavFile" \
bs=1 count=2 \
seek=34 \
status=none \
conv=notrunc
echo 'Fixed wav file\'s BitsPerSample by setting to 16.';
else
echo 'Could not fix wav file\'s BitsPerSample by setting to 16.';
end
end
end
end
echo;
end
#!/usr/bin/env python
# SatisfactoryAudioRenamer updated convert script for batch/mass parsing WWISER
# audio file metadata to rename FModel-extracted wem audio files.
# Sample wem file reference lines:
# Other's (WWISER v20240526):
# wem/218091215.wem
#
# Mine (WWISER v20241210):
# ../Media/10/1072608286.wem
# Fixing and Conversion example:
# if pushd "$dir"
# find 'out' -mindepth 1 -maxdepth 1 -iname '*.wav' -printf '%f\n' \
# | while read fileName
# test ! -e 'out2'; and mkdir 'out2';
# set fileFixed 'out2/'(filenameAddSuffix "$fileName" '-fixed');
# if test ! -e "$fileFixed"
# '.../FModel Exports/Exports/.data/vgmstream-cli.exe' \
# "out/$fileName" \
# -o "$fileFixed" \
# ;
# end
#
# test ! -e 'out3'; and mkdir 'out3';
# set fileConverted 'out3/'(removeExtension (basename "$fileFixed"))'.opus';
# if test ! -e "$fileConverted"
# ffmpeg \
# -i "$fileFixed" \
# "$fileConverted" \
# < /dev/null \
# ;
# end
# end
# end
import os
from pathlib import Path
import shutil
def convert(filename):
my_file = open('./txtp/' + filename, 'r')
data = my_file.read()
my_file.close()
data_into_list = data.replace('\n', ' ').split(' ')
for i in range(len(data_into_list)):
term = data_into_list[i]
if term.endswith('wem'):
wemfile = term
wemfilesrc = relevant_path + wemfile
wavname = './out/' + filename.split('.')[0] + '_' + str(i) + '.wav'
if not os.path.isfile(wemfilesrc):
print(wemfilesrc + ' not found.')
exit(1)
if os.path.isfile(wavname):
print('Wav file ' + wavname + ' already exists.');
continue
if shutil.copy(wemfilesrc, wavname):
print('Copied ' + wemfilesrc + ' to ' + wavname + '.')
else:
print('Failed to copy ' + wemfilesrc + ' to ' + wavname + '.')
exit(2)
relevant_path = './txtp/'
included_extensions = ['txtp']
file_names = [fn for fn in os.listdir(relevant_path)
if any(fn.endswith(ext) for ext in included_extensions)]
for file_name in file_names:
convert(file_name)
exit() # testing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment