diff --git a/autorippr.py b/autorippr.py index dc2ed65..a4a83b2 100755 --- a/autorippr.py +++ b/autorippr.py @@ -117,6 +117,8 @@ def rip(config): Returns nothing """ log = logger.Logger("Rip", config['debug'], config['silent']) + + notify = notification.Notification(config) mkv_save_path = config['makemkv']['savePath'] @@ -204,10 +206,13 @@ def rip(config): else: log.info("No video titles found") log.info("Try decreasing 'minLength' in the config and try again") - + else: log.info("Video folder %s already exists" % disc_title) + if config['notification']['smtp_enable'] and 'rip' in config['notification']['smtp_state']: + notify.rip_complete(dbvideo) + if config['makemkv']['eject']: eject(config, dvd['location']) @@ -222,6 +227,8 @@ def compress(config): Returns nothing """ log = logger.Logger("Compress", config['debug'], config['silent']) + + notify = notification.Notification(config) comp = compression.Compression(config) @@ -255,7 +262,10 @@ def compress(config): dbvideo, "Compression Completed successfully" ) - + + if config['notification']['smtp_enable'] and 'compress' in config['notification']['smtp_state']: + notify.compress_complete(dbvideo) + comp.cleanup() else: @@ -282,6 +292,8 @@ def extras(config): Returns nothing """ log = logger.Logger("Extras", config['debug'], config['silent']) + + notify = notification.Notification(config) fb = filebot.FileBot(config['debug'], config['silent']) @@ -334,6 +346,9 @@ def extras(config): else: log.info("Not grabbing subtitles") database.update_video(dbvideo, 8) + + if config['notification']['smtp_enable'] and 'extra' in config['notification']['smtp_state']: + notify.extra_complete(dbvideo) else: log.info("Rename failed") diff --git a/classes/__init__.py b/classes/__init__.py index 7012e0e..5dde77b 100755 --- a/classes/__init__.py +++ b/classes/__init__.py @@ -8,6 +8,7 @@ 'handbrake', 'logger', 'makemkv', + 'notification', 'stopwatch', 'testing' ] diff --git a/classes/database.py b/classes/database.py index f3fc8a2..ed772e8 100755 --- a/classes/database.py +++ b/classes/database.py @@ -56,7 +56,7 @@ class Videos(BaseModel): lastupdated = DateTimeField(db_column='lastUpdated') class Meta: - db_table = 'movies' + db_table = 'videos' class Statustypes(BaseModel): diff --git a/classes/notification.py b/classes/notification.py new file mode 100644 index 0000000..54e33d1 --- /dev/null +++ b/classes/notification.py @@ -0,0 +1,66 @@ +""" +Notification Class + + +Released under the MIT license +Copyright (c) 2014, Ian Bird + +@category misc +@version $Id: 1.7-test2, 2015-05-11 07:48:38 ACST $; +@author Jacob Carrigan +@license http://opensource.org/licenses/MIT +""" + +import os +import subprocess +import logger + +class Notification(object): + + def __init__(self, config): + self.log = logger.Logger("notification", config['debug'], config['silent']) + self.server = config['notification']['smtp_server'] + self.username = config['notification']['smtp_username'] + self.password = config['notification']['smtp_password'] + self.port = config['notification']['smtp_port'] + self.to_address = config['notification']['destination_email'] + self.from_address = config['notification']['source_email'] + + def _send(self, status): + import smtplib + from email.MIMEMultipart import MIMEMultipart + from email.MIMEText import MIMEText + + if self.from_address == 'username@gmail.com': + self.logging.error('Email address has not been set correctly, ignoring send request from: %s' % self.from_address) + return + + msg = MIMEMultipart() + msg['From'] = self.from_address + msg['To'] = self.to_address + msg['Subject'] = "Autorippr" + + body = status + msg.attach(MIMEText(body, 'plain')) + + server = smtplib.SMTP(self.server, self.port) + server.starttls() + server.login(self.from_address, self.password) + text = msg.as_string() + server.sendmail(self.from_address, self.to_address, text) + server.quit() + + def rip_complete(self,dbvideo): + + status = 'Rip of %s complete' % dbvideo.vidname + self._send(status) + + def compress_complete(self,dbvideo): + + status = 'Compress of %s complete' % dbvideo.vidname + self._send(status) + + def extra_complete(self,tracks,dbvideo): + + status = 'Extra of %s complete' % dbvideo.vidname + self._send(status) diff --git a/settings.example.cfg b/settings.example.cfg index fb9461d..ca8031d 100755 --- a/settings.example.cfg +++ b/settings.example.cfg @@ -73,6 +73,31 @@ filebot: # TV Folder tvPath: /tmp/tvshows + +notification: + # Enable email notification + smtp_enable: False + + # Email state + smtp_state: rip, compress, extra + + # Outgoing Mail Server (smtp.live.com, smtp.mail.yahoo.com) + smtp_server: smtp.gmail.com + + # Outgoing Mail Port (Hotmail 587, Yahoo 995) + smtp_port: 465 + + # Email Username + smtp_username: username@gmail.com + + # Email Username's Password + smtp_password: my_password + + # Source email, usually smtp_username + source_email: username@gmail.com + + # Destination Email + destination_email: to_address@gmail.com analytics: enable: True