Skip to content

Commit

Permalink
Mering
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMillward committed Oct 31, 2015
2 parents 333a89d + a680cf7 commit 99ae31a
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 3 deletions.
19 changes: 17 additions & 2 deletions autorippr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down Expand Up @@ -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'])

Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand All @@ -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'])

Expand Down Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions classes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'handbrake',
'logger',
'makemkv',
'notification',
'stopwatch',
'testing'
]
2 changes: 1 addition & 1 deletion classes/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Videos(BaseModel):
lastupdated = DateTimeField(db_column='lastUpdated')

class Meta:
db_table = 'movies'
db_table = 'videos'


class Statustypes(BaseModel):
Expand Down
66 changes: 66 additions & 0 deletions classes/notification.py
Original file line number Diff line number Diff line change
@@ -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 == '[email protected]':
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)
25 changes: 25 additions & 0 deletions settings.example.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]

# Email Username's Password
smtp_password: my_password

# Source email, usually smtp_username
source_email: [email protected]

# Destination Email
destination_email: [email protected]

analytics:
enable: True
Expand Down

0 comments on commit 99ae31a

Please sign in to comment.