Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

This script downloads video not only from YouTube but from any popular video storage such as Break.com, Metacafe, iFilm, MySpace etc.

Usage: pownload.pl VideoURL [outputfile]

Examples:

perl pownload.pl 'http://www.break.com/index/ridiculous-chimp-rides-and-\
crashes-segway.html' chimp.flv

perl pownload.pl 'http://www.youtube.com/watch?v=N9Unv4zioSc'

If outputfile is not given then the script choose a name like video_0001.flv

The idea is that there are plenty of websites which translate videourl to the link to direct download the video. Using those services my script is not affected when youtube or others change their html templates.

The script asks one of the services to translate video page url to download link and then downloads the video. If the service does not respond then the script asks another service from a list

#!/usr/bin/perl -- # # pownload.pl -- a tool for downloading video from popular videoserv +ices # use strict; use warnings; use LWP::UserAgent; $| = 1; my %services = ( 'http://cs.videosaver.ru/xurl/' => 'href="([^"]*)"\s+title="FLV', 'http://keepvid.com/' => '<a href="([^"]*)"[^>]*>[^:]*\.flv', 'http://vidirect.ru/backend/main_backend.php' => '^(.*)$', 'http://0download.ru/' => q{copytoclipboard\('([^']*)'\)}, ); die "Usage: pownload.pl VideoURL [outputfile]\n" unless @ARGV; my ($videourl, $outflv) = @ARGV; my $i = 0; $outflv = sprintf('video_%04d.flv', $i++) while !$outflv or -e $outflv; my $ua = LWP::UserAgent->new; foreach my $service (keys %services) { print "Trying $service...\n"; my $response = $ua->get($service . '?url=' . $videourl); next unless $response->is_success && $response->content =~ /$services{$service}/; print "Saving video to $outflv...\n"; my $received_size = 0; open my $fh, '>' , $outflv or die $!; binmode $fh; $ua->get($1, ':content_cb' => sub { my ($data, $response) = @_; $received_size += length $data; print {$fh} $data; printf "\r" . [qw(- \\ | /)]->[++$i % 4] . ' %d%% ', 100 * $received_size / ($response->header('Content-Length') || 1) +; }); print "\nDone.\n"; exit; } print "Sorry.\n";

In reply to Download video from popular videoservices by ccn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (1)
As of 2024-04-25 19:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found