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

legatvs legatvs at gmail.com
Wed Apr 1 14:44:55 UTC 2009


The following commit has been merged in the master branch:
commit c1027c8bab1b23bd218219696578df3daaf3d6ff
Author: legatvs <legatvs at gmail.com>
Date:   Fri Mar 13 18:25:59 2009 +0200

    Add --stream-exec and --stream options.

diff --git a/clive b/clive
index 47b37a1..14730ab 100755
--- a/clive
+++ b/clive
@@ -75,6 +75,8 @@ my $logfile;        # path to logfile (--output-file, --append-file)
 my %dp;             # dot progress data
 my %bp;             # bar progress data
 my $workdir=getcwd; # startup workdir
+my @stream=(0,-1);  # 0=stream flag, 1=stream pid
+my $curr_fpath;     # current video output filepath
 
 my %re_hosts = (    # Precompiled regex used to identify the host
     IsYoutube   => qr|youtube.com|i,
@@ -89,18 +91,19 @@ my %re_hosts = (    # Precompiled regex used to identify the host
 # Parse config
 my $c = Config::Tiny->read($CONFIGFILE);
 %opts = (
-    progress => $c->{_}->{progress},
-    agent    => $c->{http}->{agent},
-    proxy    => $c->{http}->{proxy},
-    maxspeed => $c->{http}->{maxspeed},
-    minspeed => $c->{http}->{minspeed},
-    savedir  => $c->{output}->{savedir},
-    cclass   => $c->{output}->{cclass},
-    fnfmt    => $c->{output}->{file},
-    showfmt  => $c->{output}->{show},
-    ytuser   => $c->{youtube}->{user},
-    ytpass   => $c->{youtube}->{pass},
-    clivepass=> $c->{commands}->{clivepass},
+    progress    => $c->{_}->{progress},
+    agent       => $c->{http}->{agent},
+    proxy       => $c->{http}->{proxy},
+    maxspeed    => $c->{http}->{maxspeed},
+    minspeed    => $c->{http}->{minspeed},
+    savedir     => $c->{output}->{savedir},
+    cclass      => $c->{output}->{cclass},
+    fnfmt       => $c->{output}->{file},
+    showfmt     => $c->{output}->{show},
+    ytuser      => $c->{youtube}->{user},
+    ytpass      => $c->{youtube}->{pass},
+    clivepass   => $c->{commands}->{clivepass},
+    streamexec  => $c->{commands}->{stream},
 );
 
 $opts{clivepass}    = $ENV{CLIVEPASS_PATH} unless $opts{clivepass};
@@ -117,6 +120,7 @@ GetOptions(\%opts,
     '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',
     'version|v'     => \&print_version,
     'modversion|M', => \&print_version_mods,
     # Commented out until WWW::Curl is fixed:
@@ -133,6 +137,7 @@ GetOptions(\%opts,
     'youtube-pass|t=s',   => sub { $opts{ytpass}    = $_[1] },
     'emit-csv|e',         => sub { $opts{emitcsv}   = 1 },
     'emit-xml|E',         => sub { $opts{emitxml}   = 1 },
+    'stream-exec=s',      => sub { $opts{streamexec}= $_[1] },
 ) or exit(1);
 pod2usage(-exitstatus => 0, -verbose => 1) if $opts{help};
 
@@ -451,6 +456,8 @@ sub extract_video {
             unless $opts{extract};
 
         if ( open my $fh, "$filemode$path" ) {
+            $curr_fpath = $path;
+
             # Disable: encoding, header
             $curl->setopt(CURLOPT_HEADER, 0);
             $curl->setopt(CURLOPT_ENCODING, "identity");
@@ -486,6 +493,7 @@ sub extract_video {
                 if ( $rc == 200 or $rc == 206 ) {
                     if    ( $opts{progress} =~ /^bar/ ) { bar_finish() }
                     elsif ( $opts{progress} =~ /^dot/ ) { dot_finish() }
+                    waitpid($stream[1],0)  if $stream[0];
                 } else {
                     $errmsg = $curl->strerror($rc)." (http/$rc)";
                 }
@@ -790,8 +798,17 @@ sub handle_evisor {
 # NOTE: the 'dot' progress copies much from wget.
 
 sub progress_callback {
-    if    ( $opts{progress} =~ /^dot/ ) { dot_update(@_); }
-    elsif ( $opts{progress} =~ /^bar/ ) { bar_update(@_); }
+    my $percent = 0;
+
+    if    ( $opts{progress} =~ /^dot/ ) { $percent = dot_update(@_); }
+    elsif ( $opts{progress} =~ /^bar/ ) { $percent = bar_update(@_); }
+
+    if ($opts{stream}
+        && $opts{streamexec}
+        && !$stream[0])
+    {
+        fork_streamer()  if $percent >= $opts{stream};
+    }
     return 0;
 }
 
@@ -853,6 +870,7 @@ sub dot_update {
             dot_print_row_stats($percent, $elapsed, $eta, $rate, 0);
         }
     }
+    return $percent;
 }
 
 sub dot_finish {
@@ -905,7 +923,7 @@ sub bar_update { # See no bar, hear no bar, speak no bar.
     my $elapsed = time - $time_started;
 
     if ( !$done ) {
-        return
+        return 0
             if ( $elapsed - $bp{last_update} < BP_REFRESH_INTERVAL);
     } else {
         $dlnow = $bp{total};
@@ -916,8 +934,9 @@ sub bar_update { # See no bar, hear no bar, speak no bar.
     my $size = $bp{initial} + $dlnow;
     my $bar = "";
 
+    my $percent = 0;
     if ( $bp{total} > 0 ) {
-        my $percent = 100.0 * $size / $bp{total};
+        $percent = 100.0 * $size / $bp{total};
         if ( $percent < 100 ) {
             $bar .= sprintf("%2d%% ",$percent);
         } else {
@@ -934,6 +953,7 @@ sub bar_update { # See no bar, hear no bar, speak no bar.
         $bar .= sprintf(" | %8.2fMB ", $size/MBDIV);
         $bar .= sprintf(" | %8.2f%s/s",$rate{rate},$rate{units});
         $bar .= sprintf(" | ETA %-8s", $eta);
+        $percent = $percent_;
     } else {
         $bar .= sprintf(" | %6.2fMB ",$dlnow/MBDIV);
         $bar .= sprintf(" | %8.2f%s/s",0,"K");
@@ -942,6 +962,8 @@ sub bar_update { # See no bar, hear no bar, speak no bar.
 
     $bp{count} = $dlnow;
     print "\r".$bar;
+
+    return $percent;
 }
 
 sub bar_finish { # Never again.
@@ -1136,6 +1158,22 @@ sub daemonize {
         or die "error: cannot dup STDOUT: $!";
 }
 
+sub fork_streamer {
+    $stream[0] = 1; # set flag
+    my $child  = fork;
+
+    if ($child < 0) {
+        print STDERR "error: fork failed: $!\n";
+    } elsif ($child == 0) {
+        my $cmd = $opts{streamexec};
+        $cmd =~ s/%i/"$curr_fpath"/g;
+        system("$cmd");
+        exit(0);
+    }
+
+    $stream[1] = $child;
+}
+
 sub fetch_liveleak_playlist {
     my $playlist_url = shift;
 
@@ -1557,4 +1595,6 @@ clive [options]... [URL]...
  -l, --cclass=CLASS         use CLASS to filter titles
  -N, --filename-format=STR  use STR to construct output filename
  -x, --exec=COMMAND         execute COMMAND subsequently
+     --stream-exec=COMMAND  stream COMMAND to be executed
+     --stream=PERCENT       execute stream command when transfer reaches %
  -V, --clivepass=PATH       path to clivepass
diff --git a/clive.1 b/clive.1
index cfafae2..09c88fe 100644
--- a/clive.1
+++ b/clive.1
@@ -129,7 +129,7 @@
 .\" ========================================================================
 .\"
 .IX Title "clive 1"
-.TH clive 1 "2009-03-13" "2.1.6" "clive manual"
+.TH clive 1 "2009-03-13" "2.1.7" "clive manual"
 .SH "NAME"
 clive \- the non\-interactive video extraction utility
 .SH "SYNOPSIS"
@@ -385,6 +385,32 @@ Example:
 .IX Item "-x, --exec=command+"
 Same as \fB\-\-exec\fR, except that \*(L"%i\*(R" is replaced with as many pathnames
 as possible for the invocation of \fIcommand\fR.
+.IP "\fB\-\-stream\-exec=\fR\fIcommand\fR" 4
+.IX Item "--stream-exec=command"
+Execute \fIcommand\fR when file transfer progress reaches \fIpercent\fR as defined
+with the \fB\-\-stream\fR option. The \*(L"%i\*(R" specifier for video pathname is expected
+to appear somewhere in the \fIcommand\fR expression.
+.Sp
+Unlike the \fB\-\-exec\fR option which is executed subsequently after each file
+transfer, \fBclive\fR forks the streaming process and continues with the file
+transfer \*(-- and will not continue to download another file until the child
+process terminates.
+.Sp
+It should also be noted that \fBclive\fR makes no effort to check whether there
+is enough data to be streamed. It assumes the user knows how much data needs
+to be buffered before starting the child process. Similarly, if the transfer
+rate drops significantly after starting the process and it runs out of data,
+\&\fBclive\fR simply ignores that.
+.Sp
+Some players and formats may not work properly with this feature. Try
+\&\fImplayer\fR\|(1) and choose flv if you are unsure.
+.IP "\fB\-\-stream=\fR\fIpercent\fR" 4
+.IX Item "--stream=percent"
+Execute the \fIcommand\fR defined with the \fB\-\-stream\-exec\fR option when the file
+transfer progress reaches \fIpercent\fR.
+.Sp
+Example:
+  % clive \-\-stream\-exec=\*(L"mplayer \-really\-quiet \f(CW%i\fR\*(R" \-\-stream=20 \s-1URL\s0
 .IP "\fB\-V \-\-clivepass=\fR\fIpath\fR" 4
 .IX Item "-V --clivepass=path"
 \&\fIpath\fR to the \fIclivepass\fR\|(1) utility. If \s-1CLIVEPASS_PATH\s0 environment
diff --git a/clive.pod b/clive.pod
index b31af22..bffb58e 100644
--- a/clive.pod
+++ b/clive.pod
@@ -296,6 +296,34 @@ Example:
 Same as B<--exec>, except that "%i" is replaced with as many pathnames
 as possible for the invocation of I<command>.
 
+=item B<--stream-exec=>I<command>
+
+Execute I<command> when file transfer progress reaches I<percent> as defined
+with the B<--stream> option. The "%i" specifier for video pathname is expected
+to appear somewhere in the I<command> expression.
+
+Unlike the B<--exec> option which is executed subsequently after each file
+transfer, B<clive> forks the streaming process and continues with the file
+transfer -- and will not continue to download another file until the child
+process terminates.
+
+It should also be noted that B<clive> makes no effort to check whether there
+is enough data to be streamed. It assumes the user knows how much data needs
+to be buffered before starting the child process. Similarly, if the transfer
+rate drops significantly after starting the process and it runs out of data,
+B<clive> simply ignores that.
+
+Some players and formats may not work properly with this feature. Try
+L<mplayer(1)> and choose flv if you are unsure.
+
+=item B<--stream=>I<percent>
+
+Execute the I<command> defined with the B<--stream-exec> option when the file
+transfer progress reaches I<percent>.
+
+Example:
+  % clive --stream-exec="mplayer -really-quiet %i" --stream=20 URL
+
 =item B<-V --clivepass=>I<path>
 
 I<path> to the L<clivepass(1)> utility. If CLIVEPASS_PATH environment

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



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