Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old October 7th, 2000, 02:23 AM
benliong benliong is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 56 benliong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
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

Reply With Quote
  #2  
Old October 7th, 2000, 09:06 AM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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";
}
#############################################

Reply With Quote
  #3  
Old October 7th, 2000, 12:07 PM
benliong benliong is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 56 benliong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
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?


Reply With Quote
  #4  
Old October 7th, 2000, 03:40 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
>>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" | | &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).]

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Grapping File Problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway