Backup Tracks with "tee" And The "extern" Option

A simple way to make backups of played tracks is to set the extern option like this:

extern = tee "/some/path/%a - %t.mp3" | madplay -Q -

This will save the tracks at "/some/path/artist - track title.mp3" and play it at the same time using madplay. Note that skipped tracks are not deleted but left partially on disk.

To record music for later sending to an mp3 player, such as the Sansa Clip, you can use a slightly modified version of the above:

extern=dd of='/some/path/'%a\;%t\;%l.mp3

But you will want to make a small change to play.c to escape the filenames in the extern script so that dd won't fail on songs with apostrophes, etc. Change the call to meta using the "extern" value to use the M_SHELLESC flag, which will escape any non alphanumeric characters in the song titles, etc.

const char * cmd = meta(value(& rc, "extern"), M_SHELLESC, & track);

To later label these tracks with id3v2 tags so that the mp3 player can properly setup Artists, Songs, and Albums, use this short shell script while in /some/path/:

for file in *.mp3; do
info=${file%.mp3}
artist=$(echo $info | cut -d';' -f1)
song=$(echo $info | cut -d';' -f2)
album=$(echo $info | cut -d';' -f3)
id3v2 -a "$artist" -t "$song" -A "$album" "$file"; 
done;

There is also an extended version of the ID3 tag generation script. It also deletes incomplete files and renames the files to avoid special characters in file names.

#!/bin/bash
# filename update_id3
for file in *.mpg3; do
if test "$file" "==" "*.mpg3"; then
        exit 0;
fi
info=${file%.mpg3}
artist=$(echo $info | cut -d';' -f1)
song=$(echo $info | cut -d';' -f2)
album=$(echo $info | cut -d';' -f3)
length=$(echo $info | cut -d';' -f4)
length=`expr $length "/" 1000`
seconds=`mp3info -p "%S" "$file"`
seconds=`expr $seconds + 4`
if test $seconds -gt $length; then
        id3v2 -a "$artist" -t "$song" -A "$album" "$file";
        album=`echo "$album" | sed "s/[^A-Za-z0-9_-]/_/g"`
        song=`echo "$song" | sed "s/[^A-Za-z0-9_-]/_/g"`
        artist=`echo "$artist" | sed "s/[^A-Za-z0-9_-]/_/g"`
        mv "$file" "$artist#$song#$album.mp3" 
else
        echo "Remove $song from $artist because file length $seconds and id length $length"
        rm "$file";
fi
done

This script uses mp3info to get the actual track length and id3v2 to set the ID3 tag. The extern option above has to be modified a bit to include the track length and to change the file ending. You can also add the automatic execution of the script

extern = tee "/some/path/%a;%t;%l;%d.mpg3" | madplay -Q -
np-cmd = cd /some/path/; update_id3

The extern option generates problems on some systems. In this case, the audio output is delayed and overlaps when the track changes. I assume that it depends on the kernel version due ot the fact that the pipe length changed in version 2.6.11. Observed on Ubuntu 8.04. This problem can be solved by modifing the source code before compiling.

Change the line

if( haskey(& track, "freeTrackURL") &&  haskey(& rc, "download")) {

in file play.c to
if( /* haskey(& track, "freeTrackURL") && */ haskey(& rc, "download")) {

Also observed on Ubuntu 8.10. With shell.fm 0.6 the lines have changed to

// johnaman 05/30/2009 modified per http://shell-fm.wikidot.com/hack:extern-tee-backup
//
// replace this line (2nd find for "haskey" in play.c )
//        if(freetrack && strlen(freetrack) > 0 && haskey(& rc, "download")) {
        if( /*freetrack && strlen(freetrack) > 0 && */ haskey(& rc, "download")) {

don't forget to "$ sudo apt-get install libao-dev madplay libmad0-dev "
also "$ make clean" before you remake

and add the line ( for both 8.04 and 8.10 )

download = /some/path/%a;%t;%l;%d.mpg3

in your shell-fm.rc.

BTW, here is my shell-fm.rc

username = *YourUserNameHere*
password = *YourPasswordHere*
extern = tee "/home/john/Music/LastFM/%a - %l - %t.mp3" | madplay -Q -
download = /home/john/Music/LastFM/%a;%t;%l;%d.mp3
# use whatever you like here per guidelines in "$ man shell-fm"
default-radio = lastfm://user/johnaman/recommended
np-file = /home/john/.shell-fm/nowplaying
np-file-format = %t:%a:%S:%A
term-format = %a:%l:%t
delay-change = true
minimum = 80
gap = 20
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial 3.0 License