Mit Exit-Status richtig umgehen, nur bekannte Fehler uebergehen
This commit is contained in:
parent
f004138cb1
commit
4a5bcc4f81
1 changed files with 31 additions and 12 deletions
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
# $Schlepperbande: src/tivomirror/tivomirror,v 1.31 2010/08/06 08:41:55 stb Exp $
|
# $Schlepperbande: src/tivomirror/tivomirror,v 1.32 2010/08/07 09:04:16 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.
|
||||||
|
@ -11,12 +11,13 @@ import anydbm
|
||||||
import cookielib
|
import cookielib
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
import signal
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import urllib2
|
import urllib2
|
||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
import re
|
|
||||||
|
|
||||||
host = "tivo.lassitu.de"
|
host = "tivo.lassitu.de"
|
||||||
mak = "7194378159"
|
mak = "7194378159"
|
||||||
|
@ -65,6 +66,12 @@ tmp = "/tmp"
|
||||||
tmpmp2 = "/home/stb/tmp.mpg"
|
tmpmp2 = "/home/stb/tmp.mpg"
|
||||||
tmpmp4 = "/home/stb/tmp.mp4"
|
tmpmp4 = "/home/stb/tmp.mp4"
|
||||||
|
|
||||||
|
class TivoException(Exception):
|
||||||
|
def __init__(self, value):
|
||||||
|
self.value = value
|
||||||
|
def __str__(self):
|
||||||
|
return repr(self.value)
|
||||||
|
|
||||||
def gettoc():
|
def gettoc():
|
||||||
url = "https://" + host + "/TiVoConnect?Command=QueryContainer&Container=%2FNowPlaying&Recurse=Yes"
|
url = "https://" + host + "/TiVoConnect?Command=QueryContainer&Container=%2FNowPlaying&Recurse=Yes"
|
||||||
pwmgr.add_password(None, url, "tivo", mak)
|
pwmgr.add_password(None, url, "tivo", mak)
|
||||||
|
@ -136,19 +143,31 @@ 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):
|
def checkProcessError(curl, decode):
|
||||||
(spid, sse) = os.wait()
|
(spid, sse) = os.wait()
|
||||||
if (sse >> 8) == 0:
|
if not os.WIFSIGNALED(sse) \
|
||||||
|
and os.WIFEXITED(sse) and os.WEXITSTATUS(sse) == 0:
|
||||||
return False
|
return False
|
||||||
if spid == curl.pid:
|
if spid == curl.pid:
|
||||||
print "error downloading file: %d" % (sse >> 8)
|
proc = "curl"
|
||||||
elif spid == decode.pid:
|
elif spid == decode.pid:
|
||||||
print "error decoding file: %d" % (sse >> 8)
|
proc = "tivodecode"
|
||||||
|
if os.WIFSIGNALED(sse):
|
||||||
|
cause = "exited with signal %d" % os.WTERMSIG(sse)
|
||||||
else:
|
else:
|
||||||
print "another process(?!) finished with an error"
|
cause = "exited with code %d" % os.WEXITSTATUS(sse)
|
||||||
|
proc = "another"
|
||||||
|
print "--- %s %s" % (proc, cause)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def quit_process(pid):
|
||||||
|
try:
|
||||||
|
os.kill(p_curl.pid, signal.SIGQUIT)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
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", \
|
||||||
|
@ -159,14 +178,14 @@ def download(file, url, mak, target):
|
||||||
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)
|
||||||
if checkProcessError(p_curl, p_decode) or checkProcessError(p_curl, p_decode):
|
if checkProcessError(p_curl, p_decode) or checkProcessError(p_curl, p_decode):
|
||||||
|
quit_process(p_curl.pid)
|
||||||
|
quit_process(p_decode.pid.pid)
|
||||||
os.remove(target)
|
os.remove(target)
|
||||||
os.kill(p_curl.pid, signal.SIGQUIT)
|
raise TivoException("error downloading/decoding file")
|
||||||
os.kill(p_decode.pid, signal.SIGQUIT)
|
|
||||||
raise Exception
|
|
||||||
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 Exception
|
raise TivoException("downloaded file is too small")
|
||||||
|
|
||||||
def download_decode(file, url, mak, ar):
|
def download_decode(file, url, mak, ar):
|
||||||
#target = tmpmp2
|
#target = tmpmp2
|
||||||
|
@ -251,7 +270,7 @@ 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 Exception, e:
|
except TivoException, e:
|
||||||
print "Error processing \"%s\": %s" % (name, e)
|
print "Error processing \"%s\": %s" % (name, e)
|
||||||
print "*** Completed"
|
print "*** Completed"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue