Splitting FLAC files by cue sheet

This post consists of two things, "FLAC" and "cue sheets".

As for FLAC you can refer to this or this post. Ofcourse those are not a technical overview, they are just my opinion and impression and you can find more on the web.

As for CUE sheets and the need for them, sometimes you get a whole album as a single mp3 or FLAC file and you can't rewind to the start of the song you want. That's where CUE sheets come to the rescue. CUE sheets are a description of the file, every song has (title, singer, ...) and where it starts and ends.

So what i needed was to split the FLAC(or an mp3) file using the CUE sheet(if exists). Was it an easy task?! On Linux :) it was. Please find the bash script below which does this task given the folder path and the cue sheet file path.

#!/bin/bash
echo "split flac by cue sheets"
echo "Cue sheet file path: "
read cuesheet
echo "FLAC file path: "
read srcfile

# split files by the cuesheet
cuebreakpoints "$cuesheet" | shnsplit -o flac "$srcfile"
# import the tags from the cue sheet to the generated files
cuetag "$cuesheet" split-track*.flac

for file in *.flac ; do
# Get file index from file name
index=${file##split-track}
index=${index%.flac}

# Get Song title from tags
title=$(metaflac --show-tag=TITLE "$file")
title=${title##TITLE}
title=${title##=}

# Change file name
newfilename="$index - $title".flac
echo "Added : $newfilename"
mv $file "$newfilename"
done
I am thinking of posting some scripts that i make and find useful every now and them. Hope they help :)

Comments