Eine Funktion zum Listen aller Episoden dazu, und eine Funktion,

um den vom Tivo angebotenen Episodentitel zu ignorieren und stattdessen
einen Timestamp zu verwenden. Manche Sendungen verwenden fuer mehrere
Episoden den selben Titel, und dann wird immer nur die erste geladen.
This commit is contained in:
Stefan Bethke 2012-07-27 20:19:03 +00:00
parent 1c21d26080
commit 80535becb2

View file

@ -1,6 +1,6 @@
#!/usr/local/bin/python
# $Schlepperbande: src/tivomirror/tivomirror,v 1.45 2011/10/12 16:31:01 stb Exp $
# $Schlepperbande: src/tivomirror/tivomirror,v 1.46 2011/11/26 13:58:43 stb Exp $
#
# Stefans Script, um die Sendungen vom Tivo runterzuladen und in MPEG4
# zu transkodieren.
@ -10,6 +10,7 @@
import anydbm
import cookielib
import datetime
import getopt
import os
import re
import signal
@ -26,11 +27,13 @@ mak = "7194378159"
targetdir = "/p1/media/TV"
gig = 1024.0 * 1024 * 1024
minfree = 10 * gig
ignoreepisodetitle = False
arset = dict()
arset["Futurama"] = 169
includes = dict()
includes['Castle'] = 1
includes['Dirty Jobs'] = 1
includes['Family Guy'] = 1
includes['Flying Wild Alaska'] = 1
@ -41,12 +44,13 @@ includes['Louie'] = 1
includes['Mad Men'] = 1
includes['Modern Family'] = 1
includes['MythBusters'] = 1
includes['Sesame Street'] = 1
includes['The Big Bang Theory'] = 1
includes['The Colbert Report'] = 1
includes['The Daily Show With Jon Stewart'] = 1
includes['The Late Late Show With Craig Ferguson'] = 1
includes['IGenius: How Steve Jobs Changed the World'] = 1
includes['Unchained Reaction'] = 1
includes["Wait, Wait... Don't Tell Me! A Royal Pain in the News"] = 1
class flushfile(object):
def __init__(self, f):
@ -92,13 +96,13 @@ class TivoItem:
self.ar = arset[self.title]
elif self.highdef == "Yes":
self.ar = "hd"
if self.episode == "":
if ignoreepisodetitle or (self.episode == ""):
self.episode = self.datestr
def __str__(self):
return repr(self.title)
def gettoc():
url = "https://" + host + "/TiVoConnect?Command=QueryContainer&Container=%2FNowPlaying&Recurse=Yes"
url = "https://" + host + "/TiVoConnect?Command=QueryContainer&Container=%2FNowPlaying&Recurse=Yes&ItemCount=50"
pwmgr.add_password(None, url, "tivo", mak)
req = urllib2.Request(url)
@ -138,7 +142,7 @@ def waitForProcs(pids):
while len(pids) > 0:
(spid, sse) = os.waitpid(0, os.WNOHANG)
if spid == 0:
if 0 && time.time() - starttime > 6 * 60 * 60:
if time.time() - starttime > 6 * 60 * 60:
for pid in pids:
os.kill(pid, signal.SIGTERM)
raise TivoException("waiting for download to complete exceeded timeout")
@ -223,22 +227,28 @@ def savetoc(toc):
fd.write(toc)
fd.close()
def main():
curdir = os.getcwd()
os.chdir(tmp)
def wantitem(item, downloaddb):
if item.inprogress == "Yes":
return "recording"
if item.available == "No":
return "not available"
if downloaddb.has_key(item.name):
return "already downloaded"
#if excludes.has_key(item.title) or excludes.has_key(item.episode) or excludes.has_key(item.name):
# return "excluded"
if includes.has_key(item.title) or includes.has_key(item.episode) or includes.has_key(item.name):
pass
else:
return "not included"
return ""
def mirror(dom, downloaddb):
avail = getAvail(targetdir)
if avail < minfree:
print "%s: %.1fG available, at least %.1fG needed, stopping" % \
(targetdir, avail / gig, minfree / gig)
sys.exit(1)
downloaddb = anydbm.open(os.path.expanduser("~") + "/.tivo-downloads", "c")
print "*** Getting listing"
toc = gettoc()
savetoc(toc)
dom = xml.dom.minidom.parseString(toc)
cookiejar.save()
items = dom.getElementsByTagName("Item")
print "*** %d shows listed" % (items.length)
for i in items:
@ -251,22 +261,9 @@ def main():
item.dir = item.dir.encode("utf-8");
item.file = item.file.encode("utf-8");
if item.inprogress == "Yes":
print "*** skipping \"%s\": is currently being recorded" % item.name
continue
if item.available == "No":
print "*** skipping \"%s\": is not available" % item.name
continue
if downloaddb.has_key(item.name):
#print "*** skipping \"%s\": already downloaded" % item.name
continue
#if excludes.has_key(item.title) or excludes.has_key(item.episode) or excludes.has_key(item.name):
# #print "*** skipping \"%s\": excluded" % name
# continue
if includes.has_key(item.title) or includes.has_key(item.episode) or includes.has_key(item.name):
pass
else:
print "*** skipping \"%s\": excluded" % item.name
reason = wantitem(item, downloaddb)
if (reason != ""):
print "*** skipping \"%s\": %s" % (item.name, reason)
continue
print "*** downloading \"%s\": %.3fGB" % (item.name, item.sourcesize / 1e9)
@ -282,6 +279,52 @@ def main():
print "Error processing \"%s\": %s" % (item.name, e)
print "*** Completed %s" % datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
def printtoc(dom, downloaddb):
items = dom.getElementsByTagName("Item")
print "*** %d shows listed" % (items.length)
for i in items:
item = TivoItem(i)
item.name = "%s - %s" % (item.title, item.episode)
#dir = "%s/tivo/%s" % (curdir, re.sub("[:/]", "-", item.title))
item.dir = "%s/%s" % (targetdir, re.sub("[:/]", "-", item.title))
item.file = "%s/%s" % (item.dir, re.sub("[:/]", "-", item.name))
item.name = item.name.encode("utf-8");
item.dir = item.dir.encode("utf-8");
item.file = item.file.encode("utf-8");
reason = wantitem(item, downloaddb)
if (reason != ""):
print "--- %-11.11s: %s" % (reason, item.name)
continue
print "*** downloading %s (%.3fGB)" % (item.name, item.sourcesize / 1e9)
def main():
global ignoreepisodetitle
curdir = os.getcwd()
os.chdir(tmp)
options, remainder = getopt.getopt(sys.argv[1:], 'T',
['ignoreepisodetitle'])
for opt, arg in options:
if opt in ('-T', '--ignoreepisodetitle'):
ignoreepisodetitle = True
downloaddb = anydbm.open(os.path.expanduser("~") + "/.tivo-downloads", "c")
print "*** Getting listing"
toc = gettoc()
savetoc(toc)
dom = xml.dom.minidom.parseString(toc)
cookiejar.save()
if len(remainder) == 1:
if remainder[0] == "list":
printtoc(dom, downloaddb)
elif remainder[0] == "mirror":
mirror(dom, downloaddb)
else:
mirror(dom, downloaddb)
downloaddb.close()
if __name__ == "__main__":