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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.