perltidy.
[clive.git] / lib / clive / Host / Youtube.pm
blobeadb4cce6179f8bc04c152dfd69b754fa055a75e
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::Youtube;
23 use warnings;
24 use strict;
26 # fmt22 = HD[1280x720]
27 # fmt35 = HQ[640x380]
28 # fmt17 = 3gp[176x144]
29 # fmt18 = mp4[480x360]
30 # fmt34 = flv[320x180]
32 sub new {
33 return bless( {}, shift );
36 sub parsePage {
37 my ( $self, $content, $props ) = @_;
39 $$props->video_host("youtube");
41 my %re = (
42 id => qr|"video_id": "(.*?)"|,
43 t => qr|"t": "(.*?)"|,
46 my $tmp;
47 if ( clive::Util::matchRegExps( \%re, \$tmp, $content ) == 0 ) {
49 my $xurl
50 = "http://youtube.com/get_video?video_id=$tmp->{id}&t=$tmp->{t}";
52 my $config = clive::Config->instance->config;
54 my $fmt;
56 if ( $config->{format} eq "best" ) {
57 $fmt = $1
58 if $$content =~ /"fmt_map": "(.*?)\//;
60 else {
61 $fmt = $1
62 if toFmt( $self, $config->{format} ) =~ /^fmt(.*)$/;
65 $xurl .= "&fmt=$fmt"
66 if $fmt;
68 $$props->video_id( $tmp->{id} );
69 $$props->video_link($xurl);
71 return (0);
73 return (1);
76 sub toFmt {
77 my ( $self, $id ) = @_;
78 $id =~ s/hd/fmt22/;
79 $id =~ s/hq/fmt35/;
80 $id =~ s/mp4/fmt18/;
81 $id =~ s/3gp/fmt17/;
82 return ($id);
87 # And this is not our fate.