[SCM] Video extraction utility for YouTube, Google Video and other video sites (Debian packaging) branch, master, updated. upstream/2.1.9-120-g5cdb4a5

Damyan Ivanov dmn at debian.org
Thu Apr 9 07:26:02 UTC 2009


The following commit has been merged in the master branch:
commit a62417dbb1fb96cd99ab29e95f7f9e9fbaa2f92a
Author: Damyan Ivanov <dmn at debian.org>
Date:   Thu Apr 9 10:11:03 2009 +0300

    Imported Upstream version 2.1.10

diff --git a/clive b/clive
index 32a4e7e..444732d 100755
--- a/clive
+++ b/clive
@@ -21,7 +21,7 @@
 use warnings;
 use strict;
 
-use constant VERSION         => "2.1.9";
+use constant VERSION         => "2.1.10";
 use constant MBDIV           => 0x100000;
 use constant SHOWFMT_DEFAULT => qq/%D: "%t" | %mMB/;
 
@@ -86,8 +86,21 @@ my %re_hosts = (        # Precompiled regex used to identify the host
                  IsLiveleak  => qr|liveleak.com|i,
                  IsEvisor    => qr|evisor.tv|i,
                  IsDmotion   => qr|dailymotion.com|i,
+                 IsCctv      => qr|tv.cctv.com|i,
                );
 
