http://qs321.pair.com?node_id=718699

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

Replies are listed 'Best First'.
Re: Download video from popular videoservices
by diffredential (Beadle) on Nov 02, 2008 at 14:48 UTC
    Amazing!! really useful and clean-coded Perl script. Love the coding style. Thanks!