#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    56
    Rep Power
    15
    I was trying to write a perl script to grap a mov file for me. I know it worked when I used the same script to grap images. But when I tried to get the .mov file, quicktime viewer says there's something wrong with it.

    the code is as follows

    require LWP::UserAgent;
    require HTTP::Request;
    use HTTP::Request::Common;

    $ua = new LWP::UserAgent;
    writeFile('http://a496.g.akamai.net/5/496/51/36707eff03de83/1a1a1aaa2198c627970773d80669d84574a8d80d3cb12453c02589f25382f668c9329e0375e8177ae955ca3799026392f861 cf309cfb61c230a40578 f1/finalfantasy_480.mov');

    sub writeFile
    {
    my ($site) = @_;
    print "Getting $site...n";
    print "Saving Filen";

    $request = GET "$site";
    $response = $ua->request($request);

    if ($response->is_success)
    {
    open(outFile, ">final.mov");
    print outFile ($response->content());
    close(outFile);
    # print 'Success!';
    }
    else
    {
    print 'ERROR!';
    }
    }

    Thanks for any suggestions in advance.

    Ben
  2. #2
  3. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    Grabbing and storing, why not try something like this?

    #############################################
    #!/usr/local/bin/perl

    $local_path = "/path/to";
    use LWP::Simple;
    $target_file = "http://a496.g.akamai.net/5/496/51/36707eff03de83/1a1a1aaa2198c627970773d80669d84574a8d80d3cb12453c02589f25382f668c9329e0375e8177ae955ca3799026392f861 cf309cfb61c230a40578f1/finalfa ntasy_480.mov";
    getstore("$target_file","$local_path/final.mov");
    print "Content-type: text/htmlnn";
    if (-e "$local_path/final.mov") {
    print "Success!n";
    }
    else {
    print "Error!n";
    }
    #############################################
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    56
    Rep Power
    15
    Thanks. It's working great. But out of curiousity, why didn't my script work? I was getting all the bits and constructing the new file. should work the same why I guess?

  6. #4
  7. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>why didn't my script work?

    Because of a missing line:

    print "Content-type: text/htmlnn";

    But still, it should fetch the *.mov file okay.

    Also, your

    print "Saving Filen";

    line is not in the appropriate position. It should be in the same line as open(outFile, ">final.mov");

    A rewrite of your script would be:

    #############################################
    #!/usr/local/bin/perl

    print "Content-type: text/htmlnn";
    require LWP::UserAgent;
    require HTTP::Request;
    use HTTP::Request::Common;
    $ua = new LWP::UserAgent;
    writeFile('http://a496.g.akamai.net/5/496/51/36707eff03de83/1a1a1aaa2198c627970773d80669d84574a8d80d3cb12453c02589f25382f668c9329e0375e8177ae955ca3799026392f861 cf309cfb61c230a40578
    f1/finalfantasy_480.mov');

    sub writeFile {
    my ($site) = @_;
    print "Getting $site..<br>n";
    $request = GET "$site";
    $response = $ua->request($request);

    if ($response->is_success) {
    open(outFile, ">final.mov") && print "Saving File as final.mov<br>n" &#0124; &#0124; &error("Unable to create final.mov<br>n");
    print outFile ($response->content());
    close(outFile);
    print "Success!n";
    }
    else {
    &error("Error in fetching!n");
    }
    }

    sub error {
    my (@messages) = @_;
    my $message;
    foreach $message (@messages) {
    print $message;
    }
    #############################################

    [This message has been edited by freebsd (edited October 07, 2000).]

IMN logo majestic logo threadwatch logo seochat tools logo