Shell Scripts, ID3 Tags, and a lot of free time

September 10, 2006 at 12:53 am 3 comments

Today I spent all day writing a shell script to take 42 bzip compressed .wav files and encode them to mp3, ogg, and flac. Not only does it convert the files, but it also set the tags for the files too. My favorite part is being able to set the file names, title and track number tags based on splicing a config file.

If anyone’s interested in something like this let me know. It would be great if someone else can get some use out of it too.

Advertisements

Entry filed under: Linux. Tags: , , , .

Slackware 11 It’s Slack Time!

3 Comments Add your own

  • 1. Mason Browne  |  November 16, 2006 at 8:56 am

    Hmm… are you able to splice audio samples as well? Think you could shoot me an email? I’d like to be able to run through a directory and take 30 second samples of mp3s, fading in and out. If you have any idea as to go about this, I’d be ever-so-grateful.

    Reply
  • 2. WK  |  December 8, 2006 at 4:08 am

    I’d be interested in that script. Specifically, I’m looking for a command line program to convert CD Audio to flac. I’ve seen grip, but I figure I can do it with flac (w/o external programs). Haven’t figured it out yet.

    This post is #1 search result for “flac cli tutorial”.

    Reply
  • 3. dosnlinux  |  December 9, 2006 at 12:30 am

    Wow! My blog must be getting more attention than I thought! I guess I better write up a proper FLAC cli tutorial in the near future. 😉

    I’ve never tried to encode the files from a CD before, but I imagine it would look something like

    flac /path/to/cd/trackXY.cda -o trackXY.flac

    Here’s the FLAC part of my script, hopefully you can get some tips from it.


    # /bin/bash

    # process flac files

    #title
    album="Megaman X Command Mission"
    #tracknumber
    artist="Capcom Sound Team"
    copywrite="2004 Capcom Entertainment, Inc."
    genre="Video Game"
    date="2004"

    genorateFlacPlaylist()
    {
    # generate a playlist of flac files
    echo '#EXTM3U' > flac/mmxcm-flac.m3u
    ls flac/*.flac >> flac/mmxcm-flac.m3u
    }

    renameFlac()
    {
    # rename all files just in case they don't match
    for i in flac/*
    do
    file=`echo $i | sed 's/^flac\///'`
    tracknumber=`echo $file | cut -d '-' -f1`
    nameLine=`grep $tracknumber mmxcm-titles`
    title=`echo "$nameLine" | cut -f2 | tr [:upper:] [:lower:] | sed 's/ /_/g'`
    filename="${tracknumber}-${title}.flac"
    vfatFilename=`echo $filename | sed -n 's/[^A-Za-z0-9\._-]//gp'`
    mv $i flac/$vfatFilename
    done
    }

    removeFlacTags()
    {
    # remove all flac tags
    for i in flac/*
    do
    metaflac --dont-use-padding --remove-all-tags $i
    done
    }

    tagFlac()
    {
    # tag newly created flac files
    removeFlacTags

    for i in flac/*
    do
    file=`echo $i | sed 's/^flac\///'`
    tracknumber=`echo $file | cut -d '-' -f1`
    title=`grep $tracknumber mmxcm-titles | cut -d " " -f2`

    metaflac --dont-use-padding \
    --set-tag="TITLE=$title" \
    --set-tag="ALBUM=$album" \
    --set-tag="TRACKNUMBER=$tracknumber" \
    --set-tag="ARTIST=$artist" \
    --set-tag="COPYWRITE=$copywrite" \
    --set-tag="GENRE=$genre" \
    --set-tag="DATE=$date" $i
    done
    }

    encodeFlac()
    {
    # encode files as flac
    for i in wav/*
    do
    if [ ! -d flac ]
    then
    mkdir flac
    fi

    bzcat $i | flac --best - -o `echo $i| sed 's/wav\//flac\//' | sed 's/\..*/.flac/'`
    done
    }

    encodeFlac
    tagFlac
    renameFlac
    genorateFlacPlaylist

    If you need some help with understanding some of it, or still need some general help, feel free to email me at bzqwerty ([at symbol]) gmail [{dot}] com

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Feeds


%d bloggers like this: