Auch mehrere Downloads pro Run unterstuetzen; man muss kurz warten, damit sich der Tivo erholen kann

This commit is contained in:
Stefan Bethke 2014-07-01 16:57:33 +00:00
parent 93c2a625ea
commit 8cd90d5984

View file

@ -1,6 +1,6 @@
#!/usr/local/bin/python
# $Schlepperbande: src/tivomirror/tivomirror,v 1.56 2014/06/28 12:16:12 stb Exp $
# $Schlepperbande: src/tivomirror/tivomirror,v 1.57 2014/07/01 07:04:45 stb Exp $
#
# Stefans Script, um die Sendungen vom Tivo runterzuladen und in MPEG4
# zu transkodieren.
@ -241,6 +241,8 @@ def download(url, mak, target):
logger.info("--- downloading \"%s\"" % (url))
start = time.time()
r = session.get(url, stream=True)
r.raise_for_status()
try:
p_decode = subprocess.Popen(["tivodecode", "--mak", mak, \
"--no-verify", "--out", target, "-"], stdin=subprocess.PIPE)
@ -260,20 +262,28 @@ def download(url, mak, target):
except Exception, e:
logger.error("problem decoding: %s" % (e))
finally:
elapsed = time.time() - start
throughput = count / elapsed
logger.info("%5.3fGB transferred in %d:%02d, %.1f MB/s" % (
count/1e9, int(elapsed/3600), int(elapsed / 60) % 60, throughput/1e6))
try:
p_decode.stdin.close()
quit_process(p_decode.pid)
#quit_process(p_decode.pid)
p_decode.poll()
if p_decode.returncode == None:
time.sleep(1)
p_decode.poll()
if p_decode.returncode == None:
p_decode.terminate()
except Exception, e:
pass
p_decode.wait()
logger.info("tivodecode exited with %s" % (p_decode.returncode))
size = os.path.getsize(target)
if size < 1024:
logger.error("error downloading file: too small")
os.remove(target)
raise TivoException("downloaded file is too small")
elapsed = time.time() - start
throughput = size / elapsed
logger.info("%5.3fGB transferred in %d:%02d, %.1f MB/s" % (
size/1e9, int(elapsed/3600), int(elapsed / 60) % 60, throughput/1e6))
def download_decode(item, mak):
@ -348,13 +358,10 @@ def mirror(dom, downloaddb):
downloaddb[item.name] = item.datestr
if getattr(downloaddb, "sync", None) and callable(downloaddb.sync):
downloaddb.sync()
# stop after the first successful download since the tivo hangs easily
#logger.info("Stopping after one successful transfer")
#break
logger.debug("Sleeping 30 seconds before moving on...")
time.sleep(30)
except TivoException, e:
logger.info("Error processing \"%s\": %s" % (item.name, e))
# stop after one beacuse tivodevode cannot be launch twice in a row?
break
logger.info("*** Completed %s" % datetime.datetime.now().strftime("%Y-%m-%d %H:%M"))