Option to send recently added notification for new versions

This commit is contained in:
JonnyWong16 2016-11-05 00:02:25 -07:00
parent cc45ad0b63
commit 38d2345cd2
4 changed files with 84 additions and 22 deletions

View file

@ -959,7 +959,7 @@
<label> <label>
<input type="checkbox" name="notify_consecutive" id="notify_consecutive" value="1" ${config['notify_consecutive']}> Allow Consecutive Notifications <input type="checkbox" name="notify_consecutive" id="notify_consecutive" value="1" ${config['notify_consecutive']}> Allow Consecutive Notifications
</label> </label>
<p class="help-block">Disable to prevent consecutive notifications (i.e. both watched &amp; stopped notifications).</p> <p class="help-block">Enable to allow sending of consecutive notifications (i.e. both watched &amp; stopped notifications).</p>
</div> </div>
<div class="checkbox"> <div class="checkbox">
<label> <label>
@ -984,7 +984,7 @@
<div class="checkbox"> <div class="checkbox">
<label> <label>
<input type="checkbox" name="notify_group_recently_added_parent" id="notify_group_recently_added_parent" value="1" ${config['notify_group_recently_added_parent']}> Group Notifications into Season or Album <input type="checkbox" name="notify_group_recently_added_parent" id="notify_group_recently_added_parent" value="1" ${config['notify_group_recently_added_parent']}> Group Notifications by Season or Album
</label> </label>
<p class="help-block"> <p class="help-block">
Enable to only send one season or album notification when multiple episodes or tracks are added. Movies, single episodes, and single tracks are unaffected.<br /> Enable to only send one season or album notification when multiple episodes or tracks are added. Movies, single episodes, and single tracks are unaffected.<br />
@ -993,13 +993,22 @@
</div> </div>
<div class="checkbox"> <div class="checkbox">
<label> <label>
<input type="checkbox" name="notify_group_recently_added_grandparent" id="notify_group_recently_added_grandparent" value="1" ${config['notify_group_recently_added_grandparent']}> Group Notifications into TV Show or Artist <input type="checkbox" name="notify_group_recently_added_grandparent" id="notify_group_recently_added_grandparent" value="1" ${config['notify_group_recently_added_grandparent']}> Group Notifications by TV Show or Artist
</label> </label>
<p class="help-block"> <p class="help-block">
Enable to only send one TV show or artist notification when multiple seasons or albums are added. Movies, single episodes, and single tracks are unaffected.<br /> Enable to only send one TV show or artist notification when multiple seasons or albums are added. Movies, single episodes, and single tracks are unaffected.<br />
Note: A season range can be shown (e.g. 1-3), but all other season/episode/album/track metadata will be unavailable. Note: A season range can be shown (e.g. 1-3), but all other season/episode/album/track metadata will be unavailable.
</p> </p>
</div> </div>
<div class="checkbox">
<label>
<input type="checkbox" name="notify_recently_added_upgrade" id="notify_recently_added_upgrade" value="1" ${config['notify_recently_added_upgrade']}> Send a Notification for New Versions
</label>
<p class="help-block">
Enable to send another recently added notification when adding a new version of existing media.<br />
Note: If multiple versions are available, PlexPy will assume the higher quality one is newer.
</p>
</div>
<p><input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully"></p> <p><input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully"></p>
</div> </div>

View file

@ -282,8 +282,6 @@ class TimelineHandler(object):
rating_key = self.get_rating_key() rating_key = self.get_rating_key()
state_types = {0: 'created',
5: 'processed'}
media_types = {1: 'movie', media_types = {1: 'movie',
2: 'show', 2: 'show',
3: 'season', 3: 'season',
@ -292,13 +290,20 @@ class TimelineHandler(object):
9: 'album', 9: 'album',
10: 'track'} 10: 'track'}
state_type = state_types.get(self.timeline['state']) state_type = self.timeline.get('state')
media_type = media_types.get(self.timeline['type']) media_type = media_types.get(self.timeline.get('type'))
section_id = self.timeline['sectionID'] section_id = self.timeline.get('sectionID', 0)
title = self.timeline.get('title', 'Unknown')
metadata_state = self.timeline.get('metadataState') metadata_state = self.timeline.get('metadataState')
media_state = self.timeline.get('mediaState')
queue_size = self.timeline.get('queueSize')
# Add a new media item to the recently added queue
if media_type and section_id > 0 and \
((state_type == 0 and metadata_state == 'created') or \
(plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_UPGRADE and state_type in (1, 5) and \
media_state == 'analyzing' and queue_size is None)):
if state_type == 'created' and media_type and section_id > 0 and metadata_state == 'created':
if media_type in ('episode', 'track'): if media_type in ('episode', 'track'):
metadata = self.get_metadata() metadata = self.get_metadata()
if metadata: if metadata:
@ -313,8 +318,10 @@ class TimelineHandler(object):
parent_set.add(rating_key) parent_set.add(rating_key)
RECENTLY_ADDED_QUEUE[parent_rating_key] = parent_set RECENTLY_ADDED_QUEUE[parent_rating_key] = parent_set
logger.debug(u"PlexPy TimelineHandler :: Library item %s (grandparent %s) added to recently added queue." RECENTLY_ADDED_QUEUE[rating_key] = set([grandparent_rating_key])
% (str(rating_key), str(grandparent_rating_key)))
logger.debug(u"PlexPy TimelineHandler :: Library item '%s' (%s, grandparent %s) added to recently added queue."
% (title, str(rating_key), str(grandparent_rating_key)))
elif media_type in ('season', 'album'): elif media_type in ('season', 'album'):
metadata = self.get_metadata() metadata = self.get_metadata()
@ -325,30 +332,74 @@ class TimelineHandler(object):
parent_set.add(rating_key) parent_set.add(rating_key)
RECENTLY_ADDED_QUEUE[parent_rating_key] = parent_set RECENTLY_ADDED_QUEUE[parent_rating_key] = parent_set
logger.debug(u"PlexPy TimelineHandler :: Library item %s (parent %s) added to recently added queue." logger.debug(u"PlexPy TimelineHandler :: Library item '%s' (%s , parent %s) added to recently added queue."
% (str(rating_key), str(parent_rating_key))) % (title, str(rating_key), str(parent_rating_key)))
else: else:
queue_set = RECENTLY_ADDED_QUEUE.get(rating_key, set()) queue_set = RECENTLY_ADDED_QUEUE.get(rating_key, set())
RECENTLY_ADDED_QUEUE[rating_key] = queue_set RECENTLY_ADDED_QUEUE[rating_key] = queue_set
logger.debug(u"PlexPy TimelineHandler :: Library item %s added to recently added queue." % str(rating_key)) logger.debug(u"PlexPy TimelineHandler :: Library item '%s' (%s) added to recently added queue."
% (title, str(rating_key)))
if state_type == 'processed' and media_type in ('movie', 'show', 'artist') and section_id > 0 and metadata_state is None: # A movie, show, or artist is done processing
logger.debug(u"PlexPy TimelineHandler :: Library item %s done processing metadata." % str(rating_key)) elif media_type in ('movie', 'show', 'artist') and section_id > 0 and \
state_type == 5 and metadata_state is None and queue_size is None and \
rating_key in RECENTLY_ADDED_QUEUE:
child_keys = RECENTLY_ADDED_QUEUE.pop(rating_key, []) logger.debug(u"PlexPy TimelineHandler :: Library item '%s' (%s) done processing metadata."
% (title, str(rating_key)))
child_keys = RECENTLY_ADDED_QUEUE[rating_key]
if plexpy.CONFIG.NOTIFY_GROUP_RECENTLY_ADDED_GRANDPARENT and len(child_keys) > 1: if plexpy.CONFIG.NOTIFY_GROUP_RECENTLY_ADDED_GRANDPARENT and len(child_keys) > 1:
self.on_created(rating_key, child_keys=child_keys) self.on_created(rating_key, child_keys=child_keys)
else: elif child_keys:
for child_key in child_keys: for child_key in child_keys:
grandchild_keys = RECENTLY_ADDED_QUEUE.pop(child_key, []) grandchild_keys = RECENTLY_ADDED_QUEUE.get(child_key, [])
if plexpy.CONFIG.NOTIFY_GROUP_RECENTLY_ADDED_PARENT and len(grandchild_keys) > 1: if plexpy.CONFIG.NOTIFY_GROUP_RECENTLY_ADDED_PARENT and len(grandchild_keys) > 1:
self.on_created(child_key, child_keys=grandchild_keys) self.on_created(child_key, child_keys=grandchild_keys)
else: elif grandchild_keys:
for grandchild_key in grandchild_keys: for grandchild_key in grandchild_keys:
self.on_created(grandchild_key) self.on_created(grandchild_key)
else:
self.on_created(child_key)
else:
self.on_created(rating_key)
# Remove all keys
self.del_keys(rating_key)
# An episode or track is done processing (upgrade only)
elif plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_UPGRADE and \
media_type in ('episode', 'track') and section_id > 0 and \
state_type == 5 and metadata_state is None and queue_size is None and \
rating_key in RECENTLY_ADDED_QUEUE:
logger.debug(u"PlexPy TimelineHandler :: Library item '%s' (%s) done processing metadata (upgrade)."
% (title, str(rating_key)))
grandparent_rating_key = RECENTLY_ADDED_QUEUE[rating_key]
self.on_created(rating_key)
# Remove all keys
self.del_keys(grandparent_rating_key)
# An item was deleted, make sure it is removed from the queue
elif state_type == 9 and metadata_state == 'deleted':
logger.debug(u"PlexPy TimelineHandler :: Library item %s removed from recently added queue."
% str(rating_key))
self.del_keys(rating_key)
def del_keys(self, key):
if isinstance(key, set):
for child_key in key:
self.del_keys(child_key)
elif key in RECENTLY_ADDED_QUEUE:
self.del_keys(RECENTLY_ADDED_QUEUE.pop(key))

