From f303f1ca169b788dfbefb67a572e2b143791f64a Mon Sep 17 00:00:00 2001 From: Stefan Bethke Date: Thu, 5 Aug 2010 20:05:18 +0000 Subject: [PATCH] Kompakterer Code mit leicht verbesserter Fehlerbehandlung. Jetzt sollten auch keine leeren Dateien mehr erzeugt werden. --- src/tivomirror/tivomirror | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/tivomirror/tivomirror b/src/tivomirror/tivomirror index 256b8e0..3238c41 100755 --- a/src/tivomirror/tivomirror +++ b/src/tivomirror/tivomirror @@ -1,6 +1,6 @@ #!/usr/bin/python -# $Schlepperbande: src/tivomirror/tivomirror,v 1.28 2010/07/12 05:50:43 stb Exp $ +# $Schlepperbande: src/tivomirror/tivomirror,v 1.29 2010/07/26 20:48:02 stb Exp $ # # Stefans Script, um die Sendungen vom Tivo runterzuladen und in MPEG4 # zu transkodieren. @@ -131,32 +131,35 @@ def transcode(file, src, passno, ar): print " %s" % " ".join(transcode_opts) subprocess.check_call(transcode_opts) +def checkProcessError(curl, decode): + (spid, sse) = os.wait() + if (sse >> 8) == 0: + return False + if spid == curl.pid: + print "error downloading file: %d" % (sse >> 8) + elif spid == decode.pid: + print "error decoding file: %d" % (sse >> 8) + else: + print "another process(?!) finished with an error" + return True + + def download(file, url, mak, target): print "--- dowloading \"%s\"" % (url) p_curl = subprocess.Popen(["curl", "--anyauth", "--fail", \ "--insecure", "--cookie", "tivo/.cookies.txt", \ "--silent", "--show-error", \ - "--user", "tivo:%s" % mak, "--url", url], \ + "--user", "tivo:%s" % mak, "--url", url ], \ stdout=subprocess.PIPE) p_decode = subprocess.Popen(["tivodecode", "--mak", mak, \ "--out", target, "-"], stdin=p_curl.stdout) - status = {} - (spid, sse) = os.wait() - status.update({spid: sse}) - (spid, sse) = os.wait() - status.update({spid: sse}) - if status.get(p_curl.pid) >> 8 != 0: - print "error downloading file: %d" % (status.get(p_curl.pid) >> 8) + if checkProcessError(p_curl, p_decode) or checkProcessError(p_curl, p_decode): os.remove(target) - raise OSError - if status.get(p_decode.pid) >> 8 != 0: - print "error decoding file: %d" % (status.get(p_decode.pid) >> 8) - os.remove(target) - raise OSError + raise Exception if os.path.getsize(target) < 1024: print "error transcoding file: too small" os.remove(target) - raise OSError + raise Exception def download_decode(file, url, mak, ar): #target = tmpmp2 @@ -236,8 +239,8 @@ for i in items: downloaddb.sync() # stop after the fist successful download since the tivo hangs easily break - except: - print "Error processing \"%s\"" % name + except Exception, e: + print "Error processing \"%s\": %s" % (name, e) print "*** Completed" downloaddb.close()