Kompakterer Code mit leicht verbesserter Fehlerbehandlung. Jetzt sollten auch keine leeren Dateien mehr erzeugt werden.

This commit is contained in:
Stefan Bethke 2010-08-05 20:05:18 +00:00
parent 5913507c64
commit f303f1ca16

View file

@ -1,6 +1,6 @@
#!/usr/bin/python #!/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 # Stefans Script, um die Sendungen vom Tivo runterzuladen und in MPEG4
# zu transkodieren. # zu transkodieren.
@ -131,6 +131,19 @@ def transcode(file, src, passno, ar):
print " %s" % " ".join(transcode_opts) print " %s" % " ".join(transcode_opts)
subprocess.check_call(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): def download(file, url, mak, target):
print "--- dowloading \"%s\"" % (url) print "--- dowloading \"%s\"" % (url)
p_curl = subprocess.Popen(["curl", "--anyauth", "--fail", \ p_curl = subprocess.Popen(["curl", "--anyauth", "--fail", \
@ -140,23 +153,13 @@ def download(file, url, mak, target):
stdout=subprocess.PIPE) stdout=subprocess.PIPE)
p_decode = subprocess.Popen(["tivodecode", "--mak", mak, \ p_decode = subprocess.Popen(["tivodecode", "--mak", mak, \
"--out", target, "-"], stdin=p_curl.stdout) "--out", target, "-"], stdin=p_curl.stdout)
status = {} if checkProcessError(p_curl, p_decode) or checkProcessError(p_curl, p_decode):
(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)
os.remove(target) os.remove(target)
raise OSError raise Exception
if status.get(p_decode.pid) >> 8 != 0:
print "error decoding file: %d" % (status.get(p_decode.pid) >> 8)
os.remove(target)
raise OSError
if os.path.getsize(target) < 1024: if os.path.getsize(target) < 1024:
print "error transcoding file: too small" print "error transcoding file: too small"
os.remove(target) os.remove(target)
raise OSError raise Exception
def download_decode(file, url, mak, ar): def download_decode(file, url, mak, ar):
#target = tmpmp2 #target = tmpmp2
@ -236,8 +239,8 @@ for i in items:
downloaddb.sync() downloaddb.sync()
# stop after the fist successful download since the tivo hangs easily # stop after the fist successful download since the tivo hangs easily
break break
except: except Exception, e:
print "Error processing \"%s\"" % name print "Error processing \"%s\": %s" % (name, e)
print "*** Completed" print "*** Completed"
downloaddb.close() downloaddb.close()