View file

@ -319,8 +319,9 @@ _CONFIG_DEFINITIONS = {
'NOTIFY_GROUP_RECENTLY_ADDED': (int, 'Monitoring', 0), 'NOTIFY_GROUP_RECENTLY_ADDED': (int, 'Monitoring', 0),
'NOTIFY_UPLOAD_POSTERS': (int, 'Monitoring', 0), 'NOTIFY_UPLOAD_POSTERS': (int, 'Monitoring', 0),
'NOTIFY_RECENTLY_ADDED': (int, 'Monitoring', 0), 'NOTIFY_RECENTLY_ADDED': (int, 'Monitoring', 0),
'NOTIFY_RECENTLY_ADDED_GRANDPARENT': (int, 'Monitoring', 0),
'NOTIFY_RECENTLY_ADDED_DELAY': (int, 'Monitoring', 60), 'NOTIFY_RECENTLY_ADDED_DELAY': (int, 'Monitoring', 60),
'NOTIFY_RECENTLY_ADDED_GRANDPARENT': (int, 'Monitoring', 0),
'NOTIFY_RECENTLY_ADDED_UPGRADE': (int, 'Monitoring', 0),
'NOTIFY_CONCURRENT_BY_IP': (int, 'Monitoring', 0), 'NOTIFY_CONCURRENT_BY_IP': (int, 'Monitoring', 0),
'NOTIFY_CONCURRENT_THRESHOLD': (int, 'Monitoring', 2), 'NOTIFY_CONCURRENT_THRESHOLD': (int, 'Monitoring', 2),
'NOTIFY_WATCHED_PERCENT': (int, 'Monitoring', 85), 'NOTIFY_WATCHED_PERCENT': (int, 'Monitoring', 85),

View file

@ -2570,6 +2570,7 @@ class WebInterface(object):
"notify_consecutive": checked(plexpy.CONFIG.NOTIFY_CONSECUTIVE), "notify_consecutive": checked(plexpy.CONFIG.NOTIFY_CONSECUTIVE),
"notify_upload_posters": checked(plexpy.CONFIG.NOTIFY_UPLOAD_POSTERS), "notify_upload_posters": checked(plexpy.CONFIG.NOTIFY_UPLOAD_POSTERS),
"notify_recently_added": checked(plexpy.CONFIG.NOTIFY_RECENTLY_ADDED), "notify_recently_added": checked(plexpy.CONFIG.NOTIFY_RECENTLY_ADDED),
"notify_recently_added_upgrade": checked(plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_UPGRADE),
"notify_group_recently_added_grandparent": checked(plexpy.CONFIG.NOTIFY_GROUP_RECENTLY_ADDED_GRANDPARENT), "notify_group_recently_added_grandparent": checked(plexpy.CONFIG.NOTIFY_GROUP_RECENTLY_ADDED_GRANDPARENT),
"notify_group_recently_added_parent": checked(plexpy.CONFIG.NOTIFY_GROUP_RECENTLY_ADDED_PARENT), "notify_group_recently_added_parent": checked(plexpy.CONFIG.NOTIFY_GROUP_RECENTLY_ADDED_PARENT),
"notify_concurrent_by_ip": checked(plexpy.CONFIG.NOTIFY_CONCURRENT_BY_IP), "notify_concurrent_by_ip": checked(plexpy.CONFIG.NOTIFY_CONCURRENT_BY_IP),
@ -2609,7 +2610,7 @@ class WebInterface(object):
"movie_notify_enable", "tv_notify_enable", "music_notify_enable", "movie_notify_enable", "tv_notify_enable", "music_notify_enable",
"refresh_libraries_on_startup", "refresh_users_on_startup", "refresh_libraries_on_startup", "refresh_users_on_startup",
"movie_logging_enable", "tv_logging_enable", "music_logging_enable", "movie_logging_enable", "tv_logging_enable", "music_logging_enable",
"notify_consecutive", "notify_upload_posters", "notify_recently_added", "notify_consecutive", "notify_upload_posters", "notify_recently_added", "notify_recently_added_upgrade",
"notify_group_recently_added_grandparent", "notify_group_recently_added_parent", "notify_group_recently_added_grandparent", "notify_group_recently_added_parent",
"monitor_pms_updates", "monitor_remote_access", "get_file_sizes", "log_blacklist", "http_hash_password", "monitor_pms_updates", "monitor_remote_access", "get_file_sizes", "log_blacklist", "http_hash_password",
"allow_guest_access", "cache_images", "http_basic_auth", "notify_concurrent_by_ip", "allow_guest_access", "cache_images", "http_basic_auth", "notify_concurrent_by_ip",