Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Thu Oct 02, 2008 2:33 am 
Offline
Senior Newbie

Joined: Fri Sep 19, 2008 8:12 pm
Posts: 6
Website: http://pshields.net
AOL: mercurylime
The goal: a script to decode a specified .flac file into a .mp3 and a .ogg. flac tags should be turned into id3 tags for the mp3.

1) Can you help explain some of the lines in this script: http://github.com/tacvbo/yaflac2mp3/tre ... lac2mp3.sh

Specifically,
Code:
${vars[${N_vars}]%=*}
${files[${N_files}]/\.flac/.mp3}


2) Is there a better way to do this? I'm planning on uploading the .flac files to the server via http and triggering the script somehow.

3) I've figured out that I need to become a master of the linux shell. Know of any good tutorials?


Top
   
PostPosted: Thu Oct 02, 2008 7:39 am 
Offline
Senior Member
User avatar

Joined: Mon Dec 10, 2007 4:30 pm
Posts: 341
Website: http://markwalling.org
iobright wrote:
I've figured out that I need to become a master of the linux shell. Know of any good tutorials?


http://tldp.org/LDP/abs/html/

http://linux.die.net/man/1/bash


Top
   
PostPosted: Thu Oct 02, 2008 9:09 am 
Offline
Senior Member

Joined: Thu Oct 02, 2008 8:56 am
Posts: 99
Hopefully it is of use to you.

Code:
#!/bin/bash
# flac2lame.sh

FLAC_DIR="$1"
[ -d "${FLAC_DIR}" ] || exit 1
pushd "${FLAC_DIR}"

# Change this to suit your compression needs. For most users,
# --preset standard is a good balance between filesize and quality.
# See the lame manpage for more details
COMPRESS_FLAG="--preset standard"

# stupid mp3 format screws up with UTF-8
TEMP_LANG=`echo $LANG |sed s?"\.UTF-8$"?""?`
export LANG=${TEMP_LANG}

for file in *.flac; do
    STUMP=`basename "$file" .flac`
    TRACKNUMBER=`metaflac --list "$file" |grep -i "TRACKNUMBER=" |cut -d"=" -f2`
    TITLE=`metaflac --list "$file" |grep -i "TITLE=" |cut -d"=" -f2`
    ARTIST=`metaflac --list "$file" |grep -i "ARTIST=" |cut -d"=" -f2`
    ALBUM=`metaflac --list "$file" |grep -i "ALBUM=" |cut -d"=" -f2`
    DATE=`metaflac --list "$file" |grep -i "DATE=" |cut -d"=" -f2`
    GENRE=`metaflac --list "$file" |grep -i "GENRE=" |cut -d"=" -f2`
    COMMENT="${file}: transcoded on `date +%F`, lame `lame --version |head -n 1 |cut -d\" \" -f3`"

    if [ "$GENRE" = "Inspirational" ]; then
        GENRE="Gospel"
    fi
    flac --decode "$file"
    lame ${COMPRESS_FLAG} --add-id3v2 \
        --tn "${TRACKNUMBER}" \
        --tt "${TITLE}" \
        --ta "${ARTIST}" \
        --tl "${ALBUM}" \
        --ty "${DATE}" \
        --tg "${GENRE}" \
        --tc "${COMMENT}"  "${STUMP}.wav" "${STUMP}.mp3"
    if [ $? -eq 0 ]; then
        rm -f "${STUMP}.wav"
    else
        echo "Transcode of $file encountered a problem"
    fi
done
popd


You put the flac files you want to transcode into a directory and give the directory as an argument to the script.

Note that lame is picky about valid ID3v2 genre - so if the genre in your flac isn't one lame recognizes, you may have to adjust the script - like I did for inspirational (so that lame sees it as gospel).


Top
   
 Post subject:
PostPosted: Thu Oct 02, 2008 2:12 pm 
Offline
Senior Newbie

Joined: Fri Sep 19, 2008 8:12 pm
Posts: 6
Website: http://pshields.net
AOL: mercurylime
Thanks guys. I've nearly got it working.

FunkyRes, what does "if [ $? -eq 0 ]" mean?

Also, if anyone can help me figure out how to correct this problem, that would be great. "$fname" is the name of the file (including the path.) "$fname.tags" is the name of the metadata file created by metaflac.

Error:
Code:
-bash: ${{$fname}.tags[${N_vars}]%=*}: bad substitution
-bash: $(echo "${{$fname}.tags[${N_vars}]%=*}" | tr [:upper:] [:lower:])=${{$fname}.tags[${N_vars}]#*=}: bad substitution


Relevant code:
Code:
 for N_vars in "$fname.tags"
  do
   export "$(echo "${{$fname}.tags[${N_vars}]%=*}" | tr [:upper:] [:lower:])=${{$fname}.tags[${N_vars}]#*=}"
  done


Top
   
 Post subject:
PostPosted: Thu Oct 02, 2008 4:25 pm 
Offline
Senior Member

Joined: Tue Jan 22, 2008 2:10 am
Posts: 103
For what it's worth, you don't need a script to convert to .ogg - just pass oggenc the .flac file and it'll automatically transcode and copy across tags.


Top
   
 Post subject:
PostPosted: Thu Oct 02, 2008 9:31 pm 
Offline
Senior Member

Joined: Thu Oct 02, 2008 8:56 am
Posts: 99
iobright wrote:
Thanks guys. I've nearly got it working.

FunkyRes, what does "if [ $? -eq 0 ]" mean?


$?

shows the return value of a command.

When a command is successful, it returns a value of 0.
When a command is not successful, it returns a value other than zero (often 1 but not always - the non zero return value sometimes helps you know where it failed)

run the following from a shell:

/bin/true
echo $?

You will see a 0.

/bin/false
echo $?

You will see a 1


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group