You are not logged in.

#1 2009-09-03 08:39:41

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Got full-album-length ape/flac/tta files? Want split them? Here you go

Since MPD still doesn't support (external) cuesheets, I decided to split those full-album-length ape/flac/tta files into one song per file.

Here is a little script I've came up with just for this purpose.

It basically reads the cuesheet (if not specified, the one in the same dir with the big guy), splits the (decoded) big guy into little brothers and sisters, and encodes them to flac.
It also writes tags to the resulting flacs. ALBUM, ARTIST, TRACKNUMBER, and TITLE, that is.

#!/bin/bash

#requires:
#bchunk: split wav according to cue
#flac :     decode/encode flac
#mac:     if you want to decode ape
#ttaenc : if you want to decode tta

function help()
{
cat << HELP

==> A tool for splitting big ape|flac|tta into pieces
==> Needs a cuesheet, bchunk, and a little disk space

==> Output format can be: [flac]

Usage: `basename "$0"` [-c cuesheet] file

HELP
}

function fullpath()
{
    local DIR NAME
    DIR=$(cd "$(dirname "$1")" && pwd)
    NAME=$(basename "$1")
    echo "$DIR"/"$NAME"
}

SIG='bIgFaTfLaC' #unique, we don't want to kill the innocent
CUE=''
BIG=''

#options begin
OPT_TEMP=$( getopt --longoptions cue:,help --options c:h -- "$@" )
eval set -- "$OPT_TEMP"
while : ; do case "$1" in
    --cue|-c)    CUE=$(fullpath "$2") ; shift 2 ;;
    --help|-h)    help  ; exit 0 ;;
    --)        shift ; break  ;;
    *)        help  ; exit 1 ;;
esac ; done
#end options

BIG="$1"
if [ ! -f "$BIG" ] ; then help ; exit 1 ; else BIG=$(fullpath "$BIG") ; fi

DIR=$(dirname "$BIG") && cd "$DIR"
if [ "$?" -gt "0" ] ; then  echo "==> Can't enter working dir. Quit..." ; exit 1 ; fi

#make sure we work in a clean environment. we don't want to kill the innocent.
if [ -f "$SIG"* ] ; then echo "WTF? $SIG stolen?!" ; exit 1 ; fi

case "$BIG" in
    *.[Aa][Pp][Ee])
        mac "$BIG" "$SIG".wav -d ;;
    *.[Ff][Ll][Aa][Cc])
        flac -d -o "$SIG".wav "$BIG" ;;
    *.[Tt][Tt][Aa])
        ttaenc -d -o "$SIG".wav "$BIG" ;;
    *)    echo "==> Unsupported input. Quit..." ; exit 1 ;;
esac

if [ "$?" -gt "0" ] ; then  echo "==> Decoder required. Grab it and try again. Quit..." ; exit 1 ; fi

if [ -z "$CUE" ] ; then
    N_CUE=$(ls -1 *.cue | wc -l)
    if [ "$N_CUE" == "1" ] ; then CUE=$(ls *.cue)
    else
        echo "==> There are more than 1 cuesheets in the same dir."
        ls *.cue
        echo "==> Use -c option to specify one. Quit..." ; exit 1
    fi
fi

bchunk -w "$SIG".wav "$CUE" "$SIG"

IFS='
'
TITLES=($(grep 'TITLE' "$CUE" | cut -d\" -f2))
ARTISTS=($(grep 'PERFORMER' "$CUE" | cut -d\" -f2))
ALBUM="${TITLES[0]}"
N_TRACK="${#TITLES[@]}"
unset IFS

for ((N=1 ; N < N_TRACK ; N++)) ; do
    NN=$(printf '%.2d' $N)
    flac  -T "TRACKNUMBER=$NN" -T "ARTIST=${ARTISTS[$N]}" \
          -T "ALBUM=${ALBUM}"  -T "TITLE=${TITLES[$N]}" \
                 -o "$NN. ${TITLES[$N]}".flac "$SIG"$NN.wav
          #GENRE? YEAR? DATE? no, keep it simple. You can do the tag stuff later anyway.
done

#cleanup
rm -f "$SIG"*.wav

But there are several things I'd like to ask/point out:

1. cuesheets are not always encoded in utf8, which means it might get read incorrectly. iconv is great at charset conversion, but you must specify the input encoding yourself. Is there a way to automate input encoding detection, so all this charset conversion becomes painless? AFAIK, enca needs a language option and file doesn't always give you the right answer. If this automation can't be achieved, you'll have to check if the cuesheet is read correctly under your locale.

2. The script is based on my cuesheet format assumption. I don't know how a cuesheet can differ from others. But I used this template below. If I missed something, please let me know.

CATALOG 4988017622131

PERFORMER "Avril Lavigne"

TITLE "Under My Skin"

FILE "CDImage.ape" WAVE

  TRACK 01 AUDIO

    TITLE "Take Me Away"

    PERFORMER "Avril Lavigne"

    ISRC USAR10400373

    INDEX 01 00:00:00

  TRACK 02 AUDIO

    TITLE "Together"

    PERFORMER "Avril Lavigne"

    ISRC USAR10400483

    INDEX 01 02:57:45

  TRACK 03 AUDIO

    TITLE "Don't Tell Me"

    PERFORMER "Avril Lavigne"

    ISRC USAR10400119

    INDEX 01 06:12:17

  TRACK 04 AUDIO

    TITLE "He Wasn't"

    PERFORMER "Avril Lavigne"

    ISRC USAR10400484

    INDEX 01 09:34:18

  TRACK 05 AUDIO

    TITLE "How Does It Feel"

    PERFORMER "Avril Lavigne"

    ISRC USAR10400485

    INDEX 00 12:33:45

    INDEX 01 12:34:01

  TRACK 06 AUDIO

    TITLE "My Happy Ending"

    PERFORMER "Avril Lavigne"

    ISRC USAR10400486

    INDEX 01 16:18:71

  TRACK 07 AUDIO

    TITLE "Nobody's Home"

    PERFORMER "Avril Lavigne"

    ISRC USAR10400487

    INDEX 01 20:21:27

  TRACK 08 AUDIO

    TITLE "Forgotten"

    PERFORMER "Avril Lavigne"

    ISRC USAR10400488

    INDEX 01 23:53:58

  TRACK 09 AUDIO

    TITLE "Who Knows"

    PERFORMER "Avril Lavigne"

    ISRC USAR10400489

    INDEX 01 27:11:12

  TRACK 10 AUDIO

    TITLE "Fall To Pieces"

    PERFORMER "Avril Lavigne"

    ISRC USAR10400490

    INDEX 01 30:40:60

  TRACK 11 AUDIO

    TITLE "Freak Out"

    PERFORMER "Avril Lavigne"

    ISRC USAR10400491

    INDEX 01 34:09:36

  TRACK 12 AUDIO

    TITLE "Slipped Away"

    PERFORMER "Avril Lavigne"

    ISRC USAR10400492

    INDEX 00 37:21:31

    INDEX 01 37:22:58

  TRACK 13 AUDIO

    TITLE "I Always Get What I Want"

    PERFORMER "Avril Lavigne"

    ISRC USAR10400371

    INDEX 00 40:56:65

    INDEX 01 40:57:25

  TRACK 14 AUDIO

    TITLE "Nobody's Home (LIVE Acoustic)"

    PERFORMER "Avril Lavigne"

    ISRC USAR10400380

    INDEX 00 43:28:54

    INDEX 01 43:30:50

# The 1st and 4th line, as well as all the ISRC lines are omitted.

3. Output format can be easily enhanced. ogg, mp3, aac, or whatever you like. But I just like it simple.

4. Well, I do know about shntool and cue2tracks, but never got them working properly... Guess I'm just too lazy to try them out.

Please help me to improve this. smile

Last edited by lolilolicon (2009-09-03 09:43:03)


This silver ladybug at line 28...

Offline

#2 2009-09-03 11:40:44

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Got full-album-length ape/flac/tta files? Want split them? Here you go

I think multiple performers are possible per track and most just have the performer at the top.

Don't forget to support files that are already .wav

cue2tracks is also a bash script by the way, you could look at that, or just use that... I use this command: cue2tracks -c mp3 -Q 0 -B 320 -M V -o '%n %t' -R utf.cue

If it complains about the shell (it does in zsh even though it is called with #!/bin/bash) just remove that line.

Offline

#3 2009-12-27 17:39:04

PhotonX
Member
From: Munich
Registered: 2008-08-10
Posts: 591

Re: Got full-album-length ape/flac/tta files? Want split them? Here you go

Thanks for your script! Just searched for a piece of software that would split an ape file into some mp3's and that was exactlay what it did (with a little mp3 tweak). smile


Desktop: http://www.sysprofile.de/id15562, Arch Linux    |    Notebook: Thinkpad L13 Yoga Gen2, Manjaro

The very worst thing you can do with free software is to download it, see that it doesn't work for some reason, leave it, and tell your friends that it doesn't work.  -  Tuomas Lukka

Offline

#4 2009-12-27 19:54:03

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: Got full-album-length ape/flac/tta files? Want split them? Here you go

lolilolicon, could you post a picture of yourself?  I'm gonna hang it on the wall smile.


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#5 2010-01-08 19:35:01

RobF
Member
Registered: 2006-10-10
Posts: 157

Re: Got full-album-length ape/flac/tta files? Want split them? Here you go

Many thanks!  This script works well as is.  How can I adapt it so that the single track files are put out in mp3 format?  The lame setting -V2 (I think that's vbr around 192 kbps) would be fine for me.  I tried to adapt it by modifying one section as follows (flac -> lame and flac -> mp3):

for ((N=1 ; N < N_TRACK ; N++)) ; do
    NN=$(printf '%.2d' $N)
    lame  -T "TRACKNUMBER=$NN" -T "ARTIST=${ARTISTS[$N]}" \
          -T "ALBUM=${ALBUM}"  -T "TITLE=${TITLES[$N]}" \
                 -o "$NN. ${TITLES[$N]}".mp3 "$SIG"$NN.wav
          #GENRE? YEAR? DATE? no, keep it simple. You can do the tag stuff later anyway.
done

but when the script got to converting the single track wav files, it balked with "lame: excess arg ALBUM=Folksongs" and when I removed  -T "ALBUM=${ALBUM}" it balked with "lame: excess arg TITLE=Sopra l'aqua ... " etc.

Offline

#6 2010-01-09 08:00:49

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: Got full-album-length ape/flac/tta files? Want split them? Here you go

You need to honor the lame syntax.

for ((N=1 ; N < N_TRACK ; N++)) ; do
    NN=$(printf '%.2d' $N)
    lame  --tn $NN --ta "${ARTISTS[$N]}" \
          --tl "${ALBUM}"  --tt "${TITLES[$N]}" \
                 "$SIG"$NN.wav "$NN. ${TITLES[$N]}".mp3 
done

e
Man you really should read man pages. `ID3 tag options' section from `man 1 lame' explains it all.

I'm glad this script helps.


This silver ladybug at line 28...

Offline

#7 2010-01-09 14:47:09

RobF
Member
Registered: 2006-10-10
Posts: 157

Re: Got full-album-length ape/flac/tta files? Want split them? Here you go

Thanks!  The adapted script works great for splitting albums to single-track mp3 files.

Offline

Board footer

Powered by FluxBB