HowTo: Linux music management
Here are some scripts that I use for maintaining music on my linux
(kubuntu,ubuntu edgy) box.
First, I created up a directory off of my home directory called SONGS. I
use the KAudioCreator to rip CDs to the SONGS directory. Here is
KAudioCreator's file location spec:
~/SONGS/%{albumartist}/%{albumtitle}/%{number} - %{title}.%{extension}
I set the encoder to FLAC (run 'apt-get install flac' as root). This is
because FLAC is lossless.
After ripping the music, I convert the songs from FLAC to OGG format. It
is the OGG files that I am going to place on the MP3 player since they
are much smaller than FLAC files and the encoding is not proprietary
(you could, of course, use WAV for lossless encoding and MP3 or WMA as
the compressed format, assuming you have the codecs).
To convert to OGG format, I use the following script, named flac2ogg:
for s in "$@"
do
chmod 644 "$s"
name=`basename "$s" .flac`
echo converting "$s" to OGG
flac -s -f -d -c "$s" | sox -t wav - "$name".ogg
done
As you can see, you will need to install sox (apt-get install sox). Here
is an example use of the script:
flac2ogg *.flac
...which converts every flac file in the current director to ogg format
(the original flac files are kept).
Next, I move the ogg files to mp3 player (which is viewed by Linux as
a USB mass storage device). I use the following script to preserve the
directory hierarchy. I named the script comp2player:
location=media/usbdisk
where=`pwd`
name=`artist "$where"`
mkdir -p $location/SONGS/"$name"
for s in "$@"
do
cp "$s" $location/SONGS/"$name"/"$s"
done
You may need to change the location variable to wherever your system
mounts your player. Here is an example use of the script...
comp2player *.ogg
...which copies every ogg file in the current directory to the mp3
player. If the location of ogg files is...
~/SONGS/Bob\ Seger/Greatest\ Hits/
...the ogg files will be located at...
/SONGS/Bob\ Seger/Greatest\ Hits/
...on the mp3 player. The artist command referenced by the script
strips off the front part of the PATH up to and including the SONGS
directory. You could probably use awk to do this, but it was faster for
me to write a C program than to figure out awk:
#include <stdio>
#include <stdlib>
#include <string>
static char *strip(char *);
int
main(int argc,char **argv)
{
if (argc != 2)
{
fprintf(stderr,"usage: artist <dir>\n");
exit(-1);
}
printf(strip(argv[1]));
return 0;
}
static char *
strip(char *location)
{
char *s;
s = strstr(location,"SONGS");
if (s == 0)
return "";
else
return s+6;
}
To move files from the mp3 player to the computer, I use the script
player2comp:
where=`pwd`
name=`artist "$where"`
mkdir -p ~/SONGS/"$name"
for s in "$@"
do
cp "$s" ~/SONGS/"$name"/"$s"
done
As with comp2player, the directory hierarchy is preserved (and created,
if necessary).
|