SCRIPT — Rip CD to Flac in Linux automated

The following script will rip a cd to FLAC. 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 parameters in the following format :-
# ./cd-rip.sh
No Album/Artist Name Given
Please specify in the following format
\”ALBUM Name\” \”ARTIST\”

ALL CODE GPLv3

#!/bin/bash
#
# Desc :- Script to rip Audio CD to FLAC
#         Will intert Artist and album tag
#         You must manualy insert filename
#         and all other tags
# Version :- 1.0.0
# Date :- 12-01-09
# Author :- undersys@undersys.net
# Dependencies :- flac-1.2.1-r3, cdparanoia-3.10.2-r2
#


# -------------------
# Set Global Config
# -------------------

# -- Only change the five entrys below --

# Device to read from
CDROM=/dev/hdc

# Base extraction directory, artist and ablum dirs will be placed under here
BASEDIR=/store/flac

# Set group to own files/folders
REALGRP=users

# cdparanoia binary location
CDPARANOIA=/usr/bin/cdparanoia

# flac binary location
FLAC=/usr/bin/flac

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



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

# -- Do not change any entrys below --

# Check for root user, must be root to run cdparanoia
ROOT=`whoami | awk -F" " '{print $1}' | awk '{sub(/[ \t]+$/, "");print}'`

# 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'`
REALUSER=samba
# Remove spaces from Album name
REPSPACE=`echo $1| tr ' ' '-'`

# Remove spaces from Artist name
REPSPACEB=`echo $2 | tr ' ' '-'`

# Set first user var to ALBUM
TALBUM=$1

# set second user var ARTIST
TARTIST=$2

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



# ---------------------
# Start Function blocks
# ---------------------

# Test for input args

function testargs {
        if [[ -z $TALBUM ]]; then
                echo No Album/Artist Name Given
                echo Please specify in the following format
                echo '"ALBUM Name"' '"ARTIST"'
                exit
        fi

        if [[ -z $TARTIST ]]; then
                echo No Album/Artist Name Given
                echo Please specify in the following format
                echo '"ALBUM Name"' '"ARTIST"'
                exit
        fi

        if [[ $ROOT != "root" ]]; then
               echo You must be root to run this script
               echo cdparanoia requires root
               exit
        fi
        }


# Create base directorys

function mdir {
        if [[ -d $BASEDIR/$REPSPACEB/$REPSPACE ]]; then
                echo You have ripped this CD
                exit
        fi

        cd $BASEDIR
        if [[ -d $REPSPACEB ]]; then
                cd $BASEDIR/$REPSPACEB
                mkdir $REPSPACE
        else
                mkdir $BASEDIR/$REPSPACEB
                mkdir $BASEDIR/$REPSPACEB/$REPSPACE
        fi
        }


# rip cd

function rip {
        cd $BASEDIR/$REPSPACEB/$REPSPACE
        $CDPARANOIA -l -v -B -z -d $CDROM
        }


# encode to flac

function encode {
        cd $BASEDIR/$REPSPACEB/$REPSPACE
        $FLAC -5 -V -T "ALBUM=$TALBUM" -T "ARTIST=$TARTIST" --sector-align --replay-gain --delete-input-file *.wav
        }


# rename logs

function rename {
        cd $BASEDIR/$REPSPACEB/$REPSPACE
        mv cdparanoia.log $REPSPACE.log
        }


# set ownership and permissions

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


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



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

testargs
mdir
rip
encode
rename
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: