Fix LiveLeak.pm (#11)
[clive.git] / lib / clive / Host / Liveleak.pm
blob8c304ab45230d0a3ffe375d820baeda60146241f
1 # -*- coding: ascii -*-
2 ###########################################################################
3 # clive, command line video extraction utility.
5 # Copyright 2009 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)
12 # any later version.
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
17 # details.
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::Liveleak;
24 use warnings;
25 use strict;
27 sub new {
28 return bless( {}, shift );
31 sub parsePage {
32 my ( $self, $content, $props ) = @_;
34 $$props->video_host("liveleak");
36 my %re = (
37 id => qr|token=(.*?)['&]|,
38 config => qr|config: "(.*?)"|,
41 my $tmp;
42 if ( clive::Util::matchRegExps( \%re, \$tmp, $content ) == 0 ) {
43 if ( _parseConfig( $self, $tmp->{config} ) == 0 ) {
44 $$props->video_id( $tmp->{id} );
45 $$props->video_link( $self->{video_link} );
46 return (0);
49 return (1);
52 sub _parseConfig {
53 my ( $self, $url ) = @_;
55 require URI::Escape;
56 $url = URI::Escape::uri_unescape($url);
58 my $curl = clive::Curl->instance;
59 my $log = clive::Log->instance;
61 my $content;
62 if ( $curl->fetchToMem( $url, \$content, "config" ) == 0 ) {
63 my %re = ( file => qr|<file>(.*?)</file>| );
64 my $tmp;
65 if ( clive::Util::matchRegExps( \%re, \$tmp, \$content ) == 0 ) {
66 $self->{video_link} = $tmp->{file};
67 $self->{video_link} =~ tr/ //d;
68 return (0);
71 return (1);
76 # There are many here among us.