Compare commits

...

1 commit

Author SHA1 Message Date
823129f1d8 WIP 2020-11-25 21:26:48 +01:00

View file

@ -1,14 +1,10 @@
#!/usr/local/bin/python
#!/usr/local/bin/python
# -*- coding: utf8 -*-
# Download shows from the Tivo
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import anydbm
import cookielib
import dbm
import http.cookiejar
import datetime
import getopt
import errno
@ -25,7 +21,7 @@ import subprocess
import sys
import threading
import time
import urllib2
import urllib
import xml.dom.minidom
import yaml
@ -164,7 +160,7 @@ def trimDescription(desc):
return desc
def saveCookies(session, filename):
cj = cookielib.MozillaCookieJar(filename)
cj = http.cookiejar.MozillaCookieJar(filename)
for cookie in session.cookies:
logger.debug("storing cookie {}".format(cookie))
cj.set_cookie(cookie)
@ -249,7 +245,7 @@ class TivoToc:
def __init__(self):
self.dom = None
self.filename = "toc.xml"
self.uniquedb = anydbm.open("unique.db", "c")
self.uniquedb = dbm.open("unique.db", "c")
self.items = []
pass
@ -400,9 +396,9 @@ def download_item(item, mak, target):
upd = time.time()
dur = now - start
mb = count / 1e6
print "{:5.1f}% {:5.3f} GB downloaded in {:.0f} min, {.3f} MB/s".format(
print("{:5.1f}% {:5.3f} GB downloaded in {:.0f} min, {.3f} MB/s".format(
100.0 * count / item.sourcesize,
mb / 1e3, dur / 60, mb / dur)
mb / 1e3, dur / 60, mb / dur))
try:
signal.signal(signal.SIGINFO, info)
except Exception:
@ -443,7 +439,7 @@ def download_item(item, mak, target):
if p_decode.returncode == None:
logger.debug("terminating tivodecode")
p_decode.terminate()
except Exception, e:
except Exception as e:
pass
p_decode.wait()
logger.info("tivodecode exited with {}".format(p_decode.returncode))
@ -462,16 +458,15 @@ def download_decode(item, options, mak):
pass
try:
download_item(item, mak, item.target)
except Exception, e:
exc_info = sys.exc_info()
except Exception as e:
try:
os.remove(item.target)
except Exception, e2:
except Exception as e2:
pass
raise exc_info[1], None, exc_info[2]
raise e
try:
os.utime(item.target, (item.time, item.time))
except Exception, e:
except Exception as e:
logger.error("Problem setting timestamp: {}".format(e))
@ -489,11 +484,11 @@ def download_one(item, downloaddb, options):
cmd = cmd.format(item=item, options=options, config=config)
r = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
logger.debug("Post-process {}: {}".format(cmd, r))
except Exception, e:
except Exception as e:
logger.warn("Error running postprocess command '{}' for item {}: {}".format(cmd, item, e))
logger.debug("Sleeping 30 seconds before moving on...")
time.sleep(30)
except TivoException, e:
except TivoException as e:
logger.info("Error processing \"{}\": {}".format(item.name, e))
@ -543,7 +538,7 @@ def download_episode(toc, downloaddb, episode):
def printtoc(toc, downloaddb):
items = toc.getItems()
print "*** {} shows listed".format(len(items))
print("*** {} shows listed".format(len(items)))
shows = {}
for item in items:
if item.title not in shows:
@ -553,10 +548,10 @@ def printtoc(toc, downloaddb):
for item in sorted(shows[title], key=lambda i: i.name):
options = wantitem(item, downloaddb)
if isinstance(options, basestring):
print "{:>7.7s}: {}".format(options, item.name)
print("{:>7.7s}: {}".format(options, item.name))
continue
print "*** downloading {} ({:.3f} GB)".format(item.name, item.sourcesize / 1e9)
print "*** {} shows listed".format(len(items))
print("*** downloading {} ({:.3f} GB)".format(item.name, item.sourcesize / 1e9))
print("*** {} shows listed".format(len(items)))
def usage():
@ -573,7 +568,7 @@ def main():
handler.setFormatter(logging.Formatter(fmt='tivomirror[{}] %(asctime)s %(levelname)6.6s %(message)s'.format(os.getpid()),
datefmt='%d-%m %H:%M:%S'))
logger.addHandler(handler)
downloaddb = anydbm.open("downloads.db", "c")
downloaddb = dbm.open("downloads.db", "c")
toc = TivoToc()
cmd = "list"
updateToc = False