[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:45:00 UTC 2009


The following commit has been merged in the master branch:
commit 4cf871736b58a423858717685eb4f0a1aa35481f
Author: legatvs <legatvs at gmail.com>
Date:   Sat Mar 14 19:45:47 2009 +0200

    Add SIGWINCH handling for resizing progressbar.

diff --git a/CHANGES b/CHANGES
index b91dc08..ee12435 100644
--- a/CHANGES
+++ b/CHANGES
@@ -12,6 +12,10 @@ Version 2.1.7
   * Change default filename format to "%t_%d_%i.%s"
   * Change to "file is already fully retrieved" error message
   * Port progressbar from cclive
+  * Port SIGWINCH handling from cclive
+    - progressbar resizes matching terminal width
+    - besides OS must support SIGWINCH, the Term::ReadKey module is required
+    - progressbar defaults to 80 (chars)
 
  Developer-visible changes:
   * Add tests/lastfm.url and tests/multi.lst
diff --git a/INSTALL b/INSTALL
index cf676f6..50494fb 100644
--- a/INSTALL
+++ b/INSTALL
@@ -35,6 +35,7 @@
  - Clipboard (0.09+) # --paste
  - IO::Pager (0.05+) # --show
  - Expect (1.21+)    # --clivepass
+ - Term::ReadKey     # SIGWINCH: resize progressbar to match terminal width
 
  Note that you can install these modules from CPAN, typically (as root):
 
diff --git a/clive b/clive
index bda6689..0f1d4bc 100755
--- a/clive
+++ b/clive
@@ -46,11 +46,12 @@ use constant MBDIV               => 0x100000;
 use constant SHOWFMT_DEFAULT     => qq/%D: "%t" | %mMB/;
 
 # Non-essential modules: set flags indicating availability
-my %opted_mods = (Clipboard => 1, Expect => 1, IOPager => 1);
-eval "use Clipboard;"; $opted_mods{Clipboard}   = 0 if $@;
-eval "use IO::Pager;"; $opted_mods{IOPager}     = 0 if $@;
+my %opted_mods = (Clipboard => 1, Expect => 1, IOPager => 1, ReadKey => 1);
+eval "use Clipboard;";      $opted_mods{Clipboard}  = 0 if $@;
+eval "use IO::Pager;";      $opted_mods{IOPager}    = 0 if $@;
 sub exp_continue() {}; # Satisfies: "Bareword "exp_continue" not allowed while"
-eval "use Expect;"; $opted_mods{Expect}         = 0 if $@;
+eval "use Expect;";         $opted_mods{Expect}     = 0 if $@;
+eval "use Term::ReadKey;";  $opted_mods{ReadKey}    = 0 if $@;
 
 my $CONFIGDIR   = $ENV{CLIVE_HOME}
     || File::Spec->catfile($ENV{HOME}, ".config/clive");
@@ -76,6 +77,8 @@ 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 $recv_sigwinch=0;# whether SIGWINCH was received
+my $term_width;     # current terminal width
 
 my %re_hosts = (    # Precompiled regex used to identify the host
     IsYoutube   => qr|youtube.com|i,
@@ -143,6 +146,15 @@ pod2usage(-exitstatus => 0, -verbose => 1) if $opts{help};
 
 main();
 
+
+## Subroutines: Signal handlers
+
+sub handle_sigwinch {
+#    my $sign = shift;
+    $recv_sigwinch = 1;
+}
+
+
 ## Subroutines: Connection
 
 sub init_curl {
@@ -907,12 +919,21 @@ sub dot_print_row_stats {
 
 use constant DEFAULT_TERM_WIDTH => 80;
 
+sub get_term_width {
+    return DEFAULT_TERM_WIDTH
+        unless $opted_mods{ReadKey};
+    my ($width) = GetTerminalSize();
+    return $width;
+}
+
 sub bar_init {
     my ($initial, $total) = @_;
 
     $total = $initial
         if $initial > $total;
 
+    $term_width  = get_term_width();
+
     $bp{initial} = $initial; # bytes dl previously
     $bp{total}   = $total;   # expected bytes
     $bp{width}   = DEFAULT_TERM_WIDTH-1;
@@ -926,9 +947,19 @@ use constant REFRESH_INTERVAL => 0.2;
 sub bar_update {
     my ($clientp, $total, $now, $ultotal, $ulnow) = @_;
 
+    my $force_update = 0;
+    if ($recv_sigwinch) {
+        my $old_width = $term_width;
+        $term_width = get_term_width();
+        if ($term_width != $old_width) {
+            $bp{width} = $term_width - 1;
+            $force_update = 1;
+        }
+        $recv_sigwinch = 0;
+    }
+
     my $tnow        = time;
     my $elapsed     = $tnow - $bp{started};
-    my $force_update= 0;
 
     if (!$bp{done}) {
         return 0
@@ -1063,6 +1094,7 @@ sub get_units {
 # Subroutines: LittleHelpers
 
 sub main {
+    $SIG{WINCH} = \&handle_sigwinch;
     init_cache();
 
     if      ( $opts{clear} ) { clear_cache(); }
@@ -1548,9 +1580,10 @@ sub print_version {
 
 sub print_version_mods {
     my $perl_v      = sprintf "%vd", $^V;
-    my $clipboard_v = $opted_mods{Clipboard} ? $Clipboard::VERSION  : "-";
-    my $expect_v    = $opted_mods{Expect}    ? $Expect::VERSION     : "-";
-    my $iopager_v   = $opted_mods{IOPager}   ? $IO::Pager::VERSION  : "-";
+    my $clipboard_v = $opted_mods{Clipboard} ? $Clipboard::VERSION      : "-";
+    my $expect_v    = $opted_mods{Expect}    ? $Expect::VERSION         : "-";
+    my $iopager_v   = $opted_mods{IOPager}   ? $IO::Pager::VERSION      : "-";
+    my $readkey_v   = $opted_mods{ReadKey}   ? $Term::ReadKey::VERSION  : "-";
 print
 " * Perl/$perl_v
 Modules:
@@ -1558,7 +1591,7 @@ Modules:
  * WWW::Curl/$WWW::Curl::VERSION\t\t* Expect/$expect_v
  * HTML::TokeParser/$HTML::TokeParser::VERSION\t* Clipboard/$clipboard_v
  * XML::Simple/$XML::Simple::VERSION\t\t* IO::Pager/$iopager_v
- * URI::Escape/$URI::Escape::VERSION
+ * URI::Escape/$URI::Escape::VERSION\t\t* Term::ReadKey/$readkey_v
 Core modules:
  * POSIX/$POSIX::VERSION\t\t\t* Cwd/$Cwd::VERSION
  * Getopt::Long/$Getopt::Long::VERSION\t\t* Pod::Usage/$Pod::Usage::VERSION

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



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