record music from last.fm using shell-fm

as i mentioned before again and again, i’ve been working on to get shell-fm to record music from last.fm. originally, i was trying to get shell-fm pipe to tee to save the songs and play using madplay (or mplayer) based on this method. this worked. i just need to write scripts to post process the songs to get id3 tags, etc. things work, and i have something like this in my shell-fm.rc file:

<pre class="src src-sh">extern = tee <span style="color: #ffa07a;">"/Users/vinh/shell-fm-saves/%a;%t;%l;%d.mpg3"</span> | madplay -Q -

##extern = tee “/Users/vinh/shell-fm-saves/%a;%t;%l;%d.mpg3″ | mplayer -cache 32 -

however, if u look at the end of the same page, it mentions hacking the source code because u can get shell-fm to automatically save free files, and get id3 tags on there. hopped on #shell-fm on the freenode and spoke to the author. (i tried this before but it didn’t work — reason was i didnt do a make clean first…i had residuals from the fail install since its on a mac).

now, to get shell-fm to compile with recording of every songs and get id3 tags working, just install libtag via MacPorts, modify play.c (search for freetrack and comment out that part):

<pre class="src src-C"><span style="color: #00ffff;">if</span>( <span style="color: #ff4500;">/*</span><span style="color: #ff4500;">freetrack &amp;&amp; strlen(freetrack) &gt; 0 &amp;&amp; </span><span style="color: #ff4500;">*/</span> haskey(&amp; rc, <span style="color: #ffa07a;">"download"</span>)) {

to compile, go in the source directory, do a make clean, then do the following on a mac:

<pre class="src src-sh">cc -o shell-fm -D__darwin__ -Os -Wall -W -I./include/ -DLIBAO -I/opt/local/include -I/opt/local/include -L/opt/local/lib -lmad -lm -Wl,-framework -Wl,AudioUnit -L/opt/local/lib -lao -lpthread -DTAGLIB <span style="color: #fa8072;">`pkg-config --libs taglib_c`</span> *.c

the author helped me figure out the DTAGLIB stuff, and how to get this command originally (had to remove the main.c in the middle and change the last .a file to *.c).

did:

<pre class="src src-sh">cp ./shell-fm /usr/bin/

cd ../manual make sudo shell-fm.1 /usr/share/man/man1/

now, go to ~/.shell-fm/shell-fm.rc and put in download = /Users/vinh/shell-fm-saves/%a – %t.mp3 and all completed songs will be saved WITH id3tag

hacking/editing portfile (MacPorts) to compile madplay for use with shell-fm (last.fm)

so recently i compiled shell-fm, a command-line last.fm player. in order to record music with shell-fm, i can output the stream of incoming data into tee, which saves the data to a file and at the same time pipes it out to stdout, and have that piped to madplay, a command-line player.

i had mplayer installed, but in order to get the piping of the streaming data to work, i had to to specify a cache ‘| mplayer -cache 32 -‘ (- means to take from stdin) in order for the music to play at the right rate. otherwise, the mplayer plays at a slower rate. the shell-fm wikidot recommends madplay.

madplay doesn’t compile easily on a mac os x, so i had to resort to MacPorts for the installation. it installs fine, but madplay plays noise. googled it, and stumbled on this post. he figured out it was an endian issue.

i tried applying his patch (‘patch < temp.patch’) to the original source code, however, it didn’t compile. figured out that i need the patch and the flags (CFLAGS, LDFLAGS) from Macports as well. i didn’t know how to apply both patches. hopped on #MacPorts on the freenode, and spoke with toby.

i created the 2nd patch and called it temp.patch in /opt/local/var/macports/sources/rsync.macports.org/release/ports/audio/madplay/files. edited /opt/local/var/macports/sources/rsync.macports.org/release/ports/audio/madplay/Portfile and added temp.patch to the list of patch files. now running ‘sudo port install madplay’ did the trick after uninstalling (sources and portfiles still around). voila, i have a working install on mac os x.

toby committed the new patch to macports, so now things should work. to get the new patches, i had to run ‘sudo port -d sync’ to sync the newest patch files. i uninstalled and reinstalled and the new official patch works.

i learned how macports operated and how to apply patch files in this adventure.

installing shell-fm on mac os x

i blogged recently that i couldn’t compile shell-fm on mac os x. hopped #shell-fm on the freenode, and talked to the author himself. the error i got was:

<pre class="src src-sh">cc -o shell-fm -D__darwin__ -Os -Wall -W -I./include/ -DLIBAO -I/opt/local/include -I/opt/local/include main.c -L/opt/local/lib -lmad -lm -Wl,-framework -Wl,AudioUnit -L/opt/local/lib -lao -lpthread libshellfm.a

ld: in libshellfm.a, archive has no table of contents collect2: ld returned 1 exit status make[1]: *** Error 1 make: *** Error 2

he suggested i go to the source and do:

<pre class="src src-sh">cc -o shell-fm -D__darwin__ -Os -Wall -W -I./include/ -DLIBAO -I/opt/local/include -I/opt/local/include -L/opt/local/lib -lmad -lm -Wl,-framework -Wl,AudioUnit -L/opt/local/lib -lao -lpthread *.c

that is, remove the main.c in the middle and libshellfm.a to *.c

that did the work and i got a working binary in the source folder. ran make in the manual folder, and installed them:

<pre class="src src-sh">sudo cp ./source/shell-fm /usr/bin

sudo cp ./manual/shell-fm.1 /usr/share/man/man1/

shell-fm is working now.

ALSO: according to this site, i modified play.c before compiling in v .6 as follows:

 <pre class="src src-C"><span style="color: #ff4500;">// </span><span style="color: #ff4500;">johnaman 05/30/2009 modified per http://shell-fm.wikidot.com/hack:extern-tee-backup</span>

// // 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”)) {

Free online radio: last.fm + pandora

so i found out about online radio through michael zeller (again). i did do a search for this back then, and i thought what i wanted were podcasts….radio through itunes. however, googling it i realized that wasn’t what i wanted. podcasts are good for tutorials or talk shows or the news, but probably not for music.

last.fm and pandora are two free service. i personally use last.fm and haven’t tried pandora. it seems last.fm has more music (i don’t see vedera on pandora). in both, u can listen to on the web or have the player installed on your computer.

on the mac os x, i’m using sweetfm. it’s cool because it can record, although the options for saving isn’t features-full yet. on a linux, shell-fm is good (command-line based). u can use dd to record (check this). i’m having trouble compiling shell-fm on my mac os x.