Fix dmotion id parsing.
[clive.git] / lib / clive / Host / Dailymotion.pm
blob080ea84e5af91a3f97ddbc4a1ebb70d41b619fc2
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::Dailymotion;
24 use warnings;
25 use strict;
27 use clive::Error qw(CLIVE_FORMAT);
29 # ON2-1280x720 (vp6-hd)
30 # ON2-848x480 (vp6-hq)
31 # H264-512x384 (h264)
32 # ON2-320x240 (vp6)
33 # FLV-320x240 (spark)
34 # FLV-80x60 (spak-mini)
36 sub new {
37 return bless( {}, shift );
40 sub parsePage {
41 my ( $self, $content, $props ) = @_;
43 $$props->video_host("dailymotion");
45 my %re = (
46 id => qr|video/(.*?)_|,
47 paths => qr|"video", "(.*?)"|
50 my $tmp;
51 if ( clive::Util::matchRegExps( \%re, \$tmp, $content ) == 0 ) {
53 require URI::Escape;
54 my $paths = URI::Escape::uri_unescape( $tmp->{paths} );
55 my $config = clive::Config->instance->config;
57 my $format = $config->{format};
58 $format = "spark" if ( $format eq "flv" );
60 my %width;
61 my $xurl;
63 foreach ( split( /\|\|/, $paths ) ) {
64 my ( $path, $type ) = split(/@@/);
66 $width{$2} = $path
67 if ( $path =~ /cdn\/(.*)-(.*?)x/ );
69 if ( lc($type) eq $format
70 && $format ne "best" )
72 $xurl = $path;
73 last;
77 if ( $format eq "best" ) {
79 # Sort by width to descending order, assume [0] to be the best.
80 my $best = ( sort { $b <=> $a } keys %width )[0];
81 $xurl = $width{$best};
84 if ($xurl) {
85 $$props->video_id( $tmp->{id} );
86 $$props->video_link($xurl);
87 return (0);
89 else {
90 clive::Log->instance->err( CLIVE_FORMAT,
91 "format unavailable: `$format'" );
94 return (1);
99 # Nobody of it is worth.