find lib/ -name "*.pm" -exec tail -n 1 {} \;
[clive.git] / lib / clive / Host / Vimeo.pm
blob86fe689b148af13c320ad2c27ba29e5a59fe0544
1 # -*- coding: ascii -*-
2 ###########################################################################
3 # clive, command line video extraction utility.
4 # Copyright 2007, 2008, 2009 Toni Gundogdu.
6 # This file is part of clive.
8 # clive is free software: you can redistribute it and/or modify it under
9 # the terms of the GNU General Public License as published by the Free
10 # Software Foundation, either version 3 of the License, or (at your option)
11 # any later version.
13 # clive is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 # details.
18 # You should have received a copy of the GNU General Public License along
19 # with this program. If not, see <http://www.gnu.org/licenses/>.
20 ###########################################################################
21 package clive::Host::Vimeo;
23 use warnings;
24 use strict;
26 sub new {
27 return bless( {}, shift );
30 sub parsePage {
31 my ( $self, $content, $props ) = @_;
33 $$props->video_host("vimeo");
35 my %re = (
36 id => qr|clip_id=(.*?)"|,
37 title => qr|name="title" content="(.*?)"|
40 my $tmp;
41 if ( clive::Util::matchRegExps( \%re, \$tmp, $content ) == 0 ) {
42 my $config = "http://vimeo.com/moogaloop/load/clip:$tmp->{id}";
44 if ( _parseConfig( $self, $config, $tmp->{id} ) == 0 ) {
45 $$props->video_id( $tmp->{id} );
46 $$props->video_link( $self->{video_link} );
48 # Less hassle than using <title>.
49 $$props->page_title( undef, $tmp->{title} );
51 return (0);
54 return (1);
57 sub _parseConfig {
58 my ( $self, $url, $id ) = @_;
60 my $curl = clive::Curl->instance;
62 my $content;
63 if ( $curl->fetchToMem( $url, \$content, "config" ) == 0 ) {
64 my %re = (
65 sig => qr|<request_signature>(.*?)</request_signature>|,
66 sig_exp =>
67 qr|request_signature_expires>(.*?)</request_signature_expires>|
70 my $tmp;
71 if ( clive::Util::matchRegExps( \%re, \$tmp, \$content ) == 0 ) {
72 my $xurl = "http://vimeo.com/moogaloop/play/clip:$id"
73 . "/$tmp->{sig}/$tmp->{sig_exp}";
74 my $config = clive::Config->instance->config;
75 if ( $config->{format} eq "hd"
76 || $config->{format} eq "best" )
78 my $hd_avail = $1
79 if ( $content =~ /<hd_button>(.*?)<\/hd_button>/ );
80 $xurl .= "/?q=hd"
81 if ( $hd_avail && $hd_avail eq "1" );
83 $self->{video_link} = $xurl;
84 return (0);
87 return (1);
92 # So let us not talk falsely now.