1/04/2010

Convert ape to mp3 in linux (Fedora) Eng

Convert ape to mp3 in linux (Fedora)
Once I received ape file and I wasn't able to listen it in my Linux. I tried to find something user friendly but all found staff was useless. But finally I got this script:

Download ape2.mp3.sh

ape2mp3.sh

#!/bin/bash
echo "Brian's Archive CUE/FLAC Splitter v0.1"
echo "No sanity checking in place. Be careful."

if [ $# != 2 ]
then
       echo ""
       echo "Usage:"
       echo "    $0 cue_file ape_flac_file"
       echo ""
       exit 1
fi

#Get the filenames
cuefile=$1
flacfile=$2

#Other variables
tracks=$(cueprint -d '%N' "$cuefile")

#Get the filenames into an array
count=1
while [ $count -le $tracks ]
do
       tracknames[$count]=$(cueprint -n$count -t '%p-%T-%02n-%t' "$cuefile"|sed -e s@/@,@g)
       count=`expr $count + 1`
done

#Load up the ID3 tag info into variables for later use
id3count=1
while [ $id3count -le $tracks ]
do
       artist[$id3count]=$(cueprint -n$id3count -t '%p' "$cuefile")
       album[$id3count]=$(cueprint -n$id3count -t '%T' "$cuefile")
       tracknum[$id3count]=$(cueprint -n$id3count -t '%02n' "$cuefile")
       title[$id3count]=$(cueprint -n$id3count -t '%t' "$cuefile")
       echo "Artist: ${artist[$id3count]}"
       echo "Album: ${album[$id3count]}"
       echo "Track No: ${tracknum[$id3count]}"
       echo "Song Title: ${title[$id3count]}"
       id3count=$[$id3count + 1]
done

#Output general file information
cueprint -d '%P - %Tn' "$cuefile"
echo "Total number of tracks: " $tracks

#Split this bitch
cuebreakpoints "$cuefile" | shntool split -a '' -n '%02d' -o wav "$flacfile"

#Convert those waves into mp3s
convertcount=1
while [ $convertcount -le $tracks ]
do
       wavenum=`printf "%02d" $convertcount`

       lame --add-id3v2 --noreplaygain -b 320 --ta "${artist[$convertcount]}" --tl "${album[$convertcount]}" --tn "${tracknum[$convertcount]}" --tt "${title[$convertcount]}" "$wavenum.wav" "${tracknames[$convertcount]}.mp3"
       rm "$wavenum.wav"
       convertcount=$[$convertcount + 1]

done

usage: # ape2mp3.sh album.cue album.ape

for correct work you need following packages:

1. mac - http://moonshine.freshrpms.net/rpm.html?id=193 for fedora 7
2. LAME - yum install lame (in fedora)
3. shorten - # rpm -ivh shorten-3.6.0-1.2.i386.rpm
4. shntool - # rpm -ivh shntool-3.0.6-1.i386.rpm
5. cuetools - # rpm -ivh cuetools-1.3.1-2.i386.rpm

No comments: