Script — Transencode flac to ogg in Linux automated

The following script will trans encode FLAC to OGG preserving all tags and original files.
My way I don’t care about other tools!
Read the comments..
No i will not edit this for “your” needs
No i don’t care what happens to your system
Yes I will take constructive feedback!
You will need to scroll across the code block. I can not seem to make it wider right now.

Requires command line parmiters in the following format :-
# ./flac2ogg.sh
No Source Dir given
Please specify the full path to the source flac files

ALL CODE GPLv3

#!/bin/bash
#
# Desc :- Script will convert flac to ogg
#         Will pull flac tags into ogg tags
# Version :- 1.0.0
# Date :- 16-01-09
# Author :- undersys@undersys.net
# Dependencies :- libogg-1.1.3, libvorbis-1.2.1_rc1-r2(aotuv), vorbis-tools-1.2.0-r2,
#

# -------------------
# Set Global Config
# -------------------
#
# Only change three settings below
#

# Set the base dir to move oggs to, artist and album structure will be build under this
BASEDIR=/store/ogg

# Set oggenc path
OGGENC=/usr/bin/oggenc

# Set group to own files/folders
REALGRP=users

# -------------------
# End Global Config
# -------------------

# -------------------
# Set Global Vars
# -------------------

# Must check for valid input first, befour we set any Global Vars
if [[ -z $1 ]]; then
        echo No Source Dir given
        echo Please specify the full path to the source flac files
        exit
fi

# Find real user and not su root this is the user who owns the files at the end
#REALUSR=`who | awk -F" " '{print $1}' | awk '{sub(/[ \t]+$/, "");print}' | awk 'NR>1{exit};1'`
REALUSR=samba

# Find total coloums in input path
MAXCOL=`echo $1 | awk -F/ '{print NF}'`

# Select Album coloum
ALCOL=$(($MAXCOL - 1))

# Selet Artist coloum
ARCOL=$(($MAXCOL - 2))

# Select artist name from full path
ARTIST=`echo $1 | awk -F/ '{print $v1}' v1=$ARCOL`

# Select album name from full path
ALBUM=`echo $1 | awk -F/ '{print $v1}' v1=$ALCOL`

# Set source dir from input
SOURCEDIR=$1

# ------------------
# End Global Vars
# ------------------

# --------------------
# Start Function Block
# --------------------

function cdir {
        if [[ -d $BASEDIR/$ARTIST/$ALBUM ]]; then
                echo This Album Has been encoded
                echo Script will now exit
                exit
        fi

        mkdir -p $BASEDIR/$ARTIST/$ALBUM
        }

function transcode {
        $OGGENC -q7 $SOURCEDIR/*.flac
        }

function mvogg {
        mv $SOURCEDIR/*.ogg $BASEDIR/$ARTIST/$ALBUM
        }

function setperms {
        chown -R "$REALUSR:$REALGRP" $BASEDIR/$ARTIST/$ALBUM
        chmod -R 774 $BASEDIR/$ARTIST/$ALBUM
        }

# --------------------
# End Function Block
# --------------------

# --------------------
# main section
# --------------------

cdir
transcode
mvogg
setperms

exit

# --------------------
# End main section
# --------------------

# -------------------
# End Script
# -------------------
Advertisements

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

%d bloggers like this: