From f91a6afc703f00c04e31b5710e43a1a74799f5ad Mon Sep 17 00:00:00 2001 From: Stefan Bethke Date: Mon, 18 Sep 2017 14:09:03 +0200 Subject: [PATCH] Add postprocess configuration --- config.yaml | 1 + tivomirror.py | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/config.yaml b/config.yaml index 1659f0a..b827b41 100644 --- a/config.yaml +++ b/config.yaml @@ -5,6 +5,7 @@ shows: - series: "Dirk Gently's Holistic Detective Agency" short: "Dirk Gently" host: "wavehh.lassitu.de:30080" +postprocess: 'NQDIR=/home/stb/.tivo/nq nq archivevideo "{item.target}"' proxies: http: "http://us.lassitu.de:8888" https: "http://us.lassitu.de:8888" diff --git a/tivomirror.py b/tivomirror.py index 2d22c2e..739c753 100755 --- a/tivomirror.py +++ b/tivomirror.py @@ -47,6 +47,7 @@ class Config: useragent = 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0' def __init__(self, file=None): + self.postprocess = None if file: self.config = file self.load(self.config) @@ -72,11 +73,11 @@ class Config: if 'short' in show and 'series' in show: IncludeShow(show['series'], show['short']) 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)) sys.exit(1) else: - IncludeShow(key) + IncludeShow(show) def __repr__(self): return "Config options for tivomirror (singleton)" @@ -447,34 +448,42 @@ def download_item(item, mak, target): def download_decode(item, options, mak): - target = "{}.mpg".format(item.getPath(options)) + item.target = "{}.mpg".format(item.getPath(options)) try: os.makedirs(item.dir) except OSError: pass try: - download_item(item, mak, target) + download_item(item, mak, item.target) except Exception, e: exc_info = sys.exc_info() try: - os.remove(target) + os.remove(item.target) except Exception, e2: pass raise exc_info[1], None, exc_info[2] try: - os.utime(target, (item.time, item.time)) + os.utime(item.target, (item.time, item.time)) except Exception, e: logger.error("Problem setting timestamp: {}".format(e)) def download_one(item, downloaddb, options): - global logger + global config, logger logger.info("*** downloading \"{}\": {:.3f} GB".format(item.name, item.sourcesize / 1e9)) try: download_decode(item, options, config.mak) downloaddb[item.name] = item.datestr if getattr(downloaddb, "sync", None) and callable(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...") time.sleep(30) except TivoException, e: