Skip to content

Commit

Permalink
Merge pull request #58 from JasonMillward/dev
Browse files Browse the repository at this point in the history
Fixes #53
  • Loading branch information
JasonMillward committed Aug 18, 2014
2 parents 9cb87f2 + a70aaf0 commit 51708e7
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 57 deletions.
16 changes: 13 additions & 3 deletions autorippr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
@license http://opensource.org/licenses/MIT
Expand All @@ -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__))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion classes/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
@license http://opensource.org/licenses/MIT
"""
Expand Down
2 changes: 1 addition & 1 deletion classes/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
@license http://opensource.org/licenses/MIT
"""
Expand Down
24 changes: 17 additions & 7 deletions classes/filebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
@license http://opensource.org/licenses/MIT
"""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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())

Expand Down
44 changes: 22 additions & 22 deletions classes/handbrake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
@license http://opensource.org/licenses/MIT
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion classes/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
@license http://opensource.org/licenses/MIT
"""
Expand Down
55 changes: 35 additions & 20 deletions classes/makemkv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
@license http://opensource.org/licenses/MIT
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -192,29 +199,32 @@ 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.")

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:
Expand Down Expand Up @@ -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" %
Expand Down
2 changes: 1 addition & 1 deletion classes/stopwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
@license http://opensource.org/licenses/MIT
"""
Expand Down
2 changes: 1 addition & 1 deletion classes/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
@license http://opensource.org/licenses/MIT
"""
Expand Down
7 changes: 7 additions & 0 deletions settings.example.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

0 comments on commit 51708e7

Please sign in to comment.