The following script will trans encode FLAC to OGG preserving all tags and original files.

You need the following libraries/tools :

  • libogg
  • libvorbis
  • vorbis-tools

Requires command line parameters in the following format :-

# ./flac2ogg.sh
No Source Dir given
Please specify the full path to the source flac files

The script :

#!/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
# -------------------