Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Trying to download video from URL links

by aitap (Curate)
on Dec 22, 2013 at 09:11 UTC ( [id://1068090]=note: print w/replies, xml ) Need Help??


in reply to Trying to download video from URL links

Well, $mech->get is an overloaded method from LWP::UserAgent which can be called as $mech->get( $uri, ':content_file' => $filename ); (quote from the WWW::Mechanize documentation). I've been using this method in my own downloader, but later decided to switch to wget to do the actual downloading. Wget gives me a progress bar and download resuming for free, without writing any additional code, and I already have it installed everywhere.

It's even considered good by "UNIX-way" philosophy to call a program which does one thing and does it well when you need this thing to be done.

Replies are listed 'Best First'.
Re^2: Trying to download video from URL links
by Anonymous Monk on Dec 22, 2013 at 15:38 UTC

      So I added the ability to pass in command line arguments: para(1): url, para(2): regex in link you are looking for, para(3): is the fileExtension you want appended onto link text

      #!/usr/bin/perl -w use strict; use warnings; use WWW::Mechanize; my $total_args = $#ARGV + 1; if ($total_args != 3) { print "usage: getLinks url regEx suffix(file type)\n"; exit; } my $mech = WWW::Mechanize->new(); my $url = $ARGV[0]; my $regEx = $ARGV[1]; my $fileType = ".".$ARGV[2]; $mech->get($url); my @links = $mech->find_all_links( url_regex => qr#$regEx# ); for my $link(@links) { printf("Following: %s\n at address: %s\n", $link->text, $link->url +); printf("Saving file as %s\n", $link->text.$fileType."\n"); $mech->get($link->url, ':content_file' => $link->text.$fileType); }

      I would like to add a progress bar similar to what wget uses so could you explain a bit more about:

      $lwpmechua->show_progress( 1 )?

      Thanks as always!

        $lwpmechua is $mech in your code

       $lwpmechua->show_progress( 1 );
      Wow. There is even WWW::Mechanize::Plugin::Retry which probably can be hacked to automatically continue partial downloads, so Mechanize eventually could replace wget.

      While I have to admit that I didn't remember about show_progress, the progress bar of wget shows the percentage and ETA and the -c option automagically continues a broken download which doesn't look like a simple task in Mechanize.

Re^2: Trying to download video from URL links
by soulrain (Initiate) on Dec 22, 2013 at 19:12 UTC
    Ah this is true and definitely supported by software tools principle!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1068090]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-20 00:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found