Howto: split a flac track from its cue file

jan 3rd, 2010 by Mushiro in Musique, linux

It happens from time to time that I’ve got a music album in Flac format, in one file, with a cue sheet file. Don’t ask me where it comes from :roll: .

As my main (and only) OS at the moment is Ubuntu, and that the number of music players supporting cue files are very very limited, I have to split the unique file to multiple files, with the correct filenames and tags.

I found two sites explaining how to do that ( here, and here), and I merely merge the two articles here for archiving purpose.

(Road2Mayotte has translated the howto in french)

The name of the album I use for this howto is « MINAMOTRANCE CORE BREAK! ».

1. Splitting the file

As we will see later, it’s best to rename the cue file to a file with no space in it:

$ cp MINAMOTRANCE\ CORE\ BREAK\!.cue cue.cue

You will need the following applications: cuebreakpoints, cuetag (in cuetools package) and shnsplit (shntool package). Now let’s split it!

$ cuebreakpoints cue.cue | shnsplit -o flac MINAMOTRANCE\ CORE\ BREAK\!.flac

Something like this will be output:

Splitting [MINAMOTRANCE CORE BREAK!.flac] (52:46.37) --> [split-track01.flac] (0:44.50) : 100% OK
Splitting [MINAMOTRANCE CORE BREAK!.flac] (52:46.37) --> [split-track02.flac] (4:57.25) : 100% OK
Splitting [MINAMOTRANCE CORE BREAK!.flac] (52:46.37) --> [split-track03.flac] (5:22.00) : 100% OK
Splitting [MINAMOTRANCE CORE BREAK!.flac] (52:46.37) --> [split-track04.flac] (5:22.00) : 100% OK
......

Ok, now we have flac files named split-track01.flac, split-track02.flac…

2. Transferring the tags

How about transferring the tags (ARTIST, TITLE…) from the cue file to the flac files? We do this by using the cuetag command (this command doesn’t support filenames with spaces, that’s why we renamed the cue file earlier):

$ cuetag cue.cue split-track*.flac

You can check that the tags have been correctly set. Run for example:

$ metaflac split-track02.flac --show-tag=TITLE

and the title tag will be printed:

TITLE=Party Like Us!

3. Renaming the files

Well, all that is left is to rename the files. We extract some tags from the files, and rename them. Here is a bash script to do this (save it in a file named rename_flac.sh, and chmod a+x on it):

#!/bin/bash

for a in *.flac; do
ARTIST=`metaflac "$a" --show-tag=ARTIST | sed s/.*=//g | sed s#/#-#g`
TITLE=`metaflac "$a" --show-tag=TITLE | sed s/.*=//g | sed s#/#-#g`
TRACKNUMBER=`metaflac "$a" --show-tag=TRACKNUMBER | sed s/.*=//g`
mv "$a" "`printf %02g $TRACKNUMBER` - $ARTIST - $TITLE.flac"
done

Then in the directory with the flac files (change the path to where you saved the script):

$ ~/bin/rename_flac.sh
$ ls
01 - 源屋 - Intro.flac
02 - 源屋 - Party Like Us!.flac
....

Enjoy the music!

1 Comment