- Exclude-Liste dazu

- Available-Marker im XML auswerten (gesetzt bei Sendungen mit Copy-Protect)
- Transkodierung ausschalten
- Bessere Fehlerbehandlung bei Download- und ffmpeg-Problemen
This commit is contained in:
Stefan Bethke 2010-06-21 06:14:48 +00:00
parent 17b66ca8bc
commit 4b1bb1f3d1

View file

@ -1,6 +1,6 @@
#!/usr/bin/python
# $Schlepperbande: src/tivomirror/tivomirror,v 1.23 2010/04/22 06:35:26 stb Exp $
# $Schlepperbande: src/tivomirror/tivomirror,v 1.24 2010/04/22 06:42:22 stb Exp $
#
# Stefans Script, um die Sendungen vom Tivo runterzuladen und in MPEG4
# zu transkodieren.
@ -30,7 +30,13 @@ arset["The Daily Show With Jon Stewart"] = 43
arset["John Oliver's New York Stand-Up Show"] = 43
arset["John Oliver: Terrifying Times"] = 43
arset["House"] = 43
arset["The Late Late Show With Craig Ferguson"] = 149
#arset["The Late Late Show With Craig Ferguson"] = 149
excludes = dict()
excludes['Cops'] = 1
excludes["World's Wildest Police Videos"] = 1
excludes["World Cup Soccer"] = 1
excludes["World Cup Live"] = 1
class flushfile(object):
def __init__(self, f):
@ -50,8 +56,10 @@ cookiejar = cookielib.MozillaCookieJar(os.getcwd() + "/tivo/.cookies.txt")
opener = urllib2.build_opener(authhandler, urllib2.HTTPCookieProcessor(cookiejar))
urllib2.install_opener(opener)
tmp = "/tmp"
tmpmp2 = "/mnt/fast/tmp/tivo.mpg"
tmpmp4 = "/mnt/fast/tmp/tivo.mp4"
#tmpmp2 = "/mnt/fast/tmp/tivo.mpg"
#tmpmp4 = "/mnt/fast/tmp/tivo.mp4"
tmpmp2 = "/home/stb/tmp.mpg"
tmpmp4 = "/home/stb/tmp.mp4"
def gettoc():
url = "https://" + host + "/TiVoConnect?Command=QueryContainer&Container=%2FNowPlaying&Recurse=Yes"
@ -77,7 +85,7 @@ def getTagText(element, tagname):
return ""
def transcode(file, passno, ar):
def transcode(file, src, passno, ar):
print "--- transcoding pass %d" % passno
try:
os.remove(tmpmp4)
@ -85,8 +93,8 @@ def transcode(file, passno, ar):
pass
transcode_opts = [ "ffmpeg" ];
# transcode_opts.extend(["-t", "60"]) # testing only: only 60 seconds
transcode_opts.extend(["-aspect", "4:3", "-i"])
transcode_opts.append(tmpmp2)
#transcode_opts.extend(["-aspect", "4:3"])
transcode_opts.extend(["-i", src])
if passno == 1:
transcode_opts.extend(["-an"])
@ -101,8 +109,9 @@ def transcode(file, passno, ar):
transcode_opts.extend(["-threads", "0", "-b", "900k", "-bt", "900k"])
if ar == 43:
transcode_opts.extend(["-croptop", "4", "-cropbottom", "4", "-cropleft", "6", "-cropright", "6"])
transcode_opts.extend(["-s", "468x352"])
transcode_opts.extend(["-aspect", "4:3"])
#transcode_opts.extend(["-s", "480x352"])
transcode_opts.extend(["-s", "624x352"])
#transcode_opts.extend(["-aspect", "4:3"])
elif ar == 149:
transcode_opts.extend(["-croptop", "34", "-cropbottom", "34", "-cropleft", "6", "-cropright", "6"])
transcode_opts.extend(["-s", "546x352"])
@ -122,11 +131,13 @@ def transcode(file, passno, ar):
def download_decode(file, url, mak, ar):
#target = tmpmp2
target = "%s.mpg" % file
try:
os.makedirs(dir)
except OSError:
pass
if os.path.exists(tmpmp2):
if os.path.exists(target):
print " reusing existing download file"
else:
print "--- dowloading \"%s\" (ar %s)" % (url, ar)
@ -135,7 +146,7 @@ def download_decode(file, url, mak, ar):
"--user", "tivo:%s" % mak, "--url", url], \
stdout=subprocess.PIPE)
p_decode = subprocess.Popen(["tivodecode", "--mak", mak, \
"--out", tmpmp2, "-"], stdin=p_curl.stdout)
"--out", target, "-"], stdin=p_curl.stdout)
status = {}
(spid, sse) = os.wait()
status.update({spid: sse})
@ -143,28 +154,36 @@ def download_decode(file, url, mak, ar):
status.update({spid: sse})
if status.get(p_curl.pid) >> 8 != 0:
print "error downloading file: %d" % (status.get(p_curl.pid) >> 8)
exit(1)
os.remove(target)
raise OSError
if status.get(p_decode.pid) >> 8 != 0:
print "error decoding file: %d" % (status.get(p_decode.pid) >> 8)
exit(1)
transcode(file, 1, ar)
transcode(file, 2, ar)
os.remove(target)
raise OSError
if os.path.getsize(target) < 1024:
print "error transcoding file: too small"
os.remove(target)
raise OSError
return
transcode(file, target, 1, ar)
transcode(file, target, 2, ar)
print "--- copying to \"%s\"" % file
shutil.copy(tmpmp4, "%s.mp4" % file)
os.remove(tmpmp2)
os.remove(tmpmp4)
def savetoc():
fd=open("foo.xml", "w")
fd.write(gettoc())
def savetoc(toc):
fd=open("toc.xml", "w")
fd.write(toc)
fd.close()
exit(0)
curdir = os.getcwd()
os.chdir(tmp)
downloaddb = anydbm.open(curdir + "/tivo/.downloads", "c")
print "*** Getting listing"
dom = xml.dom.minidom.parseString(gettoc())
toc = gettoc()
savetoc(toc)
dom = xml.dom.minidom.parseString(toc)
cookiejar.save()
items = dom.getElementsByTagName("Item")
@ -177,6 +196,7 @@ for i in items:
date = date.strftime("%Y%m%d-%H%M")
url = getTagText(i, "Url")
inprogress = getTagText(i, "InProgress")
available = getTagText(i, "Available")
if episode == "":
episode = date
name = "%s - %s" % (title, episode)
@ -193,14 +213,23 @@ for i in items:
if inprogress == "Yes":
print "*** skipping \"%s\": is currently being recorded" % name
continue
if available == "No":
print "*** skipping \"%s\": is not available" % name
continue
if downloaddb.has_key(name):
print "*** skipping \"%s\": already downloaded" % name
continue
if excludes.has_key(title) or excludes.has_key(episode) or excludes.has_key(name):
print "*** skipping \"%s\": excluded" % name
continue
print "*** downloading \"%s\"" % name
download_decode(file, url, mak, ar)
downloaddb[name] = date
if getattr(downloaddb, "sync", None) and callable(downloaddb.sync):
downloaddb.sync()
try:
download_decode(file, url, mak, ar)
downloaddb[name] = date
if getattr(downloaddb, "sync", None) and callable(downloaddb.sync):
downloaddb.sync()
except:
print "Error processing \"%s\"" % name
print "*** Completed"
downloaddb.close()