4 # Copyright (C) 2011 Toni Gundogdu <legatvs@gmail.com>
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 # get_media.pl - Simple media downloader
23 # Note the use of custom user-agent string.
33 use constant AGENT
=> 'Mozilla/5.0';
34 use constant URL
=> 'http://vimeo.com/26721145';
38 my $o = new WWW
::Quvi
::Options
;
39 $o->{user_agent
} = AGENT
;
43 say STDERR
"Querying media...";
45 my $q = new WWW
::Quvi
::Query
;
48 my $m = $q->parse(URL
);
49 croak
"error: $q->{errmsg}\n" unless $q->{ok
};
53 my $fn = "$m->{page_title}.$m->{file_suffix}";
54 say STDERR
"Saving to $fn...";
56 my $ua = new LWP
::UserAgent
;
60 open my $fh, ">", "$fn" or croak
"$?";
61 my $bytes_received = 0;
63 my $res = $ua->request(
64 HTTP
::Request
->new(GET
=> $m->{url
}),
66 my ($chunk, $res) = @_;
67 $bytes_received += length($chunk);
68 my $s = sprintf "%d%% - ",
69 100 * $bytes_received / $m->{content_length
};
70 print STDERR
"$s $bytes_received bytes received\r";
76 say "\n", $res->status_line;
78 # vim: set ts=2 sw=2 tw=72 expandtab: