Excludes angepasst, Download von Transcoding trennen, nach einem erfolgreichen Download stoppen, damit der Tivo Luft holen kann.

This commit is contained in:
Stefan Bethke 2010-07-12 05:50:43 +00:00
parent 46245a8c99
commit c290f91548

View file

@ -1,6 +1,6 @@
#!/usr/bin/python
# $Schlepperbande: src/tivomirror/tivomirror,v 1.26 2010/06/27 11:36:21 stb Exp $
# $Schlepperbande: src/tivomirror/tivomirror,v 1.27 2010/07/04 10:06:46 stb Exp $
#
# Stefans Script, um die Sendungen vom Tivo runterzuladen und in MPEG4
# zu transkodieren.
@ -35,9 +35,10 @@ arset["House"] = 43
excludes = dict()
excludes['Cops'] = 1
excludes['Hot Pursuit'] = 1
excludes['Most Shocking'] = 1
excludes["World's Wildest Police Videos"] = 1
excludes["World Cup Soccer"] = 1
excludes["World Cup Live"] = 1
#excludes["World Cup Soccer"] = 1
#excludes["World Cup Live"] = 1
class flushfile(object):
def __init__(self, f):
@ -130,6 +131,32 @@ def transcode(file, src, passno, ar):
print " %s" % " ".join(transcode_opts)
subprocess.check_call(transcode_opts)
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], \
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)
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
if os.path.getsize(target) < 1024:
print "error transcoding file: too small"
os.remove(target)
raise OSError
def download_decode(file, url, mak, ar):
#target = tmpmp2
@ -138,34 +165,10 @@ def download_decode(file, url, mak, ar):
os.makedirs(dir)
except OSError:
pass
if os.path.exists(target):
print " reusing existing download file"
else:
print "--- dowloading \"%s\" (ar %s)" % (url, ar)
p_curl = subprocess.Popen(["curl", "--anyauth", "--fail", \
"--insecure", "--cookie", "tivo/.cookies.txt", \
"--silent", "--show-error", \
"--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)
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
if os.path.getsize(target) < 1024:
print "error transcoding file: too small"
os.remove(target)
raise OSError
#if os.path.exists(target):
# print " reusing existing download file"
#else:
download(file, url, mak, target)
return
transcode(file, target, 1, ar)
transcode(file, target, 2, ar)
@ -230,6 +233,8 @@ for i in items:
downloaddb[name] = date
if getattr(downloaddb, "sync", None) and callable(downloaddb.sync):
downloaddb.sync()
# stop after the fist successful download since the tivo hangs easily
break
except:
print "Error processing \"%s\"" % name
print "*** Completed"