Add postprocess configuration

This commit is contained in:
Stefan Bethke 2017-09-18 14:09:03 +02:00
parent e726390c5f
commit f91a6afc70
2 changed files with 17 additions and 7 deletions

View file

@ -5,6 +5,7 @@ shows:
- series: "Dirk Gently's Holistic Detective Agency" - series: "Dirk Gently's Holistic Detective Agency"
short: "Dirk Gently" short: "Dirk Gently"
host: "wavehh.lassitu.de:30080" host: "wavehh.lassitu.de:30080"
postprocess: 'NQDIR=/home/stb/.tivo/nq nq archivevideo "{item.target}"'
proxies: proxies:
http: "http://us.lassitu.de:8888" http: "http://us.lassitu.de:8888"
https: "http://us.lassitu.de:8888" https: "http://us.lassitu.de:8888"

View file

@ -47,6 +47,7 @@ class Config:
useragent = 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0' useragent = 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0'
def __init__(self, file=None): def __init__(self, file=None):
self.postprocess = None
if file: if file:
self.config = file self.config = file
self.load(self.config) self.load(self.config)
@ -72,11 +73,11 @@ class Config:
if 'short' in show and 'series' in show: if 'short' in show and 'series' in show:
IncludeShow(show['series'], show['short']) IncludeShow(show['series'], show['short'])
else: else:
logger.error("Need either a string or a dict with 'series' and 'short' entries for a show, got \"{}\".".format\ logger.error("Need either a string, or a dict with 'series' and 'short' entries for a show, got \"{}\".".format\
(show)) (show))
sys.exit(1) sys.exit(1)
else: else:
IncludeShow(key) IncludeShow(show)
def __repr__(self): def __repr__(self):
return "Config options for tivomirror (singleton)" return "Config options for tivomirror (singleton)"
@ -447,34 +448,42 @@ def download_item(item, mak, target):
def download_decode(item, options, mak): def download_decode(item, options, mak):
target = "{}.mpg".format(item.getPath(options)) item.target = "{}.mpg".format(item.getPath(options))
try: try:
os.makedirs(item.dir) os.makedirs(item.dir)
except OSError: except OSError:
pass pass
try: try:
download_item(item, mak, target) download_item(item, mak, item.target)
except Exception, e: except Exception, e:
exc_info = sys.exc_info() exc_info = sys.exc_info()
try: try:
os.remove(target) os.remove(item.target)
except Exception, e2: except Exception, e2:
pass pass
raise exc_info[1], None, exc_info[2] raise exc_info[1], None, exc_info[2]
try: try:
os.utime(target, (item.time, item.time)) os.utime(item.target, (item.time, item.time))
except Exception, e: except Exception, e:
logger.error("Problem setting timestamp: {}".format(e)) logger.error("Problem setting timestamp: {}".format(e))
def download_one(item, downloaddb, options): def download_one(item, downloaddb, options):
global logger global config, logger
logger.info("*** downloading \"{}\": {:.3f} GB".format(item.name, item.sourcesize / 1e9)) logger.info("*** downloading \"{}\": {:.3f} GB".format(item.name, item.sourcesize / 1e9))
try: try:
download_decode(item, options, config.mak) download_decode(item, options, config.mak)
downloaddb[item.name] = item.datestr downloaddb[item.name] = item.datestr
if getattr(downloaddb, "sync", None) and callable(downloaddb.sync): if getattr(downloaddb, "sync", None) and callable(downloaddb.sync):
downloaddb.sync() downloaddb.sync()
if config.postprocess:
cmd = config.postprocess
try:
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:
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, e: