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.
32 use constant AGENT
=> 'Mozilla/5.0';
33 use constant URL
=> 'http://vimeo.com/26721145';
37 my $o = new WWW
::Quvi
::Options
;
38 $o->{user_agent
} = AGENT
;
42 print STDERR
"Querying media...\n";
44 my $q = new WWW
::Quvi
::Query
;
47 my $m = $q->parse(URL
);
48 croak
"error: $q->{errmsg}\n" unless $q->{ok
};
52 my $fn = "$m->{page_title}.$m->{file_suffix}";
53 print STDERR
"Saving to $fn...\n";
55 my $ua = new LWP
::UserAgent
;
59 open my $fh, ">", "$fn" or croak
"$?";
60 my $bytes_received = 0;
63 $ua->request(HTTP
::Request
->new(GET
=> $m->{url
}),
65 my ($chunk,$res) = @_;
66 $bytes_received += length($chunk);
67 printf STDERR
"%d%% - ",
68 100*$bytes_received/$m->{content_length
};
69 print STDERR
"$bytes_received bytes received\r";
74 print "\n", $res->status_line, "\n";
76 # vim: set ts=2 sw=2 tw=72 expandtab: