Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

hi guys
need some serious help...

i need to capture streaming audio from a web site and save it on my local drive. i don't know where to start ??? i tried with lwp but no help... can someone point me in the right direction ??? any ideas ??

basically i want to setup a cron job to start the perl script which will start recording and then continue for about 1 hour and then end and save the file in mp3 format ... do you guys know if this can be done in perl ??

Edit by tye

Replies are listed 'Best First'.
Re: perl script to capture streaming audio
by carthag (Scribe) on Dec 20, 2002 at 21:28 UTC

    While you can do it with perl, I swear by The Right Tool for The Right Job.

    However, it's a bit unclear as to what you want to do. If you want to get a streamed file that's about one hour long, you can do this:

    curl -f -r 0-58982400 -O "http://url"

    This will get the first 58982400 bytes of the file, which is roughly one hour of sound at 128kbps (ie 128*60*60*1024/8 - adjust as you see fit). If you want the transfer to run for one hour (or 3600 seconds), do this:

    curl -f -m 3600 -O "http://url"

    cURL is most likely installed on your system. If not, it's freely available for most platforms at curl.haxx.se

    The -f option makes sure that it doesn't write a file if there's an error (who wants empty files anyway?), and the -O option tells it to save the file with the same name as on the server. Alternately, you can use -o "filename.mp3" for a specific filename. In case the server wants a referer, use -e "http://server/". There are many more switches, so have a gander at the manpage... Good luck! And have a great yule! =)

    Edit: Fixed idiotic error. Bits != bytes.

      this is very good ... i have installed it on my linux box but am having problems with it (installation is fine but don't know how to use it).. the url i am trying to capture the streaming audio is:
      http://www.wjse.com/wmplayer.asp
      and i checked the html source and can see that the file with the audio is :
      http://www.wjse.com/jseaudio.asx
      can you please help me out ... thanks

        Ah. Now this is bordering on probably being against the DMCA, but I'm not in America, so I don't mind. ;)

        One thing you can try is just curling the url to stdout to see what's in it. This might look really weird if it's binary, but in this case it's not.

        % curl http://www.wjse.com/jseaudio.asx <asx version = "3.0"> <title>WJSE Live Stream For Dial-up Connections</title> <entry> <BANNER HREF = "http://wjse.com/images/wmbanners/lavalife120x30.g +if" /> <ref href = "mmst://corp.wjse.com/audio"/> </entry> </asx>

        It's the part with the ref tag that you want. But the mmst protocol isn't supported by cURL. I believe it's propietary to some company. Probably MS ;).

        I haven't tried it myself, but I've been led to believe that asfrecorder will do the job.

        So much for discussing perl eh? - I didn't find anything but XML::ASX which doesn't do what we need here.

        Hi,

        This is beginning to look more lile a what is my favorite stream player poll. But looking at your link, I would say mplayer.


        ---------------------------
        Dr. Mark Ceulemans
        Senior Consultant
        IT Masters, Belgium

Re: perl script to capture streaming audio
by cascade_fx (Sexton) on Dec 20, 2002 at 19:38 UTC
    I am not sure how to do this with perl, but as one of the other many ways to do it, I would suggest a nifty little (unfortunately, Windows) utility from High Criteria Software called Total Recoder

    It does pretty much everything that you just listed. It does this by setting itself up as the Windows sound driver and then "T's" the output to an MP3 or Wav file while still passing the sound to the speakers.

    It is very cool.

      A little off topic, but XMMS will save to disk for you. The default plugin writes WAV files, but I do believe that there are others that will write to different formats. Not sure how to cron this, though it's probably possible.

      VSound (external link) does something similar for *nix systems. It seems a bit flaky, though.

      Personally, if I know the input is going to be an MP3 stream (or whatever else), I'd prefer to save it directly to a file via Perl instead of mucking about with loopback sound drivers.

Re: perl script to capture streaming audio
by arrow (Friar) on Dec 20, 2002 at 21:41 UTC
    Also you might want to look at Apache::MP3 and MP3::Daemon. They both do MP3 downloading activities, Apache::MP3 more so. Hope this helps!


    Cheers!
Re: perl script to capture streaming audio
by nutshell (Beadle) on Dec 20, 2002 at 22:43 UTC
    I really don't think Perl is the right tool for this.

    May I suggest the excellent StreamRipper 32?

    --nutshell