Fehler beim Dekodieren auch hochwerfen, schoener loggen
This commit is contained in:
parent
24be7bddfc
commit
e7b935535e
1 changed files with 35 additions and 14 deletions
|
@ -1,6 +1,6 @@
|
|||
#!/usr/local/bin/python
|
||||
|
||||
# $Schlepperbande: src/tivomirror/tivomirror,v 1.62 2014/07/05 15:19:39 stb Exp $
|
||||
# $Schlepperbande: src/tivomirror/tivomirror,v 1.63 2014/07/05 15:23:02 stb Exp $
|
||||
#
|
||||
# Stefans Script, um die Sendungen vom Tivo runterzuladen und in MPEG4
|
||||
# zu transkodieren.
|
||||
|
@ -33,6 +33,7 @@ import xml.dom.minidom
|
|||
import tivomp4
|
||||
|
||||
host = "tivo.lassitu.de"
|
||||
#host = "wavehh.lassitu.de:30080"
|
||||
mak = "7194378159"
|
||||
targetdir = "/p1/media/TV"
|
||||
gig = 1024.0 * 1024 * 1024
|
||||
|
@ -46,6 +47,7 @@ includes['Brooklyn Nine-Nine'] = 1
|
|||
includes['Castle'] = 1
|
||||
includes['Family Guy'] = 1
|
||||
includes['Hot in Cleveland'] = 1
|
||||
includes["How It's Made"] = 1
|
||||
includes['Late Show With David Letterman'] = 1
|
||||
includes['Louie'] = 1
|
||||
includes['Mad Men'] = 1
|
||||
|
@ -80,6 +82,7 @@ tmp = "/tmp"
|
|||
session = requests.session()
|
||||
session.verify = False
|
||||
session.auth = requests.auth.HTTPDigestAuth("tivo", mak)
|
||||
session.keep_alive = False
|
||||
|
||||
|
||||
class TimeoutError(Exception):
|
||||
|
@ -268,17 +271,22 @@ class FdLogger(threading.Thread):
|
|||
self.logger.exception("")
|
||||
|
||||
|
||||
@timeout(7200)
|
||||
def download(url, mak, target):
|
||||
@timeout(43200)
|
||||
#@timeout(7200)
|
||||
def download(item, mak, target):
|
||||
global session
|
||||
count = 0
|
||||
start = time.time()
|
||||
upd = start
|
||||
url = item.url
|
||||
#url = re.sub("tivo.lassitu.de:80", "wavehh.lassitu.de:30080", url)
|
||||
#url = re.sub("wavehh.lassitu.de:80", "wavehh.lassitu.de:30080", url)
|
||||
#url = re.sub("tivo.lassitu.de:80", "localhost:8888", url)
|
||||
#url = re.sub("tivo.lassitu.de:80", "krokodil-vpn.zs64.net:8888", url)
|
||||
logger.info("--- downloading \"%s\"" % (url))
|
||||
start = time.time()
|
||||
r = session.get(url, stream=True)
|
||||
#r = session.get(url, stream=True, proxies={"http":"http://wavehh:8888","https":"http://wavehh:8888"})
|
||||
r.raise_for_status()
|
||||
|
||||
try:
|
||||
|
@ -286,13 +294,18 @@ def download(url, mak, target):
|
|||
"--no-verify", "--out", target, "-"], stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
FdLogger(logger, logging.INFO, p_decode.stdout)
|
||||
FdLogger(logger, logging.ERROR, p_decode.stderr)
|
||||
FdLogger(logger, logging.INFO, p_decode.stderr)
|
||||
def info(signum, frame):
|
||||
upd = time.time()
|
||||
dur = now - start
|
||||
mb = count / 1e6
|
||||
print "%5.3f GB downloaded in %.0f min, %.3f MB/s" % (mb / 1e3, dur / 60, mb / dur)
|
||||
print "%5.1f%% %5.3f GB downloaded in %.0f min, %.3f MB/s" % (
|
||||
100.0 * count / item.sourcesize,
|
||||
mb / 1e3, dur / 60, mb / dur)
|
||||
try:
|
||||
signal.signal(signal.SIGINFO, info)
|
||||
except Exception:
|
||||
pass
|
||||
while True:
|
||||
time.sleep(0) # yield to logger threads
|
||||
chunk = r.raw.read(65536)
|
||||
|
@ -306,11 +319,17 @@ def download(url, mak, target):
|
|||
upd = now
|
||||
dur = now - start
|
||||
mb = count / 1e6
|
||||
logger.debug(" %5.3f GB downloaded in %.0f min, %.3f MB/s" % (mb / 1e3, dur / 60, mb / dur))
|
||||
except Exception, e:
|
||||
logger.debug(" %5.1f%% %5.3f GB downloaded in %.0f min, %.3f MB/s" % (
|
||||
100.0 * count / item.sourcesize,
|
||||
mb / 1e3, dur / 60, mb / dur))
|
||||
except Exception as e:
|
||||
logger.error("problem decoding: %s" % (e))
|
||||
raise
|
||||
finally:
|
||||
try:
|
||||
signal.signal(signal.SIGINFO, signal.SIG_IGN)
|
||||
except Exception:
|
||||
pass
|
||||
elapsed = time.time() - start
|
||||
throughput = count / elapsed
|
||||
logger.info("%5.3fGB transferred in %d:%02d, %.1f MB/s" % (
|
||||
|
@ -346,7 +365,7 @@ def download_decode(item, mak):
|
|||
logger.info(" reusing existing download file")
|
||||
else:
|
||||
try:
|
||||
download(item.url, mak, target)
|
||||
download(item, mak, target)
|
||||
except Exception, e:
|
||||
exc_info = sys.exc_info()
|
||||
try:
|
||||
|
@ -392,7 +411,7 @@ def wantitem(item, downloaddb):
|
|||
return ""
|
||||
|
||||
|
||||
def mirror(toc, downloaddb):
|
||||
def mirror(toc, downloaddb, one=False):
|
||||
avail = getAvail(targetdir)
|
||||
if avail < minfree:
|
||||
logger.error("%s: %.1fG available, at least %.1fG needed, stopping" % \
|
||||
|
@ -403,12 +422,13 @@ def mirror(toc, downloaddb):
|
|||
logger.info("*** %d shows listed" % (items.length))
|
||||
for node in items:
|
||||
item = TivoItem(node)
|
||||
|
||||
reason = wantitem(item, downloaddb)
|
||||
if reason != "":
|
||||
logger.debug("*** skipping \"%s\": %s" % (item.name, reason))
|
||||
else:
|
||||
download_one(item, downloaddb)
|
||||
if one:
|
||||
break
|
||||
|
||||
|
||||
def download_episode(toc, downloaddb, episode):
|
||||
|
@ -461,7 +481,6 @@ def main():
|
|||
logger.addHandler(handler)
|
||||
if opt in ('-u', '--update'):
|
||||
updateToc = True
|
||||
toc.download()
|
||||
if opt in ('-T', '--ignoreepisodetitle'):
|
||||
ignoreepisodetitle = True
|
||||
|
||||
|
@ -475,6 +494,8 @@ def main():
|
|||
|
||||
if cmd == "mirror":
|
||||
mirror(toc, downloaddb)
|
||||
elif cmd == "mirrorone":
|
||||
mirror(toc, downloaddb, True)
|
||||
elif cmd == "list":
|
||||
printtoc(toc, downloaddb)
|
||||
elif cmd == "download":
|
||||
|
|
Loading…
Reference in a new issue