[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#606765: possible unblock: clive/2.2.13-4



Package: release.debian.org
Severity: normal
User: release.debian.org@packages.debian.org
Usertags: unblock

Dear Release Team

Again changes in youtube broke clive, this is [1]. Upstream alredy
provided a preliminary fix, but it is not yet relased [2]. I attach
patch against current 2.2.13-3 in unstable and testing with upstream
fixes to Youtube.pm.

Would you accept this fix? I however would like to wait for upstreams
defintive fix for it, but I do not expect to have much more change as
it is now.

 [1] http://bugs.debian.org/606540
 [2] http://sourceforge.net/apps/trac/clive/ticket/1

Bests
Salvatore

-- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.26-2-amd64 (SMP w/8 CPU cores)
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Shell: /bin/sh linked to /bin/dash
diff --git a/lib/clive/Host/Youtube.pm b/lib/clive/Host/Youtube.pm
index e922d9a..290d230 100644
--- a/lib/clive/Host/Youtube.pm
+++ b/lib/clive/Host/Youtube.pm
@@ -2,7 +2,7 @@
 ###########################################################################
 # clive, command line video extraction utility.
 #
-# Copyright 2009 Toni Gundogdu.
+# Copyright 2009,2010 Toni Gundogdu.
 #
 # This file is part of clive.
 #
@@ -24,74 +24,106 @@ package clive::Host::Youtube;
 use warnings;
 use strict;
 
-# fmt22 = HD    [1280x720]
-# fmt35 = HQ     [640x380]
-# fmt17 = 3gp    [176x144]
-# fmt18 = mp4    [480x360]
-# fmt34 = flv    [320x180] (quality reportedly varies)
-
-# If --format is unused, clive defaults to whatever youtube
-# defaults to: we do not append the "&fmt=" to the video link.
-
-sub new {
-    return bless( {}, shift );
-}
+sub new { return bless ({}, shift); }
 
 sub parsePage {
-    my ( $self, $content, $props ) = @_;
+    my ($self, $content, $props) = @_;
 
-    $$props->video_host("youtube");
+    $$props->video_host ("youtube");
 
     my %re = (
         id => qr|&video_id=(.*?)&|,
-        t  => qr|&t=(.*?)&|,
+        fmt_url_map => qr|fmt_url_map=(.*?)&|,
     );
 
     my $tmp;
-    if ( clive::Util::matchRegExps( \%re, \$tmp, $content ) == 0 ) {
+    if (clive::Util::matchRegExps (\%re, \$tmp, $content) == 0) {
 
-        require URI::Escape;
+        my $best;
+        my %h;
 
-        $tmp->{t} = URI::Escape::uri_unescape($tmp->{t});
+        require URI::Escape;
 
-        my $xurl
-            = "http://youtube.com/get_video?video_id=$tmp->{id}&t=$tmp->{t}";
+        foreach (split /,/, URI::Escape::uri_unescape ($tmp->{fmt_url_map})) {
+            my ($id, $url) = split /\|/, $_;
+            $best   = $url unless $best;
+            $h{$id} = $url;
+        }
 
-        $xurl .= "&asv=2"; # Should fix the http/404 issue (#58).
+        my $url;
 
         my $config = clive::Config->instance->config;
 
-        my $fmt;
-
-        if ( $config->{format} eq "best" ) {
-            $fmt = $1
-                if ( $$content =~ /&fmt_map=(\d+)/ && $1 ne "" );
+        if ($config->{format} eq 'best') {
+            $url = $best;
         }
         else {
-            $fmt = $1
-                if toFmt( $self, $config->{format} ) =~ /^fmt(.*)$/;
+            $url = toURL ($self, $config->{format}, \%h);
+            $url = toURL ($self, 'default', \%h)  unless $url;
         }
 
-        $xurl .= "&fmt=$fmt"
-            if $fmt;
+        $$props->video_id ($tmp->{id});
+        $$props->video_link ($url);
 
-        $$props->video_id( $tmp->{id} );
-        $$props->video_link($xurl);
-
-        return (0);
+        return 0;
     }
-    return (1);
+
+    return 1;
+}
+
+sub toURL {
+    my ($self, $fmt, $h) = @_;
+
+    $fmt = 'flv_240p'  if $fmt eq 'default';
+    $fmt = toFmt ($self, $fmt);
+
+    foreach (keys %{$h})
+        { return $$h{$_}  if $_ eq $fmt; }
+
+    return undef;
 }
 
 sub toFmt {
-    my ( $self, $id ) = @_;
-    $id =~ s/hd/fmt22/;
-    $id =~ s/hq/fmt35/;
-    $id =~ s/mp4/fmt18/;
-
-    #    $id =~ s/fmt34/flv/; # Previously assumed to be the "youtube default format"
-    $id =~ s/3gp/fmt17/;
-    return ($id);
+    my ($self, $id) = @_;
+
+# http://en.wikipedia.org/wiki/YouTube#Quality_and_codecs
+# $container_$maxwidth = '$fmt_id'
+
+    my %h = (
+        # flv
+        flv_240p => '5',
+        flv_360p => '34',
+        flv_480p => '35',
+        # mp4
+        mp4_360p  => '18',
+        mp4_720p  => '22',
+        mp4_1080p => '37',
+        mp4_3072p => '38',
+        # webm
+        webm_480p => '43',
+        webm_720p => '45',
+        # 3gp
+        '3gp_144p'=> '17',
+
+# For backward-compatibility only.
+        mobile    => '17',
+        sd_270p   => "18",
+        sd_360p   => "34",
+        hq_480p   => "35",
+        hd_720p   => "22",
+        hd_1080p  => "37",
+        webm_480p => "43",
+        webm_720p => "45",
+        '3gp' => "17",
+        mp4   => "18",
+        hq    => "35",
+        hd    => "22",
+    );
+
+    foreach (keys %h)
+        { return $h{$_}  if $id eq $_; }
+
+    return $id;
 }
 
 1;

Reply to: