Many have been the cases when I've come across a single flac file of a whole cd, accompanied by its cue file.
My objective being to split the file to its individual tracks, rename accordingly and convert to mp3s, I made a script to do the job for me. I've found solutions for the tasks separately, but never on a single script.
1: Dependencies
The script uses cuetools and shntool to split the flac file. You'll need of course the flac package as well. So:
Code:
sudo apt-get install cuetools shntool flac
2: Script assumptions
The script supposes that it functions in a folder containing a log file, a cue file and a flac file.
3: The script
Code:
#!/bin/bash
rm *.log
c="`ls *.cue`"
f="`ls *.flac`"
#split flac according to cue
cuebreakpoints "$c"| shnsplit -o flac "$f"
#create a file - tt - with the songs' titles
sed '1,6'd "$c"|grep TITLE|sed 's/^.\{11\}//g'|sed 's/"//g'|sed 's/.$//'>tt
#rename flacs according to titles in tt
for i in {1..9}
do
j=`sed -n ''$i'p' tt`
echo $j
mv split-track0$i.flac 0$i-"$j".flac
done
for i in {10..99}
do
j=`sed -n ''$i'p' tt`
echo $j
mv split-track$i.flac $i-"$j".flac
done
#delete cue file, flac file, titles file
rm "$f" "$c" tt
#convert flacs to mp3s
for f in *.flac
do ffmpeg -i "$f" -acodec libmp3lame -ab 320k "${f%.flac}.mp3"
done
#delete flacs
rm *.flac
Firstly, it deletes the unnecessary log file.
It then splits the flac file according to the cue one.
A file called tt (dummy file) is created from the cue file with the tracks' titles.
The split flac files are renamed according to the titles in the dummy file.
The initial flac file, the cue file and the dummy file are deleted.
The flac files are converted to mp3s (320k).
The flac files are deleted, thus leaving only the mp3s in the folder.
Save it with whatever name you want, say flac_2_mp3s_320k, make it executable
Code:
chmod +x flac_2_mp3s_320k
paste it in your flac-cue folder and execute it.
WARNING: Come to think of it, better use it on a copy of the original folder, as the script erases everything.
Bookmarks