splitape最早是用来分割APE文件的,现在稍微经过扩展,各种文件都能分割。

割完了能转成FLAC或其他格式,并且根据metadata进行命名,之后用easytag处理一下就能内嵌metadata了,例如id3v2或者flac的tag之类。

用到了shntool

#!/bin/sh

if [ $# -le 1 ]; then
        echo "This tool would split ape file to flac file(s) according to cue sheet."
        echo "You may also specify other formats."
        echo "usage: $0 <cue file name> <ape file name> [<output format>]"
        exit 1
fi

CUEFILE="$1"

FILETYPE=`file "$1"`
PA=`echo $FILETYPE | grep "ISO-8859"`
PB=`echo $FILETYPE | grep "extended-ASCII"`
PC=`echo $FILETYPE | grep "Non-ISO"`

if [ "$PA" != "" -o "$PB" != "" -o "$PC" != "" ]; then
        echo "Found GBK-encoded CUE file, converting..."
        cat "$1" | iconv -f gbk > /tmp/splitape.cue.tmp
        CUEFILE=/tmp/splitape.cue.tmp
fi

if [ "$3" = "" ]; then
        OUTPUT_FORMAT="flac"
elif [ "$3" = "mp3" ]; then
    OUTPUT_FORMAT="cust ext=mp3 lame - %f"
else
        OUTPUT_FORMAT=$3
fi

echo "CUE File: $1"
echo "APE File: $2"

shntool split -f "$CUEFILE" -t %n_%p_%a_%t -o "$OUTPUT_FORMAT" "$2"