Automatisch erkennen, ob mehrere Episoden den selben Titel haben, und dann fuer die Serie das Datum in den Dateinamen aufnehmen
This commit is contained in:
parent
e7b935535e
commit
72f3cdabce
1 changed files with 55 additions and 21 deletions
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/local/bin/python
|
#!/usr/local/bin/python
|
||||||
|
|
||||||
# $Schlepperbande: src/tivomirror/tivomirror,v 1.63 2014/07/05 15:23:02 stb Exp $
|
# $Schlepperbande: src/tivomirror/tivomirror,v 1.64 2014/07/07 21:50:28 stb Exp $
|
||||||
#
|
#
|
||||||
# Stefans Script, um die Sendungen vom Tivo runterzuladen und in MPEG4
|
# Stefans Script, um die Sendungen vom Tivo runterzuladen und in MPEG4
|
||||||
# zu transkodieren.
|
# zu transkodieren.
|
||||||
|
@ -138,6 +138,7 @@ class TivoItem:
|
||||||
self.sourcesize = int(getTagText(i, "SourceSize"))
|
self.sourcesize = int(getTagText(i, "SourceSize"))
|
||||||
self.highdef = getTagText(i, "HighDefinition")
|
self.highdef = getTagText(i, "HighDefinition")
|
||||||
self.ar = 43
|
self.ar = 43
|
||||||
|
self.unique = True
|
||||||
if arset.has_key(self.title):
|
if arset.has_key(self.title):
|
||||||
self.ar = arset[self.title]
|
self.ar = arset[self.title]
|
||||||
elif self.highdef == "Yes":
|
elif self.highdef == "Yes":
|
||||||
|
@ -149,14 +150,21 @@ class TivoItem:
|
||||||
self.episode = self.description
|
self.episode = self.description
|
||||||
else:
|
else:
|
||||||
self.episode = self.datestr
|
self.episode = self.datestr
|
||||||
|
self.formatnames()
|
||||||
|
def makeNotUnique(self):
|
||||||
|
self.unique = False
|
||||||
|
self.formatnames()
|
||||||
|
def formatnames(self):
|
||||||
if self.episodeNumber and self.episodeNumber != u'0':
|
if self.episodeNumber and self.episodeNumber != u'0':
|
||||||
en = int(self.episodeNumber)
|
en = int(self.episodeNumber)
|
||||||
if en >= 100:
|
if en >= 100:
|
||||||
self.name = "%s S%02dE%02d %s" % (self.title, en / 100, en % 100, self.episode)
|
self.name = "%s S%02dE%02d %s" % (self.title, en / 100, en % 100, self.episode)
|
||||||
else:
|
else:
|
||||||
self.name = "%s E%s %s" % (self.title, self.episodeNumber, self.episode)
|
self.name = "%s E%s %s" % (self.title, self.episodeNumber, self.episode)
|
||||||
else:
|
elif self.unique:
|
||||||
self.name = "%s - %s" % (self.title, self.episode)
|
self.name = "%s - %s" % (self.title, self.episode)
|
||||||
|
else:
|
||||||
|
self.name = "%s - %s - %s" % (self.title, self.datestr, self.episode)
|
||||||
self.dir = "%s/%s" % (targetdir, re.sub("[:/]", "-", self.title))
|
self.dir = "%s/%s" % (targetdir, re.sub("[:/]", "-", self.title))
|
||||||
self.file = "%s/%s" % (self.dir, re.sub("[:/]", "-", self.name))
|
self.file = "%s/%s" % (self.dir, re.sub("[:/]", "-", self.name))
|
||||||
self.name = self.name.encode("utf-8");
|
self.name = self.name.encode("utf-8");
|
||||||
|
@ -168,19 +176,21 @@ class TivoItem:
|
||||||
|
|
||||||
class TivoToc:
|
class TivoToc:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.toc = None
|
self.dom = None
|
||||||
self.filename = "toc.xml"
|
self.filename = "toc.xml"
|
||||||
|
self.uniquedb = anydbm.open("unique.db", "c")
|
||||||
|
self.items = []
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
fd = open(self.filename, "r")
|
fd = open(self.filename, "r")
|
||||||
self.toc = xml.dom.minidom.parseString(fd.read())
|
self.dom = xml.dom.minidom.parseString(fd.read())
|
||||||
fd.close()
|
fd.close()
|
||||||
return self.toc
|
return self.dom
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
fd = open(self.filename, "w")
|
fd = open(self.filename, "w")
|
||||||
fd.write(self.toc.toprettyxml())
|
fd.write(self.dom.toprettyxml())
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
def download_chunk(self, offset):
|
def download_chunk(self, offset):
|
||||||
|
@ -195,7 +205,7 @@ class TivoToc:
|
||||||
}
|
}
|
||||||
url = "https://{}/TiVoConnect".format(host)
|
url = "https://{}/TiVoConnect".format(host)
|
||||||
logger.debug(" offset %d" % (offset))
|
logger.debug(" offset %d" % (offset))
|
||||||
r = session.get(url, params=params)
|
r = session.get(url, params=params, timeout=30)
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
return r.text
|
return r.text
|
||||||
|
@ -203,22 +213,47 @@ class TivoToc:
|
||||||
def download(self):
|
def download(self):
|
||||||
offset = 0
|
offset = 0
|
||||||
itemCount = 1
|
itemCount = 1
|
||||||
self.toc = None
|
self.dom = None
|
||||||
root = None
|
root = None
|
||||||
logger.info("*** Getting listing")
|
logger.info("*** Getting listing")
|
||||||
while itemCount > 0:
|
while itemCount > 0:
|
||||||
dom = xml.dom.minidom.parseString(self.download_chunk(offset))
|
dom = xml.dom.minidom.parseString(self.download_chunk(offset))
|
||||||
if self.toc == None:
|
if self.dom == None:
|
||||||
self.toc = dom
|
self.dom = dom
|
||||||
root = self.toc.childNodes.item(0)
|
root = self.dom.childNodes.item(0)
|
||||||
else:
|
else:
|
||||||
for child in dom.childNodes.item(0).childNodes:
|
for child in dom.childNodes.item(0).childNodes:
|
||||||
if child.nodeName == "Item":
|
if child.nodeName == "Item":
|
||||||
root.appendChild(child.cloneNode(True))
|
root.appendChild(child.cloneNode(True))
|
||||||
itemCount = int(getElementText(dom.documentElement.childNodes, "ItemCount"))
|
itemCount = int(getElementText(dom.documentElement.childNodes, "ItemCount"))
|
||||||
offset += itemCount
|
offset += itemCount
|
||||||
|
return self.dom
|
||||||
|
|
||||||
return self.toc
|
def getItems(self):
|
||||||
|
self.titles = {}
|
||||||
|
for node in self.dom.getElementsByTagName("Item"):
|
||||||
|
item = TivoItem(node)
|
||||||
|
self.items.append(item)
|
||||||
|
if item.title not in self.titles:
|
||||||
|
self.titles[item.title] = []
|
||||||
|
self.titles[item.title].append(item)
|
||||||
|
# see if we have items that end up having an identical name; mark
|
||||||
|
# the program title in uniquedb if that's the case
|
||||||
|
for title in self.titles:
|
||||||
|
names = {}
|
||||||
|
for item in self.titles[title]:
|
||||||
|
if item.name not in names:
|
||||||
|
names[item.name] = []
|
||||||
|
names[item.name].append(item)
|
||||||
|
for name in names:
|
||||||
|
if len(names[name]) > 1:
|
||||||
|
self.uniquedb[title.encode("utf-8")] = "1"
|
||||||
|
if getattr(self.uniquedb, "sync", None) and callable(self.uniquedb.sync):
|
||||||
|
self.uniquedb.sync()
|
||||||
|
for item in self.items:
|
||||||
|
if self.uniquedb.has_key(item.title.encode("utf-8")):
|
||||||
|
item.makeNotUnique()
|
||||||
|
return self.items
|
||||||
|
|
||||||
|
|
||||||
def getText(nodelist):
|
def getText(nodelist):
|
||||||
|
@ -418,10 +453,9 @@ def mirror(toc, downloaddb, one=False):
|
||||||
(targetdir, avail / gig, minfree / gig))
|
(targetdir, avail / gig, minfree / gig))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
items = toc.toc.getElementsByTagName("Item")
|
items = toc.getItems()
|
||||||
logger.info("*** %d shows listed" % (items.length))
|
print "*** %d shows listed" % (len(items))
|
||||||
for node in items:
|
for item in items:
|
||||||
item = TivoItem(node)
|
|
||||||
reason = wantitem(item, downloaddb)
|
reason = wantitem(item, downloaddb)
|
||||||
if reason != "":
|
if reason != "":
|
||||||
logger.debug("*** skipping \"%s\": %s" % (item.name, reason))
|
logger.debug("*** skipping \"%s\": %s" % (item.name, reason))
|
||||||
|
@ -432,7 +466,7 @@ def mirror(toc, downloaddb, one=False):
|
||||||
|
|
||||||
|
|
||||||
def download_episode(toc, downloaddb, episode):
|
def download_episode(toc, downloaddb, episode):
|
||||||
items = toc.toc.getElementsByTagName("Item")
|
items = toc.dom.getElementsByTagName("Item")
|
||||||
for node in items:
|
for node in items:
|
||||||
item = TivoItem(node)
|
item = TivoItem(node)
|
||||||
if item.title == episode or item.name == episode or item.episode == episode:
|
if item.title == episode or item.name == episode or item.episode == episode:
|
||||||
|
@ -440,11 +474,10 @@ def download_episode(toc, downloaddb, episode):
|
||||||
|
|
||||||
|
|
||||||
def printtoc(toc, downloaddb):
|
def printtoc(toc, downloaddb):
|
||||||
items = toc.toc.getElementsByTagName("Item")
|
items = toc.getItems()
|
||||||
print "*** %d shows listed" % (items.length)
|
print "*** %d shows listed" % (len(items))
|
||||||
shows = {}
|
shows = {}
|
||||||
for node in items:
|
for item in items:
|
||||||
item = TivoItem(node)
|
|
||||||
if item.title not in shows:
|
if item.title not in shows:
|
||||||
shows[item.title] = []
|
shows[item.title] = []
|
||||||
shows[item.title].append(item)
|
shows[item.title].append(item)
|
||||||
|
@ -489,6 +522,7 @@ def main():
|
||||||
|
|
||||||
if updateToc or cmd == "mirror":
|
if updateToc or cmd == "mirror":
|
||||||
toc.download()
|
toc.download()
|
||||||
|
toc.save()
|
||||||
else:
|
else:
|
||||||
toc.load()
|
toc.load()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue