From f81af4dc1c0580cb43338e46aeb2cedfb88827c3 Mon Sep 17 00:00:00 2001 From: Jason Michalski Date: Sat, 25 Nov 2006 10:07:28 +0000 Subject: [PATCH] pyTivo - BAD HACK to get subprocess to work without a console - pyTivoService.py now works --- pyTivoService.py | 11 ++++++++--- transcode.py | 24 +++++++++++++++++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/pyTivoService.py b/pyTivoService.py index cb133e1..a1e79fa 100644 --- a/pyTivoService.py +++ b/pyTivoService.py @@ -2,7 +2,7 @@ import beacon, httpserver, ConfigParser import win32serviceutil import win32service import win32event -import select +import select, sys class PyTivoService(win32serviceutil.ServiceFramework): _svc_name_ = 'pyTivo' @@ -17,8 +17,12 @@ class PyTivoService(win32serviceutil.ServiceFramework): import sys, os p = os.path.dirname(__file__) - open(os.path.join(p, 'pyTivo.conf')) - + + f = open(os.path.join(p, 'log.txt'), 'w') + sys.stdout = f + sys.stderr = f + print 'test' + config = ConfigParser.ConfigParser() config.read( os.path.join(p, 'pyTivo.conf') ) @@ -35,6 +39,7 @@ class PyTivoService(win32serviceutil.ServiceFramework): b.send_beacon_timer() while 1: + sys.stdout.flush() (rx, tx, er) = select.select((httpd,), (), (), 5) for sck in rx: sck.handle_request() diff --git a/transcode.py b/transcode.py index ebf7cbe..4f1525c 100644 --- a/transcode.py +++ b/transcode.py @@ -1,18 +1,36 @@ -import subprocess, shutil, os, re +import subprocess, shutil, os, re, sys SCRIPTDIR = os.path.dirname(__file__) +# subprocess is broken for me on windows so super hack +def patchSubprocess(): + o = subprocess.Popen._make_inheritable + + def _make_inheritable(self, handle): + print 'MY _make_inheritable' + if not handle: return subprocess.GetCurrentProcess() + return o(self, handle) + + subprocess.Popen._make_inheritable = _make_inheritable + +mswindows = (sys.platform == "win32") + +if mswindows: + patchSubprocess() + def output_video(inFile, outFile): if tivo_compatable(inFile): f = file(inFile, 'rb') shutil.copyfileobj(f, outFile) - f.close() + f.close() else: transcode(inFile, outFile) def transcode(inFile, outFile): cmd = SCRIPTDIR + "\\ffmpeg_mp2.exe -i \"%s\" -vcodec mpeg2video -r 29.97 -b 4096 %s -ac 2 -ab 192 -f vob -" % (inFile, select_aspect(inFile)) + # subprocess is busted in my python 2.5 when run without a console. Setting all to PIPE fixes it. + # but now we get this nice select loop to dump the stderr data ffmpeg = subprocess.Popen(cmd, stdout=subprocess.PIPE) try: shutil.copyfileobj(ffmpeg.stdout, outFile) @@ -67,7 +85,7 @@ def tivo_compatable(inFile): def video_info(inFile): cmd = SCRIPTDIR + "\\ffmpeg_mp2.exe -i \"%s\"" % inFile - ffmpeg = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE) + ffmpeg = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE) output = ffmpeg.stderr.read() rezre = re.compile(r'.*Video: (.+), (\d+)x(\d+), (.+) fps.*') -- 2.11.4.GIT