#!/usr/bin/perl # # Copyright (C) 2011-2012 Trizen . # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # #------------------------------------------------------- # vimeo.com video downloader # Created on: 29 April 2011 # Latest edit on: 15 March 2012 # Website: http://trizen.googlecode.com # Email: echo dHJpemVueEBnbWFpbC5jb20K | base64 -d #------------------------------------------------------- use strict; my $appname = 'vimeo-dl'; my $version = '0.0.7'; my $title; our %CONFIG; if (@ARGV) { require Getopt::Long; Getopt::Long::GetOptions( 'help|h|?' => \&help, 'version|v' => \&version, 'lowest|l' => \$CONFIG{lowest}, 'quiet|q' => \$CONFIG{quiet}, 'stream|s' => \$CONFIG{stream}, 'output|title|o=s' => \$title, ); } sub version { print "$appname $version\n"; exit 0; } sub help { print <<"HELP"; usage: $0 [options] | options: -h --help : print help and exit -v --version : print version and exit -l --lowest : download video(s) at the lowest quality available -s --stream : stream video(s) with MPlayer -o title.ext : output file -q --quiet : be quiet\n HELP exit 0; } unless (@ARGV) { require Term::ReadLine; my $term = Term::ReadLine->new("$appname $version"); my $url = $term->readline("=>> Vimeo URL/ID\e[0m\n> "); exit 1 if $url eq ''; unshift @ARGV, $url; } require LWP::UserAgent; my $chrome = 'Mozilla/5.0 (X11; Linux i686) Chrome/12.0.742.16 Safari/534.30'; my $non_ua = 'NaN'; my $lwp = 'LWP::UserAgent'->new(env_proxy => 1); sub vimeo { my $vimeo_id = shift(); unless ($CONFIG{quiet}) { print "\n** Getting: http://vimeo.com/$vimeo_id\n"; } $lwp->agent($non_ua); my ($timestamp, $request_signature, $isHD); my $content = $lwp->get("http://www.vimeo.com/moogaloop/load/clip:$vimeo_id")->content; if ($content =~ m{^\s*(.+?)\s*$}mi) { $request_signature = $1; } else { warn "** Invalid ID: $vimeo_id\n"; @ARGV ? do { undef $title; next } : exit 1; } if ($content =~ m{^\s*(.+?)\s*$}mi) { $timestamp = $1; } if ($content =~ m{^\s*(\d)\s*$}mi) { $isHD = $1; } if (not defined $title and $content =~ m{^\s*(.+?)\s*$}mi) { $title = $1; } elsif (not defined $title and $content =~ m{^\s*(.+?)\s*$}mi) { $title = $1; } else { $title = 'Unknown'; } if ($title =~ /&#?\w/) { require HTML::Entities; $title = HTML::Entities::decode_entities($title); } # Replacing reserved characters with a space $title =~ tr{\\/:*?"< >|}{ }s; my ($q, $format) = $isHD && !$CONFIG{lowest} ? ('hd', 'mp4') : ('sd', 'flv'); my $vimeo_url = "http://www.vimeo.com/moogaloop/play/clip:$vimeo_id/$request_signature/$timestamp/?q=$q"; unless ($CONFIG{quiet}) { print "** Title: '${title}'\n", "** Is HD: $isHD\n", "** Timestamp: $timestamp\n", "** Request signature: $request_signature\n", "** URL: $vimeo_url\n\n"; } if (not $CONFIG{stream}) { unless ($CONFIG{quiet}) { print "=>> Downloading '$title.${format}'\n"; $lwp->show_progress(1); } $lwp->mirror($vimeo_url, "$title.$format"); $lwp->show_progress(0); } else { system 'mplayer', $vimeo_url; } undef $title; return 1; } while (@ARGV) { my $arg = shift; if ($arg =~ m[\bvimeo[.]com/(\d+)]) { vimeo($1); } elsif ($arg =~ /^\d+$/) { vimeo($arg); } elsif ($arg =~ m{^https?://}) { $lwp->agent($chrome); my $content = $lwp->get($arg)->content; if ($content =~ /\bvimeo[.]com.+?clip_id=(\d+)/) { vimeo($1); } } else { warn "Unknown ID: $arg\n"; exit 1 unless @ARGV; } }