Skip to content

Commit

Permalink
Merge pull request #73 from JasonMillward/silent-flag
Browse files Browse the repository at this point in the history
Suppress console output
  • Loading branch information
JasonMillward committed Mar 9, 2015
2 parents d8552ad + 41f316e commit 73e9876
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 200 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ settings.cfg

# Log files
*.log


.idea
98 changes: 50 additions & 48 deletions autorippr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Compressing
An optional additional used to rename and compress movies to an acceptable standard
which still delivers quallity audio and video but reduces the file size
which still delivers quality audio and video but reduces the file size
dramatically.
Using a nice value of 15 by default, it runs HandBrake (or FFmpeg) as a background task
Expand Down Expand Up @@ -46,6 +46,7 @@
--extra Lookup, rename and/or download extras.
--all Do everything
--test Tests config and requirements
--silent Silent mode
"""

Expand All @@ -56,19 +57,19 @@
from classes import *
from tendo import singleton

__version__ = "1.6.1"
__version__ = "1.6.2"

me = singleton.SingleInstance()
DIR = os.path.dirname(os.path.realpath(__file__))
CONFIG_FILE = "%s/settings.cfg" % DIR


def eject(drive):
def eject(config, drive):
"""
Ejects the DVD drive
Not really worth its own class
"""
log = logger.logger("Eject", True)
log = logger.Logger("Eject", config['debug'], config['silent'])

log.debug("Ejecting drive: " + drive)
log.debug("Attempting OS detection")
Expand Down Expand Up @@ -115,19 +116,19 @@ def rip(config):
Does everything
Returns nothing
"""
log = logger.logger("Rip", config['debug'])
log = logger.Logger("Rip", config['debug'], config['silent'])

mkv_save_path = config['makemkv']['savePath']

log.debug("Ripping initialised")
mkv_api = makemkv.makeMKV(config)
mkv_api = makemkv.MakeMKV(config)

log.debug("Checking for DVDs")
dvds = mkv_api.find_disc()

log.debug("%d DVDs found" % len(dvds))

if (len(dvds) > 0):
if len(dvds) > 0:
# Best naming convention ever
for dvd in dvds:
mkv_api.set_title(dvd["discTitle"])
Expand All @@ -139,50 +140,50 @@ def rip(config):
if not os.path.exists(movie_path):
os.makedirs(movie_path)

