ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I wrote this script to convert flac/shn to mp3's and rename them according to the setlist often given in the accompanying txt file. I know this can be improved but it works for me. I also wrote scripts to check the md5 and/or ffp files, another one to convert flac/shn to wav, rename as above, copy over in alpha-numeric-timestamp order to a usb stick so they'll play in my car radio in the correct order. Oh and one to convert 24bit flac to 16bit... Any way here is my mp3 script, give it a whirl and let me know how it works for you.
Code:
#!/bin/bash
#f2mp3
# The intention of this script is to decode flac/shn files to a
# alpha-numericly renamed and tagged mp3 file as indicated by
# the setlist txt file that often is included in such file
# packages.
# Your original lossless directory and contents are left unchanged and will
# continue to pass md5sum.
# Srcipt assumes you are in root dir of the flac/shn files to be processed.
while getopts ":y:" opt; do
case $opt in
y ) year=$OPTARG
;;
esac
done
echo -e "\nPick the file that contains the setlist \n "
IFS=$'\n'
select file in $(find . -size -100k -type f)
do
txtfile=$(echo "$file"|sed 's/ /\./g') #substitute spaces for '.'
break
done
IFS=" "
# Define a regular expression that only describes the song titles in your
# txtfile the default, for instance, ^d[1-3]t[0-9]{2}, means every line that starts d1t01,
# d1t02, ....d3t09.
echo
read -e -p "Enter your RegEx. Default - Enter to accept or edit : " -i "^d[1-3]t[0-9]{2} " regex
read -e -p "Enter the Artist tag. Default -Enter to accept or edit : " -i "Grateful Dead" artist
#read -e -p "Enter the 'year of issue' tag :" year
#############################################################
#cleanup previous attempts
rm *wav 2>/dev/null
rm *mp3 -fr 2>/dev/null
mkdir mp3
#############################################################
a=1 #counter to choose txt file line for use in renaming
b=101 #track number
for i in *{shn,flac}
do
#if *shn or *flac doesn't exist goto next file in *{shn,flac}
[ -e "$i" ] || continue
#pick one line from txt file, call it "new" and use to rename wav file
new="$(sed -nr "/$regex/p" $txtfile |sed -e's/ - / /' -e's/\[.*\]//' \
-e's/[ ]*$//' -e's/\//-/g' -e's/:/-/' -e's/->//'\
-e's/[*#%-\r]//g' -e's/[ \t]*$//'|sed -n "$a"p)"
echo
#strip begining of line to first space then insert "$b" (track#) to front
new="$b$(echo $new | awk '{ $1 = "";print }')"
####################################################
# declare some tags for the mp3
tt=${new##$b } #titletag
ta=$artist #artist tag
tl=$(album=$(basename $PWD); echo "${album%.*}") #album tag
[ -e $year ] && ty=$year #year of issue tag
tn=$b #track number tag
tg=17 #genre tag - defaulted to "rock"
# convert flac or shn file to wav
shntool conv "$i"
echo
# convert wav file to mp3
lame --vbr-new --preset standard --tt "$tt" --ta "$ta" \
--tl "$tl" --ty "$ty" --tn "$tn" --tg "$tg" --add-id3v2 \
*wav "$new.mp3"
rm *wav
mv -v "$new.mp3" mp3/"$new.mp3"
((a++)) #get next txt file line number
((b++)) #get next track number
done
cp $txtfile mp3/
exit 0
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.