1 # -*- coding: ascii -*-
2 ###########################################################################
3 # clive, command line video extraction utility.
5 # Copyright 2009,2010 Toni Gundogdu.
7 # This file is part of clive.
9 # clive is free software: you can redistribute it and/or modify it under
10 # the terms of the GNU General Public License as published by the Free
11 # Software Foundation, either version 3 of the License, or (at your option)
14 # clive is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 # You should have received a copy of the GNU General Public License along
20 # with this program. If not, see <http://www.gnu.org/licenses/>.
21 ###########################################################################
22 package clive
::Host
::Youtube
;
27 sub new
{ return bless ({}, shift); }
30 my ($self, $content, $props) = @_;
32 $$props->video_host ("youtube");
35 id
=> qr
|&video_id
=(.*?
)&|,
36 fmt_url_map
=> qr
|fmt_url_map
=(.*?
)&|,
40 if (clive
::Util
::matchRegExps
(\
%re, \
$tmp, $content) == 0) {
47 foreach (split /,/, URI
::Escape
::uri_unescape
($tmp->{fmt_url_map
})) {
48 my ($id, $url) = split /\|/, $_;
49 $best = $url unless $best;
55 my $config = clive
::Config
->instance->config;
57 if ($config->{format
} eq 'best') {
61 $url = toURL
($self, $config->{format
}, \
%h);
62 $url = toURL
($self, 'default', \
%h) unless $url;
65 $$props->video_id ($tmp->{id
});
66 $$props->video_link ($url);
75 my ($self, $fmt, $h) = @_;
77 $fmt = 'flv_240p' if $fmt eq 'default';
78 $fmt = toFmt
($self, $fmt);
81 { return $$h{$_} if $_ eq $fmt; }
89 # http://en.wikipedia.org/wiki/YouTube#Quality_and_codecs
90 # $container_$maxwidth = '$fmt_id'
108 # For backward-compatibility only.
124 { return $h{$_} if $id eq $_; }
131 # And this is not our fate.