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