You are not logged in.

#1 2009-07-11 01:37:14

sen
Member
From: .de
Registered: 2007-02-18
Posts: 153
Website

CUE Audio-CD Image Splitter

I had to split alot of Music CDs today (different filetypes) and created a simple script to automate & speed up the process.
Dunno if there already exists a programm for this but maybe some of you find it useful as well.

The script is a frontend for: cuetools shntool mp3splt
supported filetypes: ape flac mp3 ogg tta wv wav

It splits the image in single files and tags them using the infos provided in the cue file.
ape and wav files will be converted to flac.

Usage: cuesplit /path/to/dir
The default path is the current directory.

cuesplit.sh

#!/bin/sh

# frontend for:            cuetools, shntool, mp3splt
# optional dependencies:    flac, mac, wavpack, ttaenc
# v1.3 sen


SDIR=`pwd`

if [ "$1" = "" ]
  then
    DIR=$SDIR
else
    case $1 in
        -h | --help )
            echo "Usage: cuesplit [Path]"
            echo "       The default path is the current directory."
            exit
            ;;
        * )
        DIR=$1
    esac
fi

echo -e "\

Directory: $DIR
________________________________________
"
cd "$DIR"
TYPE=`ls -t1`

case $TYPE in
    *.ape*)
        mkdir split
        shnsplit -d split -f *.cue -o "flac flac -V --best -o %f -" *.ape -t "%n %p - %t"
        rm -f split/00*pregap*
        cuetag.sh *.cue split/*.flac
        exit
        ;;

    *.flac*)
        mkdir split
        shnsplit -d split -f *.cue -o "flac flac -V --best -o %f -" *.flac -t "%n %p - %t"
        rm -f split/00*pregap*
        cuetag.sh *.cue split/*.flac
        exit
        ;;

    *.mp3*)
        mp3splt -no "@n @p - @t (split)" -c *.cue *.mp3
        cuetag.sh *.cue *split\).mp3
        exit
        ;;

    *.ogg*)
        mp3splt -no "@n @p - @t (split)" -c *.cue *.ogg
        cuetag.sh *.cue *split\).ogg
        exit
        ;;

    *.tta*)
        mkdir split
        shnsplit -d split -f *.cue -o "flac flac -V --best -o %f -" *.tta -t "%n %p - %t"
        rm -f split/00*pregap*
        cuetag.sh *.cue split/*.flac
        exit
        ;;

    *.wv*)
        mkdir split
        shnsplit -d split -f *.cue -o "flac flac -V --best -o %f -" *.wv -t "%n %p - %t"
        rm -f split/00*pregap*
        cuetag.sh *.cue split/*.flac
        exit
        ;;

    *.wav*)
        mkdir split
        shnsplit -d split -f *.cue -o "flac flac -V --best -o %f -" *.wav -t "%n %p - %t"
        rm -f split/00*pregap*
        cuetag.sh *.cue split/*.flac
        exit
        ;;

    * )
    echo "Error: Found no files to split!"
    echo "       --> APE, FLAC, MP3, OGG, TTA, WV, WAV"
esac
exit

edit: Just had to split a tta file and updated the script.
edit2: better file naming for flac files
edit3: parses additional flac encoder settings: -V --best

Last edited by sen (2010-05-16 05:13:00)

Offline

#2 2009-07-12 22:43:44

Rasi
Member
From: Germany
Registered: 2007-08-14
Posts: 1,914
Website

Re: CUE Audio-CD Image Splitter

sen wrote:

I had to split alot of Music CDs today (different filetypes) and created a simple script to automate & speed up the process.
Dunno if there already exists a programm for this but maybe some of you find it useful as well.

The script is a frontend for: cuetools shntool mp3splt
supported filetypes: ape flac mp3 ogg wv wav

It splits the image in single files and tags them using the infos provided in the cue file.
ape and wav files will be converted to flac.

Usage: cuesplit /path/to/dir
The default path is the current directoty.

cuesplit.sh

#!/bin/sh

# frontend for:            cuetools, shntool, mp3splt
# optional dependencies:    flac, mac, wavpack

SDIR=`pwd`

if [ "$1" = "" ]
  then
    DIR=$SDIR
else
    case $1 in
        -h | --help )
            echo "Usage: cuesplit [Path]"
            echo "       The default path is the current directory."
            exit
            ;;
        * )
        DIR=$1
    esac
fi

echo -e "\

Directory: $DIR
________________________________________
"
cd "$DIR"
TYPE=`ls -t1`

case $TYPE in
    *.ape*)
        cuebreakpoints *.cue | shnsplit -a track -o flac *.ape
        cuetag.sh *.cue track*.flac
        exit
        ;;

    *.flac*)
        cuebreakpoints *.cue | shnsplit -a track -o flac *.flac
        cuetag.sh *.cue track*.flac
        exit
        ;;

    *.mp3*)
        mp3splt -no "@n @p - @t (split)" -c *.cue *.mp3
        cuetag.sh *.cue *split\).mp3
        exit
        ;;

    *.ogg*)
        mp3splt -no "@n @p - @t (split)" -c *.cue *.ogg
        cuetag.sh *.cue *split\).ogg
        exit
        ;;

    *.wv*)
        cuebreakpoints *.cue | shnsplit -a track -o flac *.wv
        cuetag.sh *.cue track*.flac
        exit
        ;;

    *.wav*)
        cuebreakpoints *.cue | shnsplit -a track -o flac *.wav
        cuetag.sh *.cue track*.flac
        exit
        ;;

    * )
    echo "Error: Found no files to split!"
    echo "       --> APE, FLAC, MP3, OGG, WV, WAV"
esac
exit

Thanks, very nice job....


He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.

Douglas Adams

Offline

#3 2009-07-28 17:34:45

evhan
Member
Registered: 2009-07-20
Posts: 6
Website

Re: CUE Audio-CD Image Splitter

This is excellent -- thanks a ton.

Offline

#4 2010-02-09 20:57:25

hsn
Member
Registered: 2009-02-07
Posts: 17

Re: CUE Audio-CD Image Splitter

Tanks a lot big_smile

Offline

#5 2010-04-26 02:45:18

sen
Member
From: .de
Registered: 2007-02-18
Posts: 153
Website

Re: CUE Audio-CD Image Splitter

Updated to v1.2! wink

Offline

#6 2010-05-15 09:53:58

misc
Member
From: Bavaria, Germany
Registered: 2010-03-22
Posts: 115

Re: CUE Audio-CD Image Splitter

Thanks a lot for this; I was really missing something with a Medieval CUE Splitter functionality.

One dozy question though: Do the scripts / programs it calls make flac encode with the highest compression level?

Offline

#7 2010-05-16 05:22:47

sen
Member
From: .de
Registered: 2007-02-18
Posts: 153
Website

Re: CUE Audio-CD Image Splitter

misc wrote:

Thanks a lot for this; I was really missing something with a Medieval CUE Splitter functionality.

One dozy question though: Do the scripts / programs it calls make flac encode with the highest compression level?

Actually I didn't know if you can parse encoder settings via shnsplit but it is possible and thanks to you I looked into this.

The default flac encoding settings are this:

flac -s -o %f

So the default flac compression level of 6 was used (8 being the highest available).

I've updated the script and added the flac encoder settings -V (verification) and --best (highest available compression level - currently 8).

Offline

#8 2011-02-22 16:08:24

wsduvall
Member
From: Blacksburg
Registered: 2009-02-05
Posts: 54
Website

Re: CUE Audio-CD Image Splitter

Major thanks for this gem. I posted a link to this thread on the APE+CUE Splitting wiki page here: https://wiki.archlinux.org/index.php/AP … _Splitting

Last edited by wsduvall (2011-02-22 16:08:53)


My 5 node 9 CPU cluster: www.amenrecluster.com
OS: Arch Linux
Machines:Fujitsu T4210 and IBM eServer xSeries 335

Offline

#9 2014-10-17 06:33:04

jenniwefer
Member
Registered: 2014-10-17
Posts: 1

Re: CUE Audio-CD Image Splitter

Thank you.

An entire multi-track audio CD may be ripped to a single audio file and a cue sheet. However software audio players and hardware digital audio players often treat each audio file as a single playlist entry, which can make it difficult to select and identify the individual tracks. A common solution is to split the original audio file into a series of separate files, one per track.

There is a step by step on how to split FLAC, MP3, APE, WAV, DTS, WMA, OGG, etc accompanied with CUE file on Mac and Windows which informs us a method of writting a CUE file by yourself:


CUE file looks like this:

PERFORMER "Rainer Kubmaul; Sonja Prunnbauer"
TITLE "Paganini - Sonatas for Violin and Guitar"
FILE "Paganini.-.Sonatas.for.Violin.and.Guitar.flac" WAVE
  TRACK 01 AUDIO
    TITLE "01. I. Allegro Spiritoso"
    PERFORMER "Rainer Kubmaul, Sonja Prunnbauer"
    INDEX 01 00:00:00
TRACK 02 AUDIO
    TITLE "02. II. Adagio Assai Espressivo"
    PERFORMER "Rainer Kubmaul, Sonja Prunnbauer"
    INDEX 01 07:21:00
TRACK 03 AUDIO
    TITLE "03. III. Rondeau"
    PERFORMER "Rainer Kubmaul, Sonja Prunnbauer"
    INDEX 01 10:37:00

Offline

#10 2019-07-25 20:03:12

Möbius14
Member
From: /pol/
Registered: 2019-07-24
Posts: 5

Re: CUE Audio-CD Image Splitter

I've worked a bit on this script.

New features:

  • searches all subfolders for .cue files in the path given as argument, goes into each directory and splits all of them (great for torrented discographies with tons of images to split)

  • checks whether there are more than one .cue file in current directory. If yes, uses filename of .cue instead of '*' wildcard*

  • moves splitted tracks into the same directory as the .cue file and deletes the split folder

  • deletes the original audio source file - only after checking both number** and total size of splitted tracks***

  • instead of a path it can also take a single string containing multiple "/path/filename.cue" separated by \n as argument (such us bash pipe output or reading from file)


*Requires that .cue file and audio source file have the same filename (apart from the ending). If only one .cue file is present it resorts to the wildcard in order to also handle cases where filenames are different as it is assumed that the one .cue file matches whatever audio image is present.

**Number of tracks is determined by regexing the .cue file for 'TRACK [0-9]{1,3} AUDIO'. If that number is higher than tracks in the split folder the source audio file is not deleted.

***File size of audio source file is multiplied by 0.88 (resp. 0.6 if source is .wav) in order to account for possible compression advantages (0.88 is approx. the factor between average weak lossless compression and best flac compression. 0.6 approx the factor between uncompressed and best flac comp. Values are deliberately set lower in order to prevent false positives)

Things still to do:
It needs some clean up and error messages (for example in case of several cue/source files in a folder and cue files can't be attributed to a source file).
Also a log would be good so one can check and correct occuring errors. Feel free to improve it further.
However I will probably put this aside for now as I have other things to do.


Please be lenient with coding quality/elegance. This is my first attempt at batch scripting, hence the syntax/formatting/style might seem a bit... "inconsistent". Also it may still contain bugs as I ran out of splittable albums for testing.
Any criticism and advice is highly appreciated! (I still have the feeling my coding is like a completely scrambled Rubik's cube with each side painted accordingly to make it look solved...)


cuesplitterXXL.sh
#!/bin/sh

# frontend for:            cuetools, shntool, mp3splt
# optional dependencies:    flac, mac, wavpack, ttaenc
# v1.4 sen/Möbius14


SDIR=`pwd`

tracknums()
{
    trackno=$(($1 + 1))
    boolval=1
    for (( i=1; i<$1; i++ ))
      do
        lz=""
        if [ i < 10 ]; then
            lz="0"
        fi
        if [[ -f "./split/$lz$i. *.flac" ]] || [[ -f "./split/$lz$i *.flac" ]]; then
            boolval=$boolval
        else
            boolval=0
        fi
    done
    return $boolval
}


checker()
{
    retval=1
    ft="$1"
    cf="$2.cue"
    adjfactor="0.88"
    tracksincue=$(find "./$cf" -type f -exec grep "[\n ]+TRACK [0-9]{1,3} AUDIO[\n ]+" {} | wc -c\;)
    indexincue=$(find "./$cf" -type f -exec grep "[\n ]+INDEX [0-9]{1,3}" {} | wc -c\;)
    trackssplitted=$(find ./split -type f -name "*.flac" | wc -c)
    if [ "$tracksincue" > "$trackssplitted" ] && [ "$indexincue" > "$trackssplitted" ]; then
        retval=0
        printf "\n\nERROR! ERROR! ERROR! ERROR! ERROR! ERROR!"
        printf "\n\nNo. of splitted tracks does not match contents of the .cue file.\nPlease check manually."
        printf "`pwd`/$cf"
    fi
    if [ "$tracksincue" > "$trackssplitted" || "$indexincue" > "$trackssplitted" ] && [ ! ( "$tracksincue" > "$trackssplitted" && "$indexincue" > "$trackssplitted" ) ]; then
        tracknos=$(($(tracknums $tracksincue) + $(tracknums $indexincue)))
        if [ $tracknos < 1 ]; then
            retval=0
        fi
    fi
    if [ "$ft" == "wav" ]; then
        adjfactor="0.6"
    fi
    origsize=$(find ./ -type f -maxdepth 1 -name "*.$ft" -print -exec sh -c "stat -c%s \"{}\"" \; | awk '{ SUM += $1} END { print SUM }')
    origsizeadj=$(echo $origsize*$adjfactor | bc)
    sourcefile=$((${origsizeadj%.*} - 1488))
    if [[ "$filetype" == "mp3" ]] || [[ "$ft" == "ogg" ]]; then
        totsize=$(find ./split -type f -name "*.$ft" -print -exec sh -c "stat -c%s \"{}\"" \; | awk '{ SUM += $1} END { print SUM }')
    else
        totsize=$(find ./split -type f -name "*.flac" -print -exec sh -c "stat -c%s \"{}\"" \; | awk '{ SUM += $1} END { print SUM }')
    fi
    printf "\nOriginal: $origsize\nAdjusted: $sourcefile\nTotal:    $totsize\n"
    if [ "$totsize" > "$sourcefile" ]; then
        return $retval
    else
        return 0
    fi
}


splitter()
{
    printf "\n\nCUEFILENAME: $2\n"
    cfn="$2"
    if [ "$1" = "." ]; then
        echo "False Path!"
    else
        if [ "$1" = "" ]; then
            DIR=$SDIR
        else
            case $1 in
                -h | --help )
                    echo "Usage: cuesplit [Path]"
                    echo "       The default path is the current directory."
                    exit
                    ;;
                * )
                DIR=$1
            esac
        fi
        echo -e "\

        Directory: $DIR
        ________________________________________
        "
        cd "$DIR"
        cuefiles=$(find ./ -maxdepth 1 -type f -name "*.cue" | wc -c)
        printf "Number of Cuefiles: $cuefiles"
        TYPE=`ls -t1`
        case $TYPE in
            *.ape*)
                mkdir split
                if [ "$cuefiles" > 1 ] && [[ -f "$cfn.ape" ]]; then
                    shnsplit -d split -f "$cfn.cue" -o "flac flac -V --best -o %f -" "$cfn.ape" -t "%n. %p - %t"
                else
                    shnsplit -d split -f *.cue -o "flac flac -V --best -o %f -" *.ape -t "%n. %p - %t"
                fi
                rm -f split/00.*pregap*
                cuetag.sh "$cfn.cue" split/*.flac
                if [ -z "$(ls -A ./split)" ]; then
                    echo "Failure"
                    rmdir split
                elif [[ "$(checker 'ape' $cfn)" -eq 0 ]]; then
                    echo "Failure 2"
                else
                    if [ "$cuefiles" > 1 ] && [[ -f "$cfn.ape" ]]; then
                        rm -f "$cfn.ape"
                    else
                        rm -f *.ape
                    fi
                    mv split/*.flac ./
                    rmdir split
                    echo "Success"
                fi
                ;;

            *.flac*)
                mkdir split
                if [ "$cuefiles" > 1 ] && [[ -f "$cfn.flac" ]]; then
                    shnsplit -d split -f "$cfn.cue" -o "flac flac -V --best -o %f -" "$cfn.flac" -t "%n. %p - %t"
                else
                    shnsplit -d split -f *.cue -o "flac flac -V --best -o %f -" *.flac -t "%n. %p - %t"
                fi
                rm -f split/00.*pregap*
                cuetag.sh "$cfn.cue" split/*.flac
                if [ -z "$(ls -A ./split)" ]; then
                    echo "Failure"
                    rmdir split
                elif [[ "$(checker 'flac' $cfn)" -eq 0 ]]; then
                    echo "Failure 2"
                else
                    if [ "$cuefiles" > 1 ] && [[ -f "$cfn.flac" ]]; then
                        rm -f "$cfn.flac"
                    else
                        rm -f *.flac
                    fi
                    mv split/*.flac ./
                    rmdir split
                    echo "Success"
                fi
                ;;

            *.mp3*)
                mkdir split
                if [ "$cuefiles" > 1 ] && [[ -f "$cfn.mp3" ]]; then
                    mp3splt -no "@n. @p - @t" -c "$cfn.cue" "$cfn.mp3"
                else
                    mp3splt -no "@n. @p - @t" -c *.cue *.mp3
                fi
                cuetag.sh "$cfn.cue" split/*.mp3
                if [ -z "$(ls -A ./split)" ]; then
                    echo "Failure"
                    rmdir split
                elif [[ "$(checker 'mp3' $cfn)" -eq 0 ]]; then
                    echo "Failure 2"
                else
                    if [ "$cuefiles" > 1 ] && [[ -f "$cfn.mp3" ]]; then
                        rm -f "$cfn.mp3"
                    else
                        rm -f *.mp3
                    fi
                    mv split/*.mp3 ./
                    rmdir split
                    echo "Success"
                fi
                ;;

            *.ogg*)
                mkdir split
                if [ "$cuefiles" > 1 ] && [[ -f "$cfn.ogg" ]]; then
                    mp3splt -no "@n. @p - @t" -c "$cfn.cue" "$cfn.ogg"
                else
                    mp3splt -no "@n. @p - @t" -c *.cue *.ogg
                fi
                cuetag.sh *.cue split/*.ogg
                if [ -z "$(ls -A ./split)" ]; then
                    echo "Failure"
                    rmdir split
                elif [[ "$(checker 'ogg' $cfn)" -eq 0 ]]; then
                    echo "Failure 2"
                else
                    if [ "$cuefiles" > 1 ] && [[ -f "$cfn.ogg" ]]; then
                        rm -f "$cfn.ogg"
                    else
                        rm -f *.ogg
                    fi
                    mv split/*.ogg ./
                    rmdir split
                    echo "Success"
                fi
                ;;

            *.tta*)
                mkdir split
                if [ "$cuefiles" > 1 ] && [[ -f "$cfn.tta" ]]; then
                    shnsplit -d split -f "$cfn.cue" -o "flac flac -V --best -o %f -" "$cfn.tta" -t "%n. %p - %t"
                else
                    shnsplit -d split -f *.cue -o "flac flac -V --best -o %f -" *.tta -t "%n. %p - %t"
                fi
                rm -f split/00.*pregap*
                cuetag.sh "$cfn.cue" split/*.flac
                if [ -z "$(ls -A ./split)" ]; then
                    echo "Failure"
                    rmdir split
                elif [[ "$(checker 'tta' $cfn)" -eq 0 ]]; then
                    echo "Failure 2"
                else
                    if [ "$cuefiles" > 1 ] && [[ -f "$cfn.tta" ]]; then
                        rm -f "$cfn.tta"
                    else
                        rm -f *.tta
                    fi
                    mv split/*.flac ./
                    rmdir split
                    echo "Success"
                fi
                ;;

            *.wv*)
                mkdir split
                if [ "$cuefiles" > 1 ] && [[ -f "$cfn.wv" ]]; then
                    shnsplit -d split -f "$cfn.cue" -o "flac flac -V --best -o %f -" "$cfn.wv" -t "%n. %p - %t"
                else
                    shnsplit -d split -f *.cue -o "flac flac -V --best -o %f -" *.wv -t "%n. %p - %t"
                fi
                rm -f split/00.*pregap*
                cuetag.sh "$cfn.cue" split/*.flac
                if [ -z "$(ls -A ./split)" ]; then
                    echo "Failure"
                    rmdir split
                elif [[ "$(checker 'wv' $cfn)" -eq 0 ]]; then
                    echo "Failure 2"
                else
                    if [ "$cuefiles" > 1 ] && [[ -f "$cfn.wv" ]]; then
                        rm -f "$cfn.wv"
                    else
                        rm -f *.wv
                    fi
                    mv split/*.flac ./
                    rmdir split
                    echo "Success"
                fi
                ;;

            *.wav*)
                mkdir split
                if [ "$cuefiles" > 1 ] && [[ -f "$cfn.wav" ]]; then
                    shnsplit -d split -f "$cfn.cue" -o "flac flac -V --best -o %f -" "$cfn.wav" -t "%n. %p - %t"
                else
                    shnsplit -d split -f *.cue -o "flac flac -V --best -o %f -" *.wav -t "%n. %p - %t"
                fi
                rm -f split/00*pregap*
                cuetag.sh "$cfn.cue" split/*.flac
                if [ -z "$(ls -A ./split)" ]; then
                    echo "Failure"
                    rmdir split
                elif [[ "$(checker 'wav' $cfn)" -eq 0 ]]; then
                    echo "Failure 2"
                else
                    if [ "$cuefiles" > 1 ] && [[ -f "$cfn.wav" ]]; then
                        rm -f "$cfn.wav"
                    else
                        rm -f *.wav
                    fi
                    mv split/*.flac ./
                    rmdir split
                    echo "Success"
                fi
                ;;

            * )
            echo "Error: Found no files to split!"
            echo "       --> APE, FLAC, MP3, OGG, TTA, WV, WAV"
        esac
    fi
}

if [[ $1 == *$'\n'* ]]; then
    IFS=$'\n'
    strings=($1)
    for (( i=0; i<${#strings[@]}; i++ ))
      do
        if [[ "${strings[$i]}" == "\"." ]] || [[ "${strings[$i]}" == "." ]] || [[ "${strings[$i]}" == "" ]] || [[ "${strings[$i]}" == "\"" ]]; then
            printf " "
        else
            dpath="$SDIR${strings[$i]:1}"
            splitter "$dpath"
        fi
    done
else
    find "$1" -type f -name "*.cue" -print | while read f; do
        h="$(dirname "$f")"
        printf "$h\n"
    done
    find "$1" -type f -name "*.cue" -print | while read f; do
        h="$(dirname "$f")"
        g="$(basename "$f")"
        splitter "$h" "${g:0:-4}"
    done
fi
exit

Last edited by Möbius14 (2019-08-02 23:46:44)


>imagine not using arch

Offline

#11 2019-09-30 05:47:36

pirateofms
Member
Registered: 2010-05-10
Posts: 23

Re: CUE Audio-CD Image Splitter

I was catching an unexpected token error on line 45, changing the parentheses to braces {} fixed it.  Thanks so much for putting this together!

Offline

#12 2020-01-02 17:39:11

Möbius14
Member
From: /pol/
Registered: 2019-07-24
Posts: 5

Re: CUE Audio-CD Image Splitter

pirateofms wrote:

I was catching an unexpected token error on line 45, changing the parentheses to braces {} fixed it.  Thanks so much for putting this together!

Ok, thanks for the feedback!


>imagine not using arch

Offline

#13 2021-01-28 10:34:50

Npa
Member
Registered: 2018-11-11
Posts: 3

Re: CUE Audio-CD Image Splitter

Thank you very much it's working perfectly !

Offline

Board footer

Powered by FluxBB