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