perltidy.
[clive.git] / lib / clive / Host / Golem.pm
blobb8de44f999a7aef29f3a4811b4bbf834d95d3e63
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::Golem;
23 use warnings;
24 use strict;
26 # --format=(high|medium|ipod)
27 # high = hd
28 # medium = default (what we call "flv" in clive)
29 # ipod = ipod
31 # Note that we do not use "medium" at all. The host
32 # defaults to "medium" if "?q=" is not appended.
33 # Users do not need to bother themselves with this.
35 # We use config:title instead of video page title
36 # if it can be parsed from the config. Saves us
37 # the trouble from cleaning up the <title>.
39 sub new {
40 return bless( {}, shift );
43 sub parsePage {
44 my ( $self, $content, $props ) = @_;
46 $$props->video_host("golem");
48 my %re = ( id => qr|"id", "(.*?)"| );
50 my $tmp;
51 if ( clive::Util::matchRegExps( \%re, \$tmp, $content ) == 0 ) {
52 my $url = "http://video.golem.de/xml/$tmp->{id}";
53 if ( _fetchConfig( $self, $url, $tmp->{id} ) == 0 ) {
55 $$props->page_title( undef, $self->{page_title} )
56 if ( $self->{page_title} );
58 $$props->video_id( $tmp->{id} );
59 $$props->video_link( $self->{video_link} );
61 return (0);
64 return (1);
67 sub _fetchConfig {
68 my ( $self, $url, $id ) = @_;
70 my $curl = clive::Curl->instance;
72 my $content;
73 if ( $curl->fetchToMem( $url, \$content, "config" ) == 0 ) {
75 my $xurl = "http://video.golem.de/download/$id";
76 my $config = clive::Config->instance->config;
78 my $title = $1
79 if ( $content =~ /<title>(.*?)<\/title>/ );
81 my $fmt;
82 if ( $config->{format} eq "best" ) {
84 my %re = ( path => qr|<filename>(.*?)</filename>| );
85 my @fnames = $content =~ /$re{path}/g;
87 foreach my $i (qw/hd sd ipod/) {
88 if ( my @b = grep( /$i/, @fnames ) ) {
89 $fmt = $b[0];
90 last;
94 $fmt =~ s/hd/high/;
95 $fmt =~ s/sd//; # medium
97 else {
98 $fmt = $config->{format};
99 $fmt =~ s/flv//; # medium (default)
102 $xurl .= "?q=$fmt"
103 if $fmt;
105 $self->{page_title} = $title;
106 $self->{video_link} = $xurl;
108 return (0)
109 if $xurl;
111 return (1);
116 # And the wind began to howl.