# HG changeset patch # User morphbr # Date 1179236464 -3600 # Node ID 76a3f315ef428aacf4f8dd96d735e6de2949d029 # Parent 1d8c80fdd4305238b88b3f6931c2d03669293a02 [svn r657] * GMyth-Streamer - Updated to get status (mencoder) diff -r 1d8c80fdd430 -r 76a3f315ef42 gmyth-stream/server/0.2/lib/utils.py --- a/gmyth-stream/server/0.2/lib/utils.py Mon May 14 23:41:05 2007 +0100 +++ b/gmyth-stream/server/0.2/lib/utils.py Tue May 15 14:41:04 2007 +0100 @@ -159,3 +159,16 @@ return "HTML format error. Wrong keys: %s" % e # getHTML + +def progress_bar(log, value, max, barsize): + chars = int(value * barsize / float(max)) + percent = int((value / float(max)) * 100) + sys.stdout.write("#" * chars) + sys.stdout.write(" " * (barsize - chars + 2)) + if value >= max: + sys.stdout.write("done. \n\n") + else: + sys.stdout.write("[%3i%%]\r" % (percent)) + sys.stdout.flush() + +# progress_bar by osantana diff -r 1d8c80fdd430 -r 76a3f315ef42 gmyth-stream/server/0.2/plugins/transcoders/mencoder.py --- a/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py Mon May 14 23:41:05 2007 +0100 +++ b/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py Tue May 15 14:41:04 2007 +0100 @@ -3,6 +3,7 @@ import signal import subprocess import time +import fcntl import lib.utils as utils import lib.server as server @@ -224,6 +225,7 @@ # _start_outfile() def _start(self, outfd): + # Play a file on disk or DVD if not self._run_mencoder(output=subprocess.PIPE): return False @@ -253,42 +255,37 @@ try: self.gmyth = subprocess.Popen(opts, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, close_fds=True) except Exception, e: self.log.error("Error executing gmyth-cat: %s" % e) return False + err = self.gmyth.stderr + if not self._run_mencoder(input=self.gmyth.stdout, output=subprocess.PIPE): return False - show_loading = 0 - show = True - - #n800 150000 and 1000 + if kind == "f": + partial = 0 + size = err.read(20).split("\n")[0].split("Size:")[1] + self.log.debug("Size of file: %s" % size) + flags = fcntl.fcntl (err, fcntl.F_GETFL, 0) | os.O_NONBLOCK + fcntl.fcntl(err, fcntl.F_SETFL, flags) try: while self.proc and self.proc.poll() == None: - - r, w, x = select([self.proc.stdout], [], [], 0) + r, w, x = select([err, self.proc.stdout], [], [], 0) if self.proc.stdout in r: d = self.proc.stdout.read(4096) outfd.write(d) - # self.log.debug("Sending tv data: %d" % show_loading) - # if show_loading > 150000 and show: - # self.log.debug("Disabling loading video") - # show = False - #elif show_loading % 10000 == 0 and show: - # show_loading += 1 - # d = open("loading.mpg") - # outfd.write(d.read()) - # self.log.debug("Sendind loading video: %d" % show_loading) + if err in r and kind == "f": + partial = err.read(50).split("\n")[-2] + if partial != "": + utils.progress_bar(self.log, int(partial), int(size), 50) - #else: - # show_loading += 1 - - #self.log.debug("SHOW_LOADING: %d" % show_loading) except Exception, e: self.log.error("Problems handling data: %s" % e)