On Mon, Jan 24, 2011 at 06:58:22PM -0500, Adrian Irving-Beer wrote:

> I would think we should be consulting the provider modules to
> determine the list of usable formats.  At the very least, the
> Config.pm validation badly needs updating, and the docs need updating
> either way because the "fmt??" formats are all invalid now.

Looking at the recent clive releases there are a bunch of compatiblity
lists in Config.pm though Youtube.pm will then still only fetch the default
format.

I think the best one could do now (for Squeeze) is to update the compatiblity
list in Youtube.pm with the old formats to be at least more consistent with
the manpage.

The interdiff would be rather small 

diff -u b/lib/clive/Host/Youtube.pm b/lib/clive/Host/Youtube.pm
--- b/lib/clive/Host/Youtube.pm
+++ b/lib/clive/Host/Youtube.pm
@@ -118,6 +118,11 @@
         mp4   => "18",
         hq    => "35",
         hd    => "22",
+       fmt22 => "22",
+       fmt35 => "35",
+       fmt18 => "18",
+       fmt34 => "34",
+       fmt17 => "17",
     );
 
     foreach (keys %h)

maybe this can be added in a Squeeze point release in case it's too late now.
At least my guess would be that the release team currently has better things
to do ...

Updated fix-606540-youtube.patch attached.

Sven
-- 
And I don't know much, but I do know this:
With a golden heart comes a rebel fist.
     [ Streetlight Manifesto - Here's To Life ]
Description: Fix broken clive due to youtube changes.
Origin: vendor
Bug: http://sourceforge.net/apps/trac/clive/ticket/1 
Bug-Debian: http://bugs.debian.org/606540
Forwarded: not-needed
Author: Salvatore Bonaccorso <car...@debian.org>
Reviewed-by: Salvatore Bonaccorso <car...@debian.org>
Last-Update: 2010-12-12

--- 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,111 @@ 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($xurl);
+        $$props->video_id ($tmp->{id});
+        $$props->video_link ($url);
 
-        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",
+	fmt22 => "22",
+	fmt35 => "35",
+	fmt18 => "18",
+	fmt34 => "34",
+	fmt17 => "17",
+    );
+
+    foreach (keys %h)
+        { return $h{$_}  if $id eq $_; }
+
+    return $id;
 }
 
 1;

Reply via email to