binmerge.sh: a bash based bin merger.
I searched but just couldn't find the post on vogons.org *sigh*
So I'll post Akuma's script here, I hope he doesn't mind
This merges bin files into one, and creates a new bin+cue sheet.
I think there needs to be a disclaimer attached, but i cant find it.
So use at own risk, I guess.
Code: Select all
#!/bin/bash
BINMERGE converter v1.00
Copyright (c) 2020 by Akuma under GNU General Public License 2.0
set -eo pipefail
OLDIFS=$IFS;IFS=$'\t\n'
trap "result" 0 1 2 3 15
result(){
case $? in
0) echo -e "\nSuccess";;
100) echo -e "usage: ${0##*/} /path/to/cue-file";;
101) echo "error: '$file' file not found";;
esac
echo
IFS=$OLDIFS
}
to_time(){\
printf "%02d:%02d:%02d" $(((10#$1/75)/60)) $(((10#$1/75)%60)) $((10#$1%75));}
to_frames(){ set ${1//:/ }; echo $(((60*10#$1+10#$2)*75+10#$3));}
getcuemode(){ grep -Po 'MODE./[0-9]{4}' "$1";}
getfilesize(){ stat -c%s "$1";}
mergecue(){ #cue-file
local cue="$1" line framesize filesize frames=0 print
echo "FILE \"merged.bin\" BINARY"
cat "$cue"|while read line;do
IFS=$' \t\r\n';set $line
case "$1" in
FILE) IFS='"';set $line
framesize="$(getcuemode "$cue")";framesize="${framesize##*/}"
filesize=$(getfilesize "$2")
print=$frames
frames=$((frames+(filesize/framesize)))
continue
;;
INDEX) print=$((print+$(to_frames $3)));;
PREGAP) print=$((print+$(to_frames $2)));;
esac
echo "${line/??:??:??/$(to_time $print)}"
done
IFS=$'\t\r\n'
}
mergebin(){ grep -Po '".*"' "$1"|while read file;do echo "${1%/*}/$file"; done|xargs cat;}
checkfile(){ file="$1";[[ -f "$1" ]] || exit 101;}
[[ -f "$1" ]] || exit 100
cue="$(readlink -f $1)"; checkfile "$cue"
mergecue "$cue" > merged.cue
mergebin "$cue" > merged.bin
IFS=$OLDIFS
exit 0