dbMovie = database.insert_movie(
dbmovie = database.insert_movie(
movie_title,
movie_path,
config['filebot']['enable']
)

database.insert_history(
dbMovie,
dbmovie,
"Movie added to database"
)

mkv_api.get_disc_info()

if len( mkv_api.get_savefile() ) != 0:
database.update_movie(dbMovie, 3, mkv_api.get_savefile())
database.update_movie(dbmovie, 3, mkv_api.get_savefile())

with stopwatch.stopwatch() as t:
with stopwatch.StopWatch() as t:
database.insert_history(
dbMovie,
dbmovie,
"Movie submitted to MakeMKV"
)
status = mkv_api.rip_disc(mkv_save_path)

if status:
if config['makemkv']['eject']:
eject(dvd['location'])
eject(config, dvd['location'])

log.info("It took %s minute(s) to complete the ripping of %s" %
(t.minutes, movie_title)
)

database.update_movie(dbMovie, 4)
database.update_movie(dbmovie, 4)

else:
log.info("MakeMKV did not did not complete successfully")
log.info("See log for more details")
log.debug("Movie title: %s" % movie_title)

database.insert_history(
dbMovie,
dbmovie,
"MakeMKV failed to rip movie"
)

database.update_movie(dbMovie, 2)
database.update_movie(dbmovie, 2)
else:
log.info("No movie titles found")
log.info("Try decreasing 'minLength' in the config and try again")
Expand All @@ -200,58 +201,57 @@ def compress(config):
Does everything
Returns nothing
"""
log = logger.logger("Compress", config['debug'])
log = logger.Logger("Compress", config['debug'], config['silent'])

if config['compress']['type'] == "ffmpeg":
comp = ffmpeg.ffmpeg(config['debug'])
else:
comp = handbrake.handBrake(config['debug'], config['compress']['compressionPath']);
comp = compression.Compression(config)

log.debug("Compressing initialised")
log.debug("Looking for movies to compress")

dbMovie = database.next_movie_to_compress()
dbmovie = database.next_movie_to_compress()

if dbMovie is not None:
if comp.check_exists(dbMovie) is not False:
if dbmovie is not None:
if comp.check_exists(dbmovie) is not False:

database.update_movie(dbMovie, 5)
database.update_movie(dbmovie, 5)

log.info("Compressing %s" % dbMovie.moviename)
log.info("Compressing %s" % dbmovie.moviename)

with stopwatch.stopwatch() as t:
with stopwatch.StopWatch() as t:
status = comp.compress(
args=config['compress']['com'],
nice=int(config['compress']['nice']),
dbMovie=dbMovie
dbmovie=dbmovie
)

if status:
log.info("Movie was compressed and encoded successfully")

log.info(("It took %s minutes to compress %s" %
(t.minutes, dbMovie.moviename))
(t.minutes, dbmovie.moviename))
)

database.insert_history(
dbMovie,
dbmovie,
"Compression Completed successfully"
)

database.update_movie(
dbMovie, 6, filename="%s.mkv" % dbMovie.moviename)
dbmovie, 6, filename="%s.mkv" % dbmovie.moviename)

comp.cleanup()

else:
database.update_movie(dbMovie, 5)
database.update_movie(dbmovie, 5)

database.insert_history(dbMovie, "Compression failed", 4)
database.insert_history(dbmovie, "Compression failed", 4)

log.info("Compression did not complete successfully")
else:
database.update_movie(dbMovie, 2)
database.update_movie(dbmovie, 2)

database.insert_history(
dbMovie, "Input file no longer exists", 4
dbmovie, "Input file no longer exists", 4
)

else:
Expand All @@ -264,42 +264,42 @@ def extras(config):
Does everything
Returns nothing
"""
log = logger.logger("Extras", config['debug'])
log = logger.Logger("Extras", config['debug'], config['silent'])

fb = filebot.filebot(config['debug'])
fb = filebot.FileBot(config['debug'], config['silent'])

dbMovie = database.next_movie_to_filebot()
dbmovie = database.next_movie_to_filebot()

if dbMovie is not None:
if dbmovie is not None:
log.info("Attempting movie rename")

database.update_movie(dbMovie, 7)
database.update_movie(dbmovie, 7)

status = fb.rename(dbMovie)
status = fb.rename(dbmovie)

if status[0]:
log.info("Rename success")
database.update_movie(dbMovie, 6, filename=status[1])
database.update_movie(dbmovie, 6, filename=status[1])

if config['filebot']['subtitles']:
log.info("Grabbing subtitles")

status = fb.get_subtitles(
dbMovie, config['filebot']['language'])
dbmovie, config['filebot']['language'])

if status:
log.info("Subtitles downloaded")
database.update_movie(dbMovie, 8)
database.update_movie(dbmovie, 8)

else:
log.info("Subtitles not downloaded, no match")
database.update_movie(dbMovie, 8)
database.update_movie(dbmovie, 8)

log.info("Completed work on %s" % dbMovie.moviename)
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(
subprocess.Popen(
[com],
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
Expand All @@ -308,7 +308,7 @@ def extras(config):

else:
log.info("Not grabbing subtitles")
database.update_movie(dbMovie, 8)
database.update_movie(dbmovie, 8)

else:
log.info("Rename failed")
Expand All @@ -323,6 +323,8 @@ def extras(config):

config['debug'] = arguments['--debug']

config['silent'] = arguments['--silent']

if bool(config['analytics']['enable']):
analytics.ping(__version__)

Expand Down
10 changes: 5 additions & 5 deletions classes/analytics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Basic analtics
Basic analytics
The purpose of this file is to simply send a 'ping' with a unique identifier
and the script version once a day to give an indication of unique users
Expand Down Expand Up @@ -43,12 +43,12 @@ def ping(version):
"version": version
}

dateFile = "/tmp/%s" % time.strftime("%Y%m%d")
datefile = "/tmp/%s" % time.strftime("%Y%m%d")

if not os.path.isfile(dateFile):
if not os.path.isfile(datefile):

with open(dateFile, 'w'):
os.utime(dateFile, None)
with open(datefile, 'w'):
os.utime(datefile, None)

requests.post(
'http://api.jcode.me/autorippr/stats',
Expand Down
Loading

0 comments on commit 73e9876

Please sign in to comment.