1.1 --- a/gmyth-stream/server/0.2/lib/utils.py Mon May 14 23:41:05 2007 +0100
1.2 +++ b/gmyth-stream/server/0.2/lib/utils.py Tue May 15 14:41:04 2007 +0100
1.3 @@ -159,3 +159,16 @@
1.4 return "HTML format error. Wrong keys: %s" % e
1.5
1.6 # getHTML
1.7 +
1.8 +def progress_bar(log, value, max, barsize):
1.9 + chars = int(value * barsize / float(max))
1.10 + percent = int((value / float(max)) * 100)
1.11 + sys.stdout.write("#" * chars)
1.12 + sys.stdout.write(" " * (barsize - chars + 2))
1.13 + if value >= max:
1.14 + sys.stdout.write("done. \n\n")
1.15 + else:
1.16 + sys.stdout.write("[%3i%%]\r" % (percent))
1.17 + sys.stdout.flush()
1.18 +
1.19 +# progress_bar by osantana
2.1 --- a/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py Mon May 14 23:41:05 2007 +0100
2.2 +++ b/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py Tue May 15 14:41:04 2007 +0100
2.3 @@ -3,6 +3,7 @@
2.4 import signal
2.5 import subprocess
2.6 import time
2.7 +import fcntl
2.8
2.9 import lib.utils as utils
2.10 import lib.server as server
2.11 @@ -224,6 +225,7 @@
2.12 # _start_outfile()
2.13
2.14 def _start(self, outfd):
2.15 + # Play a file on disk or DVD
2.16 if not self._run_mencoder(output=subprocess.PIPE):
2.17 return False
2.18
2.19 @@ -253,42 +255,37 @@
2.20
2.21 try:
2.22 self.gmyth = subprocess.Popen(opts, stdout=subprocess.PIPE,
2.23 + stderr=subprocess.PIPE,
2.24 close_fds=True)
2.25 except Exception, e:
2.26 self.log.error("Error executing gmyth-cat: %s" % e)
2.27 return False
2.28
2.29 + err = self.gmyth.stderr
2.30 +
2.31 if not self._run_mencoder(input=self.gmyth.stdout,
2.32 output=subprocess.PIPE):
2.33 return False
2.34
2.35 - show_loading = 0
2.36 - show = True
2.37 -
2.38 - #n800 150000 and 1000
2.39 + if kind == "f":
2.40 + partial = 0
2.41 + size = err.read(20).split("\n")[0].split("Size:")[1]
2.42 + self.log.debug("Size of file: %s" % size)
2.43 + flags = fcntl.fcntl (err, fcntl.F_GETFL, 0) | os.O_NONBLOCK
2.44 + fcntl.fcntl(err, fcntl.F_SETFL, flags)
2.45
2.46 try:
2.47 while self.proc and self.proc.poll() == None:
2.48 -
2.49 - r, w, x = select([self.proc.stdout], [], [], 0)
2.50 + r, w, x = select([err, self.proc.stdout], [], [], 0)
2.51 if self.proc.stdout in r:
2.52 d = self.proc.stdout.read(4096)
2.53 outfd.write(d)
2.54 - # self.log.debug("Sending tv data: %d" % show_loading)
2.55 - # if show_loading > 150000 and show:
2.56 - # self.log.debug("Disabling loading video")
2.57 - # show = False
2.58
2.59 - #elif show_loading % 10000 == 0 and show:
2.60 - # show_loading += 1
2.61 - # d = open("loading.mpg")
2.62 - # outfd.write(d.read())
2.63 - # self.log.debug("Sendind loading video: %d" % show_loading)
2.64 + if err in r and kind == "f":
2.65 + partial = err.read(50).split("\n")[-2]
2.66 + if partial != "":
2.67 + utils.progress_bar(self.log, int(partial), int(size), 50)
2.68
2.69 - #else:
2.70 - # show_loading += 1
2.71 -
2.72 - #self.log.debug("SHOW_LOADING: %d" % show_loading)
2.73
2.74 except Exception, e:
2.75 self.log.error("Problems handling data: %s" % e)