+my @re_hosts_arr = (
+                    [$re_hosts{IsYoutube},   \&handle_youtube],
+                    [$re_hosts{IsGoogle},    \&handle_google],
+                    [$re_hosts{IsSevenload}, \&handle_sevenload],
+                    [$re_hosts{IsBreak},     \&handle_break],
+                    [$re_hosts{IsLastfm},    \&handle_lastfm],
+                    [$re_hosts{IsLiveleak},  \&handle_liveleak],
+                    [$re_hosts{IsEvisor},    \&handle_evisor],
+                    [$re_hosts{IsDmotion},   \&handle_dmotion],
+                    [$re_hosts{IsCctv},      \&handle_cctv],
+                   );
+
 # Parse config
 my $c = Config::Tiny->read($CONFIGFILE);
 %opts = (
@@ -122,7 +135,8 @@ GetOptions(
     'output|o=s', 'append|a=s', 'background|b', 'quiet|q',
     'grep|g=s',   'agent|U=s',  'proxy|y=s',    'savedir|S=s',
     'cclass|l=s', 'exec|x=s',   'progress|G=s', 'clivepass|V=s',
-    'stream=i',
+    'stream=i',   'stderr',
+    'hosts'     => \&print_hosts,
     'version|v' => \&print_version,
 
     # Workarounds since $longopt!|$shortopt cannot be used.
@@ -322,44 +336,29 @@ sub process_page
 {
     my ($url, $response_ref, $response_fh) = @_;
 
-    print "done.\nprocess page ..."
-      unless $opts{quiet};
-
-    $$response_ref =~ tr{\n}//d;
+    #$$response_ref =~ tr{\n}//d;
 
     my $p = HTML::TokeParser->new($response_ref);
     $p->get_tag("title");
     my $title = $p->get_trimmed_text;
 
-    my ($xurl, $id);
-    if ($url =~ /$re_hosts{IsYoutube}/)
-    {
-        ($xurl, $id) = handle_youtube($response_ref);
-    }
-    elsif ($url =~ /$re_hosts{IsGoogle}/)
-    {
-        ($xurl, $id) = handle_google($response_ref);
-    }
-    elsif ($url =~ /$re_hosts{IsSevenload}/)
-    {
-        ($xurl, $id) = handle_sevenload($response_ref, $response_fh);
-    }
-    elsif ($url =~ /$re_hosts{IsBreak}/)
-    {
-        ($xurl, $id, $title) = handle_break($response_ref);
-    }
-    elsif ($url =~ /$re_hosts{IsLiveleak}/)
-    {
-        ($xurl, $id) = handle_liveleak($response_ref, $response_fh);
-    }
-    elsif ($url =~ /$re_hosts{IsEvisor}/)
+    my ($xurl, $id, $_title, $supported);
+    $supported = 0;
+    foreach (@re_hosts_arr)
     {
-        ($xurl, $id) = handle_evisor($response_ref);
-    }
-    elsif ($url =~ /$re_hosts{IsDmotion}/)
-    {
-        ($xurl, $id) = handle_dmotion($response_ref);
+        my ($re, $handler) = @{$_};
+        if ($url =~ /$re/)
+        {
+            $supported = 1;
+            ($xurl, $id, $_title) =
+              &$handler($response_ref, $response_fh, $url);
+            $title = $_title || $title;
+            last;
+        }
     }
+    die "error: lookup array missing handler; should never get here\n"
+      if !$supported;
+
     return -1
       if !$xurl
           or !$id
@@ -555,7 +554,8 @@ sub extract_video
 
                 # Use 'dot' progress if the output is not a TTY
                 if (    $opts{progress} !~ /^dot/
-                    and $opts{progress} ne 'none')
+                    and $opts{progress} ne 'none'
+                    and !$opts{stderr})
                 {
                     $opts{progress} = 'dot'
                       if !-t STDOUT or !-t STDERR;
@@ -617,9 +617,8 @@ sub extract_video
 
     if (!$errmsg)
     {
-        print "\nclosed http/$rc.\n"
+        c_log("\n")
           unless $opts{quiet};
-
         push @exec_files, $path
           if $opts{exec};
     }
@@ -745,7 +744,7 @@ sub parse_input
 
 sub handle_youtube
 {
-    my ($response_ref, $xurl) = (shift);
+    my ($response_ref, $xurl) = @_;
 
     my %re = (
               GrabID => qr/"video_id": "(.*?)"/,
@@ -783,7 +782,7 @@ sub handle_youtube
 
 sub handle_google
 {
-    my $response_ref = shift;
+    my ($response_ref) = @_;
 
     my %re = (
 
@@ -792,7 +791,7 @@ sub handle_google
         GrabMP4      => qr|href="http://vp\.(.*?)"|,
     );
 
-    my $id  = $1 if $$response_ref =~ /$re{GrabID}/;
+    my $id = $1 if $$response_ref =~ /$re{GrabID}/;
 
     my $xurl = URI::Escape::uri_unescape($1)
       if $$response_ref =~ /$re{GrabVideoURL}/;
@@ -838,7 +837,7 @@ sub handle_sevenload
 
 sub handle_break
 {
-    my $response_ref = shift;
+    my ($response_ref) = @_;
 
     my %re = (
               GrabTitle    => qr|id="vid_title" content="(.*?)"|,
@@ -916,7 +915,7 @@ sub handle_liveleak
 
 sub handle_evisor
 {
-    my $respr = shift;
+    my ($respr) = @_;
 
     my %re = (
               GrabXurl => qr|file=(.*?)"|,
@@ -945,7 +944,7 @@ sub handle_evisor
 
 sub handle_dmotion
 {
-    my $resp = shift;
+    my ($resp) = @_;
 
     my %re = (
               GrabID    => qr|swf%2F(.*?)"|,
@@ -1366,11 +1365,22 @@ sub main
     select STDOUT;
     $| = 1;
 
-    daemonize()
-      if $opts{background};
+    if ($opts{background})
+    {
+        daemonize();
+    }
+    else
+    {
+        if ($opts{stderr})
+        {
 
-    process_queue();
+            # redirect stdout to stderr
+            open STDOUT, ">&STDERR"
+              or die "error: cannot dup STDOUT: $!";
+        }
+    }
 
+    process_queue();
     free_cache();
 
     exit($err_flag);
@@ -1693,21 +1703,14 @@ sub title_to_filename
 {
     my $title = shift;
 
-    $title =~ s/(youtube|video|liveleak.com|sevenload|dailymotion)//gi;
+    $title =~
+      s/(youtube|video|liveleak.com|sevenload|dailymotion|cctv.com)//gi;
     $title =~ s/^\s+//;
     $title =~ s/\s+$//;
 
     my $r = $opts{cclass} || qr|\w|;
     $title = join('', $title =~ /$r/g);
 
-    # Courtesy of:
-    #   http://search.cpan.org/~gaas/URI-1.37/URI.pm#PARSING_URIs_WITH_REGEXP
-    my ($scheme, $authority, $path, $query, $fragment) =
-      m{(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?}o;
-
-    # Extract the domain from the URL.
-    my @a = split(/\./, $authority);
-
     my $fn = $opts{fnfmt} || "%t_%d_%i.%s";
     my $timestamp = POSIX::strftime("%F %T", localtime);
 
@@ -2013,7 +2016,7 @@ sub print_version
         $str .= "\n" if (++$i % 2 == 0);
     }
     $str .=
-      "clive is licensed under the ISC license which is functionally\n"
+      "\nclive is licensed under the ISC license which is functionally\n"
       . "equivalent to the 2-clause BSD licence.\n"
       . "\tReport bugs: <http://code.google.com/p/clive/issues/>\n";
     print("$str");
@@ -2030,6 +2033,7 @@ clive [options]... [URL]...
 
  -h, --help                 print help and exit
  -v, --version              print version and exit
+     --hosts                print supported hosts and exit
  -b, --background           go to background after startup
  -e, --emit-csv             emit video details as csv to stdout
  -E, --emit-xml             emit video details as csv to stdout
@@ -2054,6 +2058,7 @@ Logging and Input Options:
  -r, --recall               recall last url batch
  -T, --savebatch=FILE       save url batch to FILE
  -p, --paste                paste input from clipboard
+     --stderr               redirect all output to stderr even when no tty
 Download Options:
  -O, --output-video=FNAME   write video to file
  -n, --no-extract           do not extract any videos
diff --git a/clive.1 b/clive.1
index d30e558..2fe3b93 100644
--- a/clive.1
+++ b/clive.1
@@ -1,4 +1,4 @@
-.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.35
+.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05)
 .\"
 .\" Standard preamble:
 .\" ========================================================================
@@ -25,11 +25,11 @@
 ..
 .\" Set up some character translations and predefined strings.  \*(-- will
 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
-.\" double quote, and \*(R" will give a right double quote.  | will give a
-.\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used to
-.\" do unbreakable dashes and therefore won't be available.  \*(C` and \*(C'
-.\" expand to `' in nroff, nothing in troff, for use with C<>.
-.tr \(*W-|\(bv\*(Tr
+.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
+.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
+.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
+.\" nothing in troff, for use with C<>.
+.tr \(*W-
 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
 .ie n \{\
 .    ds -- \(*W-
@@ -48,22 +48,25 @@
 .    ds R" ''
 'br\}
 .\"
+.\" Escape single quotes in literal strings from groff's Unicode transform.
+.ie \n(.g .ds Aq \(aq
+.el       .ds Aq '
+.\"
 .\" If the F register is turned on, we'll generate index entries on stderr for
 .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
 .\" entries marked with X<> in POD.  Of course, you'll have to process the
 .\" output yourself in some meaningful fashion.
-.if \nF \{\
+.ie \nF \{\
 .    de IX
 .    tm Index:\\$1\t\\n%\t"\\$2"
 ..
 .    nr % 0
 .    rr F
 .\}
-.\"
-.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
-.\" way too many mistakes in technical documents.
-.hy 0
-.if n .na
+.el \{\
+.    de IX
+..
+.\}
 .\"
 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
@@ -145,7 +148,7 @@ clive is a command line utility for extracting videos from Youtube and other
 video sharing Web sites. It was originally written to bypass the Adobe Flash
 requirement needed to view the hosted videos.
 .PP
-clive can be non\-interactive. This means it can work in the background
+clive can be non-interactive. This means it can work in the background
 while the user is not logged on, allowing the user to start an extraction
 and disconnect from the system and letting clive finish the work.
 .PP
@@ -171,6 +174,9 @@ Print this help and exit.
 .IP "\fB\-v \-\-version\fR" 4
 .IX Item "-v --version"
 Print version and exit.
+.IP "\fB\-\-hosts\fR" 4
+.IX Item "--hosts"
+Print supported hosts and exit.
 .IP "\fB\-b \-\-background\fR" 4
 .IX Item "-b --background"
 Go to background immediately after startup. If no output file is specified
@@ -264,11 +270,14 @@ Recall the last \s-1URL\s0 batch from the previous runtime. Note that clive over
 this information at every runtime. See also \*(L"\s-1CACHE\s0\*(R".
 .IP "\fB\-T \-\-savebatch=\fR\fIfile\fR" 4
 .IX Item "-T --savebatch=file"
-Save current \s-1URL\s0 batch to \fIfile\fR. 
+Save current \s-1URL\s0 batch to \fIfile\fR.
 .IP "\fB\-p \-\-paste\fR" 4
 .IX Item "-p --paste"
 Paste input from clipboard. The pasted URLs are expected to be separated with
 newlines.
+.IP "\fB\-\-stderr\fR" 4
+.IX Item "--stderr"
+Redirect all input to stderr, even if no \s-1TTY\s0 is available.
 .PP
 \&\fBDownload Options\fR
 .IP "\fB\-O \-\-output\-video=\fR\fIfile\fR" 4
@@ -317,7 +326,7 @@ Progress indication can be disabled completely by setting \fItype\fR to \*(L"non
 .IP "\fB\-u \-\-youtube\-user=\fR\fIusername\fR" 4
 .IX Item "-u --youtube-user=username"
 \&\fIusername\fR to log into Youtube. Typically needed only if you are planning
-to extract videos flagged as mature\-content.
+to extract videos flagged as mature-content.
 .IP "\fB\-t \-\-youtube\-pass=\fR\fIpassword\fR" 4
 .IX Item "-t --youtube-pass=password"
 \&\fIpassword\fR to log into Youtube. If \fIpassword\fR is \*(L"\-\*(R", causes clive to
@@ -509,11 +518,14 @@ Formats: (spark|spak\-mini|vp6\-hq|vp6\-hd|vp6|h264)  Continue: Yes
 .Sp
 spark is the \*(L"regular\*(R" 320x240 flv. \fBclive\fR defaults to spark
 if requested format is not available.
+.IP "\fBtv.cctv.com\fR" 4
+.IX Item "tv.cctv.com"
+Formats: flv  Continue: Yes
 .SH "CACHE"
 .IX Header "CACHE"
 The cache has two purposes:
 .IP "1." 4
-Keep reusable video data available for fast re\-extraction.
+Keep reusable video data available for fast re-extraction.
 .IP "2." 4
 Keep a record of extracted videos.
 .PP
@@ -575,7 +587,7 @@ Development repository can be cloned with:
 For release announcements, subscribe to the project at:
   <http://freshmeat.net/projects/clive/>
 .PP
-Additional utilities (clive\-utils):
+Additional utilities (clive-utils):
   <http://code.google.com/p/clive\-utils/>
 .SH "AUTHOR"
 .IX Header "AUTHOR"
diff --git a/clive.pod b/clive.pod
index 13de351..dac7acb 100644
--- a/clive.pod
+++ b/clive.pod
@@ -44,6 +44,10 @@ Print this help and exit.
 
 Print version and exit.
 
+=item B<--hosts>
+
+Print supported hosts and exit.
+
 =item B<-b --background>
 
 Go to background immediately after startup. If no output file is specified
@@ -175,6 +179,10 @@ Save current URL batch to I<file>.
 Paste input from clipboard. The pasted URLs are expected to be separated with
 newlines.
 
+=item B<--stderr>
+
+Redirect all input to stderr, even if no TTY is available.
+
 =back
 
 B<Download Options>
@@ -478,6 +486,10 @@ Formats: (spark|spak-mini|vp6-hq|vp6-hd|vp6|h264)  Continue: Yes
 spark is the "regular" 320x240 flv. B<clive> defaults to spark
 if requested format is not available.
 
+=item B<tv.cctv.com>
+
+Formats: flv  Continue: Yes
+
 =back
 
 =head1 CACHE
diff --git a/tests/cctv.url b/tests/cctv.url
new file mode 100644
index 0000000..30ee3e0
--- /dev/null
+++ b/tests/cctv.url
@@ -0,0 +1 @@
+http://space.tv.cctv.com/video/VIDE1212909276513233

-- 
Video extraction utility for YouTube, Google Video and other video sites (Debian packaging)



More information about the Pkg-perl-cvs-commits mailing list