rulururu

post MP3 to ogg, preserving tags

April 20th, 2008

Filed under: mac — zedr0n @ 2:51 pm

I personally don’t like all those insane 320kbit bitrates, I’m perfectly fine with listening to 80kbit ogg(which sounds like 128kbit mp3 occupying less space at the same time). As it’s impossible to convert from inside iTunes(oh, Foobar, where art thou?) I had to resort to command line tools. The tools we’ll need are

  • LAME - mp3 encoder
  • eggenc - ogg encoder(you’ll need to build libogg, libvorbis, vorbis-tools but it builds out-of-box)
  • id3tool - mp3 tag viewer(and editor) - also builds successfully
  • Grep and sed - text manipulators, powerful standard tools

Now the bash script which will convert all the supplied mp3 files to ogg(mp32ogg):

#!/bin/sh

for file in "$@"
do
    if test ! -f "$(basename "$file" .mp3).ogg"
    then
        lame --decode "$file"
        ARTIST=`id3tool "$file" | grep Artist | sed s/Artist:// | sed 's/[^A-Za-z0-9]*//'`
        ALBUM=`id3tool "$file" | grep Album | sed s/Album:// | sed 's/[^A-Za-z0-9]*//'`
        TRACK=`id3tool "$file" | grep Track | sed s/Track:// | sed 's/[^A-Za-z0-9]*//'`
        YEAR=`id3tool "$file" | grep Year | sed s/Year:// | sed 's/[^A-Za-z0-9]*//'`
        GENRE=`id3tool "$file" | grep Genre | sed s/Genre:// | sed -e 's/[^A-Za-z0-9]*//' -e 's/(.*)$//'`
        oggenc -a "$ARTIST" -G "$GENRE" -d "$YEAR" -N "$TRACK" -l "$ALBUM" -b 80 "$file.wav" -o "$(basename "$file" .mp3).ogg"
        rm "$file.wav"
    fi
done

In case you wonder why it uses such strange long lines, the process of getting the artist for example can be described as follows:

  • id3tool “$file” - get tags
  • grep Artist - get line containing word Artist
  • sed s/Artist:// - remove the preceding string “Artist:” from the line
  • sed ’s/[^A-Za-z0-9]*// - remove the unnecessary spaces/tabs/etc… before the artist name itself(the actual meaning is remove all characters before encountering alphanumerical - A-Z or a-z or 0-9)

Btw, basename “$file” .mp3 is just a neat way to strip mp3 extension preserving the filename itself.

The syntax is straightforward - you could use built-in wildcards - e.g. mp32ogg T*.mp3 will convert all mp3 files starting with T.

post Using CMake with vim

April 13th, 2008

Filed under: C++, Coding — zedr0n @ 3:08 pm

I’ve recently moved from make to CMake which is a cross-platform build system. It’s quite nice if you want to be able to build for mac/win with the same makefile(CMakeLists.txt for CMake). The CMakeLists syntax is quite powerful and I haven’t regretted moving since.

One of the main ideas of CMake is out-of-source build - that is you use cmake like this

cmake directory

where directory contains the CMakeLists.txt and it builds everything in the current directory you are in. This is mostly because CMake is quite messy - it uses lots of files to build.

I use Vim for my development and its awesome ‘make’ compatibility which allows to build programs using make inside vim and view errors with special vim commands. Now as CMake uses unix makefiles on mac, it works quite well from vim. But then you’ll have to first generate makefiles with cmake inside the source directory for that to function. Not a nice idea really…

My solution to this is to use Makeobj. It is a script used to build using normal make outside of source directory. It uses OBJ_SUBDIR environment variable which defines the name of subdirectory where the build will take place.

How can it be used with CMake and vim? Here is the maker script I use

#!/bin/bash

if [ -e makefile ]; then
    make
else
    export OBJ_SUBDIR=build
    if [ -e CMakeLists.txt ]; then
        if [ -d build ]; then
            cd build
            rm CMakeCache.txt
        else
            mkdir build
            cd build
        fi
        cmake ../
        cd ..
        makeobj $1 $2 $3 $4 $5
    fi
fi

Now in vim you just go

:set makeprg=maker
ruldrurd
© quant0r.com , Designed by Stealth Settings
Entries (RSS) and Comments (RSS)