Unsinn wieder ausbauen, jetzt wo das Routing wieder geht

This commit is contained in:
Stefan Bethke 2011-11-26 13:58:43 +00:00
parent a03a8c8cbe
commit f6be7dc724

View file

@ -1,6 +1,6 @@
#!/usr/local/bin/python #!/usr/local/bin/python
# $Schlepperbande: src/tivomirror/tivomirror,v 1.44 2011/09/15 11:08:11 stb Exp $ # $Schlepperbande: src/tivomirror/tivomirror,v 1.45 2011/10/12 16:31:01 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.
@ -45,6 +45,7 @@ includes['The Big Bang Theory'] = 1
includes['The Colbert Report'] = 1 includes['The Colbert Report'] = 1
includes['The Daily Show With Jon Stewart'] = 1 includes['The Daily Show With Jon Stewart'] = 1
includes['The Late Late Show With Craig Ferguson'] = 1 includes['The Late Late Show With Craig Ferguson'] = 1
includes['IGenius: How Steve Jobs Changed the World'] = 1
class flushfile(object): class flushfile(object):
@ -77,8 +78,9 @@ class TivoItem:
def __init__(self, i): def __init__(self, i):
self.title = getTagText(i, "Title") self.title = getTagText(i, "Title")
self.episode = getTagText(i, "EpisodeTitle") self.episode = getTagText(i, "EpisodeTitle")
self.date = getTagText(i, "CaptureDate") d = getTagText(i, "CaptureDate")
self.date = datetime.datetime.utcfromtimestamp(int(self.date, 16)) self.date = datetime.datetime.utcfromtimestamp(int(d, 16))
self.time = int(d, base=0)
self.datestr = self.date.strftime("%Y%m%d-%H%M") self.datestr = self.date.strftime("%Y%m%d-%H%M")
self.url = getTagText(i, "Url") self.url = getTagText(i, "Url")
self.inprogress = getTagText(i, "InProgress") self.inprogress = getTagText(i, "InProgress")
@ -132,8 +134,16 @@ def quit_process(pid):
def waitForProcs(pids): def waitForProcs(pids):
success = True success = True
starttime = time.time()
while len(pids) > 0: while len(pids) > 0:
(spid, sse) = os.wait() (spid, sse) = os.waitpid(0, os.WNOHANG)
if spid == 0:
if 0 && time.time() - starttime > 6 * 60 * 60:
for pid in pids:
os.kill(pid, signal.SIGTERM)
raise TivoException("waiting for download to complete exceeded timeout")
time.sleep(2)
continue
pids.remove(spid) pids.remove(spid)
if os.WIFSIGNALED(sse) \ if os.WIFSIGNALED(sse) \
or (os.WIFEXITED(sse) and os.WEXITSTATUS(sse) != 0): or (os.WIFEXITED(sse) and os.WEXITSTATUS(sse) != 0):
@ -148,9 +158,12 @@ def waitForProcs(pids):
quit_process(pid) quit_process(pid)
if not success: if not success:
raise TivoException("error executing processes") raise TivoException("error executing processes")
pass
def download(file, url, mak, target): def download(file, url, mak, target):
#url = re.sub("tivo.lassitu.de:80", "localhost:8888", url)
#url = re.sub("tivo.lassitu.de:80", "krokodil-vpn.zs64.net:8888", url)
print "--- downloading \"%s\"" % (url) print "--- downloading \"%s\"" % (url)
start = time.time() start = time.time()
p_curl = subprocess.Popen(["curl", "--anyauth", "--fail", \ p_curl = subprocess.Popen(["curl", "--anyauth", "--fail", \
@ -186,20 +199,23 @@ def download_decode(item, mak):
os.makedirs(item.dir) os.makedirs(item.dir)
except OSError: except OSError:
pass pass
if os.path.exists(target): if 0 & os.path.exists(target):
print " reusing existing download file" print " reusing existing download file"
else: else:
try: try:
download(item.file, item.url, mak, target) download(item.file, item.url, mak, target)
except Exception, e: except Exception, e:
try:
os.remove(target) os.remove(target)
raise except Exception, e2:
pass
raise e
#tivomp4.transcode(target, mp4, item.ar) #tivomp4.transcode(target, mp4, item.ar)
try: try:
os.utime(target, (item.date, item.date)) os.utime(target, (item.time, item.time))
#os.utime(mp4, [item.date, item.date]) #os.utime(mp4, [item.date, item.date])
except Exception, e: except Exception, e:
print "Urgh:", e print "Problem setting timestamp: ", e
def savetoc(toc): def savetoc(toc):
@ -265,7 +281,7 @@ def main():
except TivoException, e: except TivoException, e:
print "Error processing \"%s\": %s" % (item.name, e) print "Error processing \"%s\": %s" % (item.name, e)
print "*** Completed" print "*** Completed %s" % datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
downloaddb.close() downloaddb.close()
if __name__ == "__main__": if __name__ == "__main__":