LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Bash Script to convert FLAC album to Ogg Vorbis (preserving tags) (https://www.linuxquestions.org/questions/linux-general-1/bash-script-to-convert-flac-album-to-ogg-vorbis-preserving-tags-772235/)

will177 11-29-2009 04:52 AM

Bash Script to convert FLAC album to Ogg Vorbis (preserving tags)
 
Hi,

I wrote this simple bash script that you might find useful if you have all your music stored in FLAC but wish to convert some of it to Ogg Vorbis for use on your mobile music player.

I call the script OggEncodeAFLACAlbum.sh

Here is the contents:


#!/bin/bash

if [ $# -lt 1 ]; then
echo " "
echo "Please supply artist/albumname as argument, e.g. abba/gold"
else
SRC_DIR=/music/flac/$1

if [ -d "$SRC_DIR" ]; then
echo " "
echo "Will Ogg encode the album $1 "
echo "from "
echo "$SRC_DIR"
echo "to "
DEST_DIR=/music/ogg/q6/$1
echo $DEST_DIR
echo " "
if [ -d "$DEST_DIR" ]; then
echo "Destination already exists, will do nothing."
else
echo "Ogg encoding album $1 please wait..."
mkdir -p $DEST_DIR
cd $SRC_DIR
for i in *.flac; do oggenc -q6 -o $DEST_DIR/${i%%flac}ogg $i; done
fi
else
echo "Source directory $SRC_DIR does not exist, doing nothing."
fi
fi

echo "Finished."


HTH someone.

SethsdadtheLinuxer 12-30-2009 08:57 AM

saving for study - never know when you'll find a good nugget of info.

Arancaytar 10-16-2012 12:33 PM

This is neat.

Note that spaces in the filenames will cause oggenc to complain about multiple files. Wrapping both the destination argument and the file argument in quotes will fix that.

Code:

for i in *.flac; do oggenc -q6 -o "$DEST_DIR/${i%%flac}ogg" "$i"; done


All times are GMT -5. The time now is 02:52 AM.