JBOPS/notify/notify_on_added.py

103 lines
3.8 KiB
Python
Raw Normal View History

2017-07-12 18:00:01 +00:00
"""
Tautulli > Settings > Notification Agents > Scripts > Bell icon:
2017-07-12 18:00:01 +00:00
[X] Notify on Recently Added
Tautulli > Settings > Notification Agents > Scripts > Gear icon:
2017-07-12 18:00:01 +00:00
Recently Added: notify_on_added.py
Tautulli > Settings > Notifications > Script > Script Arguments:
2017-07-12 18:00:01 +00:00
-sn {show_name} -ena {episode_name} -ssn {season_num00} -enu {episode_num00} -srv {server_name} -med {media_type} -pos {poster_url} -tt {title} -sum {summary} -lbn {library_name}
You can add more arguments if you want more details in the email body
"""
2016-09-13 17:21:26 +00:00
from email.mime.text import MIMEText
import email.utils
import smtplib
import sys
2016-09-29 03:08:32 +00:00
import argparse
2016-09-13 17:21:26 +00:00
2016-09-29 03:08:32 +00:00
parser = argparse.ArgumentParser()
parser.add_argument('-sn', '--show_name', action='store', default='',
help='The name of the TV show')
parser.add_argument('-ena', '--episode_name', action='store', default='',
help='The name of the episode')
parser.add_argument('-ssn', '--season_num', action='store', default='',
help='The season number of the TV show')
parser.add_argument('-enu', '--episode_num', action='store', default='',
help='The episode number of the TV show')
parser.add_argument('-srv', '--plex_server', action='store', default='',
help='The name of the Plex server')
parser.add_argument('-med', '--show_type', action='store', default='',
help='The type of media')
parser.add_argument('-pos', '--poster', action='store', default='',
help='The poster url')
parser.add_argument('-tt', '--title', action='store', default='',
help='The title of the TV show')
parser.add_argument('-sum', '--summary', action='store', default='',
help='The summary of the TV show')
parser.add_argument('-lbn', '--library_name', action='store', default='',
help='The name of the TV show')
p = parser.parse_args()
2016-09-13 17:21:26 +00:00
# Edit user@email.com and shows
users = [{'email': 'user1@gmail.com',
'shows': ('show1', 'show2')
},
{'email': 'user2@gmail.com',
'shows': ('show1', 'show2', 'show3')
},
{'email': 'user3@gmail.com',
'shows': ('show1', 'show2', 'show3', 'show4')
}]
# Kill script now if show_name is not in lists
2016-10-03 12:09:29 +00:00
too = list('Match' for u in users if p.show_name in u['shows'])
if not too:
2017-07-12 18:00:01 +00:00
print 'Kill script now show_name is not in lists'
2016-09-30 18:04:42 +00:00
exit()
# Join email addresses
to = list([u['email'] for u in users if p.show_name in u['shows']])
2016-09-13 17:21:26 +00:00
# Email settings
name = 'Tautulli' # Your name
2016-09-13 17:21:26 +00:00
sender = 'sender' # From email address
email_server = 'smtp.gmail.com' # Email server (Gmail: smtp.gmail.com)
email_port = 587 # Email port (Gmail: 587)
email_username = 'email' # Your email username
email_password = 'password' # Your email password
2016-09-29 03:08:32 +00:00
email_subject = 'New episode for ' + p.show_name + ' is available on ' + p.plex_server # The email subject
2016-09-13 17:21:26 +00:00
2016-09-29 03:08:32 +00:00
# Detailed body for tv shows
2016-09-13 17:21:26 +00:00
show_html = """\
<html>
<head></head>
<body>
<p>Hi!<br>
2016-09-29 03:08:32 +00:00
{p.show_name} S{p.season_num} - E{p.episode_num} -- {p.episode_name} -- was recently added to {p.library_name} on PLEX
2016-09-13 17:21:26 +00:00
<br><br>
2016-09-29 03:08:32 +00:00
<br> {p.summary} <br>
<br><img src="{p.poster}" alt="Poster unavailable" height="150" width="102"><br>
2016-09-13 17:21:26 +00:00
</p>
</body>
</html>
2016-09-29 03:08:32 +00:00
""".format(p=p)
2016-09-13 17:21:26 +00:00
### Do not edit below ###
2016-09-29 03:08:32 +00:00
# Check to see whether it is a tv show
if p.show_type.lower() == 'show' or p.show_type.lower() == 'episode':
2016-09-13 17:21:26 +00:00
message = MIMEText(show_html, 'html')
message['Subject'] = email_subject
message['From'] = email.utils.formataddr((name, sender))
2016-09-13 17:21:26 +00:00
mailserver = smtplib.SMTP(email_server, email_port)
mailserver.starttls()
mailserver.ehlo()
mailserver.login(email_username, email_password)
mailserver.sendmail(sender, to, message.as_string())
mailserver.quit()
else:
2016-09-30 18:04:42 +00:00
exit()