Skip to content

Commit

Permalink
New Features
Browse files Browse the repository at this point in the history
Can now set days, hours and minutes and use all fields in the search.
Can now filter categories
Ease of Use updates
  • Loading branch information
jakewaldron committed Mar 13, 2015
1 parent 9897f8a commit 323f006
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 45 deletions.
30 changes: 12 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ This script aggregates all new TV and movie releases for the past x days and wri
## Supported Environments
* Windows - Tested
* Linux - Tested
* Mac
* Mac - Tested

## Supported Email Protocols
* SMTP

## Prerequisites

1. Python 2.7 - 32 bit - https://www.python.org/ftp/python/2.7.9/python-2.7.9.msi
2. 32 bit DLL for SQLite version 3.8.8.3 - http://www.sqlite.org/2015/sqlite-dll-win32-x86-3080803.zip (Put this into the DLLs folder of the Python installation)
3. If web reports are wanted, a web server (i.e. Wamp, Apache, etc.)
1. Python 2.7 - Windows: 32 bit - https://www.python.org/ftp/python/2.7.9/python-2.7.9.msi
2. Windows - 32 bit DLL for SQLite version 3.8.8.3 - http://www.sqlite.org/2015/sqlite-dll-win32-x86-3080803.zip (Put this into the DLLs folder of the Python installation)
3. Requests module for Python. pip install requests or download it here and put it in the LIb folder of your Python installation: https://pypi.python.org/packages/source/r/requests/requests-2.5.3.tar.gz#md5=23bf4fcc89ea8d353eb5353bb4a475b1
4. If web reports are wanted, a web server (i.e. Wamp, Apache, etc.)


## Installation (Windows)
Expand Down Expand Up @@ -88,19 +89,6 @@ python plexEmail.py -c C:\files\plexEmailWeekly.conf

The config file is in the scripts folder. Before first run of the script, please update this file with your information.

####Required Fields to Update:

* plex_data_folder
* web_folder
* web_domain
* web_path
* email_to
* email_from
* email_smtp_address (gmail default)
* email_smtp_port
* email_username
* email_password

####Field Explanations:

#####Folder Paths
Expand All @@ -110,8 +98,8 @@ The config file is in the scripts folder. Before first run of the script, pleas
#####General
* date_format - Format to use for the date
* date_days_back_to_search - Number of days to search backwards
* date_use_hours - Search back y hours instead of days (useful for 24 hours reports)
* date_hours_back_to_search - Number of hours to search backwards
* date_minutes_back_to_search - Number of minutes to search backwards

#####Web
* web_enabled - Enable the creation of the web page
Expand Down Expand Up @@ -141,6 +129,12 @@ The config file is in the scripts folder. Before first run of the script, pleas
* email_use_web_images - Use images from the web server instead of attaching them directly to the email
* email_skip_if_no_additions - True to skip sending emails if there are no new additions

#####Filtering
* filter_show_movies - True to show recently added movies
* filter_show_shows - True to show recently added TV shows
* filter_show_seasons - True to show recently added TV seasons
* filter_show_episodes - True to show recently added TV episodes

#####Messages
* msg_email_teaser - Teaser text on the email
* msg_web_title - Title of the webpage
Expand Down
15 changes: 11 additions & 4 deletions scripts/config.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
##Folder Paths
# Windows Example: 'E:\\Library\\Plex\\'
# Linux/Mac Example: '/var/lib/plexmediaserver/Library/Application Support/'
# Windows Example: 'C:\\Users\\{User Name}\\AppData\\Local\\'
# Linux Example: '/var/lib/plexmediaserver/Library/Application Support/'
# Mac Example: '/Users/{User Name}/Library/Application Support/'
plex_data_folder = ''
# Windows Example: 'C:\\wamp\\www\\'
# Linux/Mac Example: '/var/www/'
Expand All @@ -9,8 +10,8 @@ web_folder = ''
##General
date_format = '%m/%d/%y'
date_days_back_to_search = 7
date_use_hours = False
date_hours_back_to_search = 24
date_hours_back_to_search = 0
date_minutes_back_to_search = 0

