21 April 2008 @ 10:50Recording MP3 streams with Applescript

The other day when Ralph Bakshi was scheduled to be interviewed on WNYC, it prompted me to try to find a way to record the MP3 stream while I was away.

The basis of my Applescript was the following curl command:

curl -A "Mozilla/4.0" http://wnycfm.streamguys.com/ -o ~/Desktop/wnyc.mp3

I have yet to figure out how to get the Applescript to look at the iCal event it is attached to in order to find when it should end the curl process. I don't even know if this is possible. As of right now, I have an Applescript that requires user interaction when launched to obtain the duration and url of the stream. Of course, in its current state it is unfit to be attached to an iCal event.

property stream_url : ""
property duration : ""
set timestamp to (do shell script "date " & "+%H%M_%m_%d_%Y")
display dialog "Enter the URL for the stream" default answer stream_url
set the stream_url to text returned of result
display dialog "Enter the duration in seconds" default answer duration
set the duration to text returned of result
do shell script ("curl -A \"Mozilla/4.0\" " & stream_url & " -o ~/Desktop/stream_" & timestamp & ".mp3 &> /dev/null & echo $!")
set pid to the result
do shell script "sleep " & duration & "; kill " & pid

One somewhat clumsy way of doing this would be to have two separate Applescripts -- one to start the recording and one to end the recording, but adding and maintain these events would sure be a pain.

If anyone out there knows how to have the script that is attached to an event access the end time and description of the event, I would love to know. It would go something like this: have a script that is attached to an iCal alarm, and have this script get the uid of the event that opened the script. Then have the script look at the end time of the event and calculate the duration of the recording, and get the url of the stream out of the description.

Shop for Applescript books

Be Sociable, Share!

by | Add a comment | Tags:
Posted in applescript, curl, music | Link to this

Add a Comment

Show who you are with a Gravatar.


Sign up for PayPal and start accepting credit card payments instantly.

Staples Logo

Get fed!

rss icon subscribe to Geek stuff

rss icon Geek stuff in your inbox

Add the "Geek stuff" Google Gadget to your homepage

Add the "Daily Deals" Google Gadget to your homepage


Search Amazon

Search Amazon.com
Search Amazon.co.uk

Recent Forum Topics


    Web hosting by ICDSoft