Home
July 2009   01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
megreen

Oggify (improved)

Posted on 2008.09.04 at 23:56
Aside from any argument over which audio file format is best (I like FOSS, thus ogg), I reworked my oggify script, attempting to implement what I learned from comments at [info]linux


#!/bin/bash

# convert mp3 and wav to ogg
# tonytraductor / http://www.BaldwinSoftware.com



echo -e "Oggify, at your service.\nOggify will convert all mp3 and wav files in this directory to ogg files, and REMOVE the old mp3 and wav files.\nFirst, it will make all file extensions lower case, and remove spaces from the file names.\n\nDo you wish to continue? (type y to continue)"

read ans

if [ $ans == y ]; then


echo "Removing spaces in names, and removing capitals from file extensions..."

##
# Note: Ubuntu users (possibly any deb based distro?) will have to alter the rename command to
# rename 's/\ /_/' *.(file extension)

# make extensions all lower case

for i in *.MP3
do
rename MP3 mp3 *.MP3
done


for i in .WAV
do
rename WAV wav *.WAV
done


# remove spaces in names

for i in .mp3
do
rename \ _ *.mp3
done

for i in *.wav
do
rename \ _ *.wav
done


echo "Converting mp3 files to wav..."

# converting all mp3 files to wav,
# so there will be nothing but wavs
# DELETING the mp3 files as soon as the wav is completed


for i in *.mp3
do

n=$i

echo "Converting $n to wav..."

mpg123 -w "$n.wav" "$n"

echo "Stripping mp3 extension from wav file name..."

rename .mp3. . $n.wav

echo "Removing mp3 file..."

rm $n

done


# and, now, converting those wav files to ogg
# DELETING wav files after oggs are created

echo "Converting wav files to ogg..."

for i in *.wav
do
n=$i
oggenc $n

echo "Ogg created, removing wav file..."

rm $n

done

# more clean up



echo -e "Your oggs are all fresh and toasty and ready to enjoy, friend.\nHappy Listening!"

exit

else

echo -e "Oh..okay...Ogg files are an excellent audio file format, though.\nYou can learn more about them at www.vorbis.com\nB'bye now..."

fi

exit

# This program was written by tony baldwin - tonytraductor@linguasos.org
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

Comments:


Matthew Caron
[info]mattcaron at 2008-09-09 13:54 (UTC) (Link)
<a href="http://www.mattcaron.net/linux/scripts/cd2ogg>this</a> may hold some interest to you.
Matthew Caron
[info]mattcaron at 2008-09-09 13:54 (UTC) (Link)
Err, that should be:

this may hold some interest to you.
tonytraductor
[info]tonytraductor at 2008-09-09 17:23 (UTC) (Link)
ok...
It's written in perl.
It retains the mega-tag data, but, I'm not quite sure I understand how (that information is in a text file, and the script will display the format of the file in response to "cdoogg -help", but where the text file came from is a mystery to me)...
Your rename commands look funny to me, because you use xubuntu.
(ubuntu, for all I know, any deb-based distro, have a different rename than pclos/mnadriva based distros, like mine).
You perform a number of rename functions to have sane file names, removing all _-_, __, ', etc.
Rips with cdparanoia and encodes with oggenc.
It looks for files at /dev/sdc (cdrom drive), and if it doesn't find them, it looks in the pwd (probably only encoding files?).
If there are <10 ten tracks, it starts labeling them with 0, but, if there are more, it does not.
I don't know what 'chomp' does.
Filenames, upon complete should look like:
01-grateful_dead-bertha.ogg
I think.
artist-no-title.ogg
but, what about album name?
01-moody_blues-the_story_of_the_moody_blues_legend_of_a_band-nights_in_white_satin.ogg
of course, that's a really long file name...
That file here is:
/mnt/storage/tunes/rock/moody_blues/the_story_of_the_moody_blues_legend_of_a_band/01_nights_in_white_satin.ogg
but that's how grip did it...
Maybe that's what your script is doing...
setting up the dir structure, then just naming the file
01-artist-title.ogg
is that it?

Hmmmm...
I need to learn perl.

Matthew Caron
[info]mattcaron at 2008-09-09 21:32 (UTC) (Link)
I made up the text file, and in fact it gets all the meta-tag data from that. Why? Well, I didn't like the typos and classifications from OTHER people which pollute online cd db's.

There actually aren't any rename commands - it uses the default output from the cd ripper and just determines what the output name should be. The correctname subroutine normalizes the name of the file based on the text of the track input. In this way, I can brainlessly type in what is on the CD jacket, or pull it from an online track list from the band's site.

chomp kills leading and trailing whitespace.

Aside from the above, you are correct.

The album is only used for ogg header info. Otherwise, it is discarded. The reason is because putting the album name in the file name leads to a very long name. Thus, I tend to just put the files in a directory named for the album, which is done manually.

Regular expressions are the most powerful thing in perl, hands down.
Previous Entry  Next Entry