Kompakterer Code mit leicht verbesserter Fehlerbehandlung. Jetzt sollten auch keine leeren Dateien mehr erzeugt werden.
This commit is contained in:
parent
5913507c64
commit
f303f1ca16
1 changed files with 20 additions and 17 deletions
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue