3

I have a music collection consisting of several film soundtracks in Apple Lossless and I'd like to convert it to 48kbps OGG Vorbis in a completely different folder structure with file names in the following format:

/music folder/{album artist}/{album name}/{track number} {track title} - {track artist}.ogg

I would also like to extract the album covers in a separate file called 'AlbumArt.jpg' in the same folder.

The problem is I want to do this on my headless Ubuntu server - so terminal only.

Is there any way to do this without some extensive script-writing?

3
  • Could you give us some more info? You cannot avoid bash scripting here, so I am trying to write a script for your occassion. But I am missing some information, like where are your initial soundtracks? What is your favorite converter to use (do you even have?)?. Where is {track number} located at the filenames of your initial files and in what format (e.g. the 1st track number is filename1.mp3 or filename01.mp3 or filename001.mp3)? As for the complexity of the bash script I'd say don't worrry, such things are easy to be done with a bash script!
    – hytromo
    Aug 13, 2012 at 21:54
  • The {track artist} will be ridiculously because the artist is declared in the folder, at the begin. Also, all the songs are in the same format?
    – Lucio
    Aug 14, 2012 at 2:23
  • Let's say the initial soundtracks are located in /soundtracks/, each soundtrack in it's own sub-folder(s). The source files are not named in one specific manner (except for the .m4a part) so the only way to get things like {track number} is from the tags. The files I want to convert are all in the same format, but of course it would be nice if the script could convert from other formats as well.
    – Silke
    Aug 19, 2012 at 9:24

1 Answer 1

3

Here's a sample script and how to use it.

Install these packages first: libav-tools mediainfo ubuntu-restricted-extras

  • avconv (formerly known as ffmpeg) performs the actual conversion
  • mediainfo provides the tag information to create the folder structure and name the file.

The script is:

#!/bin/bash
OUTPUTBASE=converted-oggs #path to the base folder for output ALBUMARTIST=`mediainfo --Inform="General;%Album/Performer%" "$1"` ALBUM=`mediainfo --Inform="General;%Album%" "$1"` TNUMBER=`mediainfo --Inform="General;%Track/Position%" "$1"` TTITLE=`mediainfo --Inform="General;%Track%" "$1"` TARTIST=`mediainfo --Inform="General;%Performer%" "$1"` mkdir -p "$OUTPUTBASE/$ALBUMARTIST/$ALBUM" mediainfo --Inform="General;%Cover_Data%" "$1" | base64 -d > "$OUTPUTBASE/$ALBUMARTIST/$ALBUM/AlbumArt.jpg" avconv -i "$1" -acodec libvorbis -b 48k "$OUTPUTBASE/$ALBUMARTIST/$ALBUM/$TNUMBER $TTITLE - $TARTIST.ogg"

Suppose we name the script ~/silexcvt.sh, then you to convert all m4a tracks in the ~/soundtracks folder, you would have find and xargs call the script as:

find soundtracks -regex '.*m4a$' | xargs -I '{}' ./silexcvt.sh "{}"
2
  • Thanks for your answer, you've helped a lot! I do have some small points however: 1) The package avconv doesn't exist, it should be libav-tools. 2) cvt should be $OUTPUTBASE. 3) This script doesn't output the albumart to AlbumArt.jpg as I would like, is this possible?
    – Silke
    Aug 23, 2012 at 13:32
  • Album art can be extracted by adding the following to the script: mediainfo --Inform="General;%Cover_Data%" "$1" | base64 -d > "$OUTPUTBASE/$ALBUMARTIST/$ALBUM/AlbumArt.jpg". With this information my question is solved. Thanks again!
    – Silke
    Aug 23, 2012 at 15:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .