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

hi, I wrote a spyder to go to a site and follow the link log in using the userid and password, do all the neat stuff to download the mp3 songs from the site....aight now this is wat happens I did succeed in getting the song downloaded using UserAgent Get method but the song get corrupted somehow and it won't play :(, any thoughts anyone wat do I gotta do to keep the song quality/format the same? thanx in advance
  • Comment on downloading mp3 songs using LWP::UserAgent

Replies are listed 'Best First'.
Re: downloading mp3 songs using LWP::UserAgent
by tachyon (Chancellor) on Oct 07, 2004 at 06:31 UTC

    You will probably be on Win32 and will not have applied binmode to the filehandle you used to save the data.

    open F, $outfile or die $!; binmode F; print F $response->content; close F;

    cheers

    tachyon

Re: downloading mp3 songs using LWP::UserAgent
by bart (Canon) on Oct 07, 2004 at 20:58 UTC
    getstore() works fine for me.

    But: applying binmode to the file handle you're saving to, should work, too.

    p.s. You mentioned logging in, so maybe therefore, LPW::Simple is out. But, because mp3 files are quite big, I am not in favour of first retrieving the whole file, and then saving it, as some other people suggested. Instead, take a look at how LWP::Simple implements getstore(), and copy those few lines of code, then extend it to include the logging in.

      If you want to keep using LWP::UserAgent how about something like this:
      $user_agent->get($mp3_url, ":content_file" => $local_mp3_filename);
Re: downloading mp3 songs using LWP::UserAgent
by radiantmatrix (Parson) on Oct 07, 2004 at 14:38 UTC
    aight now this is wat happens

    Are you serious? I'm not normally a grammar-nazi, but if you're asking for help from professionals, you could at least make an attempt at writing professionally.

    "Aight" is not a word, unless it is an archaic spelling of "eight". "Wat" is just odd -- don't you have an "h" key?

    This isn't IRC, or an IM system... I have a very hard time respecting a questioner that doesn't show respect to those he questions.

    radiantmatrix
    require General::Disclaimer;
      YUB Dishing Jizzy G's whack rapp'n?
      YU gotta B like all that, Yo?
      Peas!
Re: downloading mp3 songs using LWP::UserAgent
by Anonymous Monk on Oct 07, 2004 at 10:45 UTC
    Buy a guitar?