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"
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"

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'
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: