Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
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! –  hakermania Aug 13 '12 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 '12 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. –  Silex Aug 19 '12 at 9:24

1 Answer 1

up vote 3 down vote accepted

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 "{}"
share|improve this answer
    
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? –  Silex Aug 23 '12 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! –  Silex Aug 23 '12 at 15:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.