diff --git a/autorippr.py b/autorippr.py index 86067d8..4566a5d 100644 --- a/autorippr.py +++ b/autorippr.py @@ -27,7 +27,7 @@ Copyright (c) 2014, Jason Millward @category misc -@version $Id: 1.6, 2014-07-21 18:48:00 CST $; +@version $Id: 1.6.1, 2014-08-18 10:42:00 CST $; @author Jason Millward @license http://opensource.org/licenses/MIT @@ -52,10 +52,11 @@ import os import sys import yaml +import subprocess from classes import * from tendo import singleton -__version__ = "1.6" +__version__ = "1.6.1" me = singleton.SingleInstance() DIR = os.path.dirname(os.path.realpath(__file__)) @@ -212,7 +213,7 @@ def compress(config): log.info("Compressing %s" % dbMovie.moviename) with stopwatch.stopwatch() as t: - status = hb.convert( + status = hb.compress( args=config['handbrake']['com'], nice=int(config['handbrake']['nice']), dbMovie=dbMovie @@ -289,6 +290,15 @@ def extras(config): log.info("Completed work on %s" % dbMovie.moviename) + if config['commands'] is not None and len(config['commands']) > 0: + for com in config['commands']: + proc = subprocess.Popen( + [com], + stderr=subprocess.PIPE, + stdout=subprocess.PIPE, + shell=True + ) + else: log.info("Not grabbing subtitles") database.update_movie(dbMovie, 8) diff --git a/classes/analytics.py b/classes/analytics.py index 7ff287f..cce7b60 100644 --- a/classes/analytics.py +++ b/classes/analytics.py @@ -20,7 +20,7 @@ Copyright (c) 2012, Jason Millward @category misc -@version $Id: 1.6, 2014-07-21 18:48:00 CST $; +@version $Id: 1.6.1, 2014-08-18 10:42:00 CST $; @author Jason Millward @license http://opensource.org/licenses/MIT """ diff --git a/classes/database.py b/classes/database.py index ceb3c8f..39dc5fc 100644 --- a/classes/database.py +++ b/classes/database.py @@ -6,7 +6,7 @@ Copyright (c) 2012, Jason Millward @category misc -@version $Id: 1.6, 2014-07-21 18:48:00 CST $; +@version $Id: 1.6.1, 2014-08-18 10:42:00 CST $; @author Jason Millward @license http://opensource.org/licenses/MIT """ diff --git a/classes/filebot.py b/classes/filebot.py index f5c1b03..1286060 100644 --- a/classes/filebot.py +++ b/classes/filebot.py @@ -6,7 +6,7 @@ Copyright (c) 2012, Jason Millward @category misc -@version $Id: 1.6, 2014-07-21 18:48:00 CST $; +@version $Id: 1.6.1, 2014-08-18 10:42:00 CST $; @author Jason Millward @license http://opensource.org/licenses/MIT """ @@ -46,12 +46,17 @@ def rename(self, dbMovie): stderr=subprocess.PIPE ) - output = proc.stdout.read() + (results, errors) = proc.communicate() + + if proc.returncode is not 0: + self.log.error( + "Filebot (rename) returned status code: %d" % proc.returncode) + renamedMovie = "" checks = 0 - if len(output) is not 0: - lines = output.split("\n") + if len(results) is not 0: + lines = results.split("\n") for line in lines: self.log.debug(line.strip()) if "MOVE" in line: @@ -99,11 +104,16 @@ def get_subtitles(self, dbMovie, lang): stderr=subprocess.PIPE ) + (results, errors) = proc.communicate() + + if proc.returncode is not 0: + self.log.error( + "Filebot (get_subtitles) returned status code: %d" % proc.returncode) + checks = 0 - output = proc.stdout.read() - if len(output) is not 0: - lines = output.split("\n") + if len(results) is not 0: + lines = results.split("\n") for line in lines: self.log.debug(line.strip()) diff --git a/classes/handbrake.py b/classes/handbrake.py index f8316b4..6df8cff 100644 --- a/classes/handbrake.py +++ b/classes/handbrake.py @@ -6,7 +6,7 @@ Copyright (c) 2012, Jason Millward @category misc -@version $Id: 1.6, 2014-07-21 18:48:00 CST $; +@version $Id: 1.6.1, 2014-08-18 10:42:00 CST $; @author Jason Millward @license http://opensource.org/licenses/MIT """ @@ -58,7 +58,7 @@ def check_exists(self, dbMovie): self.log.error("Input file no longer exists") return False - def convert(self, nice, args, dbMovie): + def compress(self, nice, args, dbMovie): """ Passes the nessesary parameters to HandBrake to start an encoding Assigns a nice value to allow give normal system tasks priority @@ -94,36 +94,36 @@ def convert(self, nice, args, dbMovie): str(inMovie), '-o', str(outMovie), - args, - '2>&1' + args ], stdout=subprocess.PIPE, - stderr=subprocess.PIPE + stderr=subprocess.STDOUT ) - # I'm a little confused here - # handbrake cli spits out good information into stderr - # so I'll parse stderr as stdout + (results, errors) = proc.communicate() - if proc.stderr is not None: - output = proc.stderr.read() - if len(output) is not 0: - lines = output.split("\n") - for line in lines: + if proc.returncode is not 0: + self.log.error( + "HandBrakeCLI (compress) returned status code: %d" % proc.returncode) + + if results is not None and len(results) is not 0: + lines = results.split("\n") + for line in lines: + if "Encoding: task" not in line: self.log.debug(line.strip()) - if "average encoding speed for job" in line: - checks += 1 + if "average encoding speed for job" in line: + checks += 1 - if "Encode done!" in line: - checks += 1 + if "Encode done!" in line: + checks += 1 - if "ERROR" in line and "opening" not in line: - self.log.error( - "HandBrakeCLI encountered the following error: ") - self.log.error(line) + if "ERROR" in line and "opening" not in line: + self.log.error( + "HandBrakeCLI encountered the following error: ") + self.log.error(line) - return False + return False if checks >= 2: self.log.debug("HandBrakeCLI Completed successfully") diff --git a/classes/logger.py b/classes/logger.py index be0ad42..4b22809 100644 --- a/classes/logger.py +++ b/classes/logger.py @@ -6,7 +6,7 @@ Copyright (c) 2012, Jason Millward @category misc -@version $Id: 1.6, 2014-07-21 18:48:00 CST $; +@version $Id: 1.6.1, 2014-08-18 10:42:00 CST $; @author Jason Millward @license http://opensource.org/licenses/MIT """ diff --git a/classes/makemkv.py b/classes/makemkv.py index c9b8268..26e3b42 100644 --- a/classes/makemkv.py +++ b/classes/makemkv.py @@ -6,7 +6,7 @@ Copyright (c) 2012, Jason Millward @category misc -@version $Id: 1.6, 2014-07-21 18:48:00 CST $; +@version $Id: 1.6.1, 2014-08-18 10:42:00 CST $; @author Jason Millward @license http://opensource.org/licenses/MIT """ @@ -47,6 +47,8 @@ def _clean_title(self): tmpName = re.sub(r"Disc_(\d)", "", tmpName) + tmpName = tmpName.replace("_t00", "") + tmpName = tmpName.replace("\"", "").replace("_", " ") # Clean up the edges and remove whitespace @@ -144,16 +146,21 @@ def rip_disc(self, path): stdout=subprocess.PIPE ) - if proc.stderr is not None: - output = proc.stderr.read() - if len(output) is not 0: + (results, errors) = proc.communicate() + + if proc.returncode is not 0: + self.log.error( + "MakeMKV (rip_disc) returned status code: %d" % proc.returncode) + + if errors is not None: + if len(errors) is not 0: self.log.error("MakeMKV encountered the following error: ") - self.log.error(output) + self.log.error(errors) return False checks = 0 - output = proc.stdout.read() - lines = output.split("\n") + + lines = results.split("\n") for line in lines: if "skipped" in line: continue @@ -192,20 +199,24 @@ def find_disc(self): """ drives = [] proc = subprocess.Popen( - ['makemkvcon', '-r', 'info'], + ['makemkvcon', '-r', 'info', 'disc:-1'], stderr=subprocess.PIPE, stdout=subprocess.PIPE ) - output = proc.stderr.read() - if proc.stderr is not None: - if len(output) is not 0: + (results, errors) = proc.communicate() + + if proc.returncode is not 0: + self.log.error( + "MakeMKV (find_disc) returned status code: %d" % proc.returncode) + + if errors is not None: + if len(errors) is not 0: self.log.error("MakeMKV encountered the following error: ") - self.log.error(output) + self.log.error(errors) return [] - output = proc.stdout.read() - if "This application version is too old." in output: + if "This application version is too old." in results: self.log.error("Your MakeMKV version is too old." "Please download the latest version at http://www.makemkv.com" " or enter a registration key to continue using MakeMKV.") @@ -213,8 +224,7 @@ def find_disc(self): return [] # Passed the simple tests, now check for disk drives - - lines = output.split("\n") + lines = results.split("\n") for line in lines: if line[:4] == "DRV:": if "/dev/" in line: @@ -255,11 +265,16 @@ def get_disc_info(self): stderr=subprocess.PIPE ) - output = proc.stderr.read() - if proc.stderr is not None: - if len(output) is not 0: + (results, errors) = proc.communicate() + + if proc.returncode is not 0: + self.log.error( + "MakeMKV (get_disc_info) returned status code: %d" % proc.returncode) + + if errors is not None: + if len(errors) is not 0: self.log.error("MakeMKV encountered the following error: ") - self.log.error(output) + self.log.error(errors) return False self.log.debug("MakeMKV found %d titles" % diff --git a/classes/stopwatch.py b/classes/stopwatch.py index aaf0052..8bd96fd 100644 --- a/classes/stopwatch.py +++ b/classes/stopwatch.py @@ -6,7 +6,7 @@ Copyright (c) 2012, Jason Millward @category misc -@version $Id: 1.6, 2014-07-21 18:48:00 CST $; +@version $Id: 1.6.1, 2014-08-18 10:42:00 CST $; @author Jason Millward @license http://opensource.org/licenses/MIT """ diff --git a/classes/testing.py b/classes/testing.py index cae37d6..f02abd2 100644 --- a/classes/testing.py +++ b/classes/testing.py @@ -6,7 +6,7 @@ Copyright (c) 2012, Jason Millward @category misc -@version $Id: 1.6, 2014-07-21 18:48:00 CST $; +@version $Id: 1.6.1, 2014-08-18 10:42:00 CST $; @author Jason Millward @license http://opensource.org/licenses/MIT """ diff --git a/settings.example.cfg b/settings.example.cfg index da1cc40..caafbd5 100644 --- a/settings.example.cfg +++ b/settings.example.cfg @@ -18,6 +18,7 @@ handbrake: nice: 15 # The HandBrake command line options and arguments + # Configure this to change output quality com: --x264-preset=medium --two-pass --turbo -s 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 filebot: @@ -32,3 +33,9 @@ filebot: analytics: enable: True + +commands: + # A list of commands to run after filebot completes + # each line should start with - + # eg: + # - mythutil --scanvideos