##Image Upload - If this option is enabled, image hosting will be used for web and email
#Cloudinary - Sign up for a free account at: http://cloudinary.com/
Expand Down Expand Up @@ -41,6 +42,12 @@ email_password = ''
email_use_web_images = True
email_skip_if_no_additions = False

##Filtering
filter_show_movies = True
filter_show_shows = True
filter_show_seasons = True
filter_show_episodes = True

##Messages
msg_email_teaser = 'Check out this week\'s releases from Plex: {website} - {past_day} - {current_day}'
msg_web_title = 'New Plex Releases'
Expand Down
67 changes: 44 additions & 23 deletions scripts/plexEmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@

def replaceConfigTokens():
## The below code is for backwards compatibility
if ('filter_show_movies' not in config):
config['filter_show_movies'] = True

if ('filter_show_shows' not in config):
config['filter_show_shows'] = True

if ('filter_show_seasons' not in config):
config['filter_show_seasons'] = True

if ('filter_show_episodes' not in config):
config['filter_show_episodes'] = True

if ('date_minutes_back_to_search' not in config):
config['date_minutes_back_to_search'] = 0

if ('msg_no_new_content' not in config):
config['msg_no_new_content'] = 'There have been no new additions to Plex from {past_day} through {current_day}.'

Expand Down Expand Up @@ -85,18 +100,18 @@ def replaceConfigTokens():
# The below code is replacing tokens
for value in config:
if (isinstance(config[value], str)):
if ('date_use_hours' in config and config['date_use_hours']):
config[value] = config[value].replace('{past_day}', str((date.today() - timedelta(hours=config['date_hours_back_to_search'])).strftime(config['date_format'])))
else:
config[value] = config[value].replace('{past_day}', str((date.today() - timedelta(days=config['date_days_back_to_search'])).strftime(config['date_format'])))
config[value] = config[value].replace('{past_day}', str((date.today() - timedelta(days=config['date_days_back_to_search'], hours=config['date_hours_back_to_search'], minutes=config['date_minutes_back_to_search'])).strftime(config['date_format'])))
config[value] = config[value].replace('{current_day}', str(date.today().strftime(config['date_format'])))
config[value] = config[value].replace('{website}', config['web_domain'] + config['web_path'])
config[value] = config[value].replace('{path_sep}', os.path.sep)

if (config['plex_data_folder'] and config['plex_data_folder'].rfind(os.path.sep) < len(config['plex_data_folder']) - len(os.path.sep)):
if (config['plex_data_folder'].rfind(os.path.sep) < len(config['plex_data_folder']) - len(os.path.sep)):
config['plex_data_folder'] = config['plex_data_folder'] + os.path.sep

if (config['web_folder'] and config['web_folder'].rfind(os.path.sep) < len(config['web_folder']) - len(os.path.sep)):
if (config['plex_data_folder'].find('Plex Media Server') >= 0):
config['plex_data_folder'] = config['plex_data_folder'][0:config['plex_data_folder'].find('Plex Media Server')]

if (config['web_folder'].rfind(os.path.sep) < len(config['web_folder']) - len(os.path.sep)):
config['web_folder'] = config['web_folder'] + os.path.sep

def deleteImages():
Expand Down Expand Up @@ -304,13 +319,13 @@ def createEmailHTML():
<!-- Page Content -->
<div class="container">"""

if (movieCount > 0):
if (movieCount > 0 and config['filter_show_movies']):
emailText += emailMovies + '<br/>&nbsp;'
if (showCount > 0):
if (showCount > 0 and config['filter_show_shows']):
emailText += emailTVShows + '<br/>&nbsp;'
if (seasonCount > 0):
if (seasonCount > 0 and config['filter_show_seasons']):
emailText += emailTVSeasons + '<br/>&nbsp;'
if (episodeCount > 0):
if (episodeCount > 0 and config['filter_show_episodes']):
emailText += emailTVEpisodes

if(not hasNewContent):
Expand Down Expand Up @@ -396,22 +411,22 @@ def createWebHTML():
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">"""
if (movieCount > 0):
if (movieCount > 0 and config['filter_show_movies']):
htmlText += """
<li>
<a href="#movies-top">""" + config['msg_movies_link'] + """</a>
</li>"""
if (showCount > 0):
if (showCount > 0 and config['filter_show_shows']):
htmlText += """
<li>
<a href="#shows-top">""" + config['msg_shows_link'] + """</a>
</li>"""
if (seasonCount > 0):
if (seasonCount > 0 and config['filter_show_seasons']):
htmlText += """
<li>
<a href="#seasons-top">""" + config['msg_seasons_link'] + """</a>
</li>"""
if (episodeCount > 0):
if (episodeCount > 0 and config['filter_show_episodes']):
htmlText += """
<li>
<a href="#episodes-top">""" + config['msg_episodes_link'] + """</a>
Expand All @@ -437,13 +452,13 @@ def createWebHTML():
<!-- Page Content -->
<div class="container">"""

if (movieCount > 0):
if (movieCount > 0 and config['filter_show_movies']):
htmlText += htmlMovies + '<br/>&nbsp;'
if (showCount > 0):
if (showCount > 0 and config['filter_show_shows']):
htmlText += htmlTVShows + '<br/>&nbsp;'
if (seasonCount > 0):
if (seasonCount > 0 and config['filter_show_seasons']):
htmlText += htmlTVSeasons + '<br/>&nbsp;'
if (episodeCount > 0):
if (episodeCount > 0 and config['filter_show_episodes']):
htmlText += htmlTVEpisodes

if(not hasNewContent):
Expand Down Expand Up @@ -506,15 +521,21 @@ def createWebHTML():

DATABASE_FILE = config['plex_data_folder'] + 'Plex Media Server' + os.path.sep + 'Plug-in Support' + os.path.sep + 'Databases' + os.path.sep + 'com.plexapp.plugins.library.db'

if (not os.path.isfile(DATABASE_FILE)):
print DATABASE_FILE + ' does not exist. Please make sure the plex_data_folder value is correct.'
sys.exit()

con = sqlite3.connect(DATABASE_FILE)
con.text_factory = str

with con:

if ('date_use_hours' in config and config['date_use_hours']):
dateSearch = 'datetime(\'now\', \'localtime\', \'-' + str(config['date_hours_back_to_search']) + ' hours\')'
else:
dateSearch = 'datetime(\'now\', \'localtime\', \'-' + str(config['date_days_back_to_search']) + ' days\')'
#if ('date_use_hours' in config and config['date_use_hours']):
#dateSearch = 'datetime(\'now\', \'localtime\', \'-' + str(config['date_hours_back_to_search']) + ' hours\')'
#else:
#dateSearch = 'datetime(\'now\', \'localtime\', \'-' + str(config['date_days_back_to_search']) + ' days\')'

dateSearch = 'datetime(\'now\', \'localtime\', \'-' + str(config['date_days_back_to_search']) + ' days\', \'-' + str(config['date_hours_back_to_search']) + ' hours\', \'-' + str(config['date_minutes_back_to_search']) + ' minutes\')'

cur = con.cursor()
cur.execute("SELECT id, parent_id, metadata_type, title, title_sort, original_title, rating, tagline, summary, content_rating, duration, user_thumb_url, tags_genre, tags_director, tags_star, year, hash, [index], studio FROM metadata_items WHERE added_at >= " + dateSearch + " AND metadata_type >= 1 AND metadata_type <= 4 ORDER BY title_sort;")
Expand Down Expand Up @@ -803,7 +824,7 @@ def createWebHTML():
htmlTVEpisodes += '<p class="lead">Network: ' + tvEpisodes[episode]['studio'].decode('utf-8') + '</p>'
htmlTVEpisodes += '</div></div><br/>&nbsp;<br/>&nbsp;'

if (movieCount > 0 or showCount > 0 or seasonCount > 0 or episodeCount > 0):
if ((movieCount > 0 and config['filter_show_movies']) or (showCount > 0 and config['filter_show_shows']) or (seasonCount > 0 and config['filter_show_seasons']) or (episodeCount > 0 and config['filter_show_episodes'])):
hasNewContent = True
else:
hasNewContent = False
Expand Down

0 comments on commit 323f006

Please sign in to comment.