From 923f8f45a32edef8b812948f9fe15b84634575c5 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Thu, 30 Apr 2020 00:46:38 -0400 Subject: bchunkmulti: extract bin/cue CD images with multiple bin files --- bchunkmulti | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100755 bchunkmulti diff --git a/bchunkmulti b/bchunkmulti new file mode 100755 index 0000000..a5dce5d --- /dev/null +++ b/bchunkmulti @@ -0,0 +1,131 @@ +#!/bin/sh + + +SELF="$( basename $0 )" +VERSION="0.1" + +usage() { + cat <&2 + exit 1 +fi + +base="${2:-track}" + +if [ -n "$3" ]; then + echo "$SELF: too many filenames on command line, try $SELF --help" 1>&2 + exit 1 +fi + +# de-space-ify args +bchunkopts=$( echo $bchunkopts ) + +# check that the cue file at least exists and can be read +cat "$cue_in" >/dev/null || exit $? + +# need this to let "read" read the initial spaces in the .cue file lines +IFS="" + +# save old stdout +exec 3>&1 + +# use temp dir in the current dir (we're writing there anyway) +tmpdir="$( mktemp -d bcm.XXXXXX )" +[ -z "$tmpdir" ] && exit $? + +# split up each track entry in the input .cue file into a separate .cue +# file containing only that track. +count=1 +cat "$cue_in" | while read line; do + case "$line" in + FILE*) cue_out="$tmpdir/tmpcue$( printf '%02d' $count ).cue" + exec > "$cue_out" + count="$( expr $count + 1 )" + ;; + esac + echo "$line" +done + +# restore old stdout +exec 1>&3 + +# now convert each file to .iso or .wav (bchunk is smart enough +# to know which is which). +for cue_out in $tmpdir/tmpcue??.cue; do + binfile="$( head -1 "$cue_out" | cut -d\" -f2 )" + tracktmp="$tmpdir/tmp" + + # brand new empty dir for bchunk to write to, will contain only + # one file after bchunk runs. + rm -rf "$tracktmp" + mkdir -p "$tracktmp" + + bchunk $bchunkopts "$binfile" "$cue_out" "$tracktmp"/"$base" + + if grep -q 'TRACK.*AUDIO' "$cue_out"; then + # got audio track, convert to ogg and/or flac if requested + if [ -n "$OGGQ$FLAC" ]; then + [ -n "$OGGQ" ] && oggenc -q"$OGGQ" "$tracktmp"/*.wav + [ -n "$FLAC" ] && flac "$tracktmp"/*.wav + [ -z "$KEEPWAV" ] && rm -f "$tracktmp"/*.wav + fi + fi + + mv "$tracktmp"/* . + + rm -rf "$cue_out" "$tracktmp" +done + +rmdir "$tmpdir" +exit 0 -- cgit v1.2.3