don't block on sucking transcode (but transcode processes still here..)
authorgc <gc>
Tue, 15 Mar 2005 21:58:10 +0000 (21:58 +0000)
committergc <gc>
Tue, 15 Mar 2005 21:58:10 +0000 (21:58 +0000)
booh

diff --git a/booh b/booh
index 19ceb1af7e24fd0cbd7d70209c4d0579e6285529..ce4c15f81f6163b480137533d1ba49382488b6d5 100755 (executable)
--- a/booh
+++ b/booh
@@ -24,6 +24,7 @@ require 'gettext'
 include GetText
 require 'rexml/document'
 include REXML
+require 'timeout'
 
 require 'html_merges'
 
@@ -269,6 +270,19 @@ def entry2type(entry)
     end
 end
 
+#- grab the results of a command but don't sleep forever on a runaway process
+def subproc_runaway_aware(command)
+    begin
+        timeout(5) {
+            return `#{command}`
+        }
+    rescue Timeout::Error    
+        msg 1, _("forgetting runaway process (transcode sucks again?)")
+        #- todo should slay transcode but dunno how to do that
+        return nil
+    end
+end
+
 def gen_thumbnails(orig, dests)
     if !dests.detect { |dest| !File.exists?(dest['filename']) } 
         return true
@@ -296,16 +310,15 @@ def gen_thumbnails(orig, dests)
             if !File.exists?("#{dest_dir}/screenshot.jpg000004.jpg")
                 cmd = "transcode -a 0 -c 0-5 -i '#{orig}' -y jpg -o '#{dest_dir}/screenshot.jpg' 2>&1"
                 msg 2, cmd
-                results = `#{cmd}`
-                if results =~ /V: import format.*unknown/ || !File.exists?("#{dest_dir}/screenshot.jpg000004.jpg")
-                    msg 1, __("could not extract first image of video %s with transcode, will try first converting with mencoder", dest['filename'])
+                if subproc_runaway_aware(cmd) =~ /V: import format.*unknown/ || !File.exists?("#{dest_dir}/screenshot.jpg000004.jpg")
+                    msg 2, __("* could not extract first image of video %s with transcode, will try first converting with mencoder", orig)
                     cmd = "mencoder '#{orig}' -nosound -ovc lavc -lavcopts vcodec=mpeg4 -o '#{dest_dir}/foo.avi' -frames 5 >/dev/null 2>/dev/null"
                     msg 2, cmd
                     system cmd
                     if File.exists?("#{dest_dir}/foo.avi")
                         cmd = "transcode -a 0 -c 0-5 -i '#{dest_dir}/foo.avi' -y jpg -o '#{dest_dir}/screenshot.jpg' 2>&1"
                         msg 2, cmd
-                        results = `#{cmd}`
+                        results = subproc_runaway_aware(cmd)
                         system("rm -f '#{dest_dir}/foo.avi'")
                         if results =~ /V: import format.*unknown/ || !File.exists?("#{dest_dir}/screenshot.jpg000004.jpg")
                             msg 0, __("could not extract first image of video %s encoded by mencoder", "#{dest_dir}/foo.avi")