diff --git a/data/interfaces/default/settings.html b/data/interfaces/default/settings.html index 40e7c057..dfabad89 100644 --- a/data/interfaces/default/settings.html +++ b/data/interfaces/default/settings.html @@ -959,7 +959,7 @@ -

Disable to prevent consecutive notifications (i.e. both watched & stopped notifications).

+

Enable to allow sending of consecutive notifications (i.e. both watched & stopped notifications).

diff --git a/plexpy/activity_handler.py b/plexpy/activity_handler.py index 128ceacb..86fe4924 100644 --- a/plexpy/activity_handler.py +++ b/plexpy/activity_handler.py @@ -282,8 +282,6 @@ class TimelineHandler(object): rating_key = self.get_rating_key() - state_types = {0: 'created', - 5: 'processed'} media_types = {1: 'movie', 2: 'show', 3: 'season', @@ -292,13 +290,20 @@ class TimelineHandler(object): 9: 'album', 10: 'track'} - state_type = state_types.get(self.timeline['state']) - media_type = media_types.get(self.timeline['type']) - section_id = self.timeline['sectionID'] + state_type = self.timeline.get('state') + media_type = media_types.get(self.timeline.get('type')) + section_id = self.timeline.get('sectionID', 0) + title = self.timeline.get('title', 'Unknown') 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'): metadata = self.get_metadata() if metadata: @@ -313,8 +318,10 @@ class TimelineHandler(object): parent_set.add(rating_key) RECENTLY_ADDED_QUEUE[parent_rating_key] = parent_set - logger.debug(u"PlexPy TimelineHandler :: Library item %s (grandparent %s) added to recently added queue." - % (str(rating_key), str(grandparent_rating_key))) + RECENTLY_ADDED_QUEUE[rating_key] = set([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'): metadata = self.get_metadata() @@ -325,30 +332,74 @@ class TimelineHandler(object): parent_set.add(rating_key) RECENTLY_ADDED_QUEUE[parent_rating_key] = parent_set - logger.debug(u"PlexPy TimelineHandler :: Library item %s (parent %s) added to recently added queue." - % (str(rating_key), str(parent_rating_key))) + logger.debug(u"PlexPy TimelineHandler :: Library item '%s' (%s , parent %s) added to recently added queue." + % (title, str(rating_key), str(parent_rating_key))) else: queue_set = RECENTLY_ADDED_QUEUE.get(rating_key, 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: - logger.debug(u"PlexPy TimelineHandler :: Library item %s done processing metadata." % str(rating_key)) + # A movie, show, or artist is done processing + 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: + + logger.debug(u"PlexPy TimelineHandler :: Library item '%s' (%s) done processing metadata." + % (title, str(rating_key))) - child_keys = RECENTLY_ADDED_QUEUE.pop(rating_key, []) + child_keys = RECENTLY_ADDED_QUEUE[rating_key] if plexpy.CONFIG.NOTIFY_GROUP_RECENTLY_ADDED_GRANDPARENT and len(child_keys) > 1: self.on_created(rating_key, child_keys=child_keys) - else: + elif 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: self.on_created(child_key, child_keys=grandchild_keys) - else: + elif grandchild_keys: for grandchild_key in grandchild_keys: 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)) diff --git a/plexpy/config.py b/plexpy/config.py index 51e1bd1e..281163dc 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -319,8 +319,9 @@ _CONFIG_DEFINITIONS = { 'NOTIFY_GROUP_RECENTLY_ADDED': (int, 'Monitoring', 0), 'NOTIFY_UPLOAD_POSTERS': (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_GRANDPARENT': (int, 'Monitoring', 0), + 'NOTIFY_RECENTLY_ADDED_UPGRADE': (int, 'Monitoring', 0), 'NOTIFY_CONCURRENT_BY_IP': (int, 'Monitoring', 0), 'NOTIFY_CONCURRENT_THRESHOLD': (int, 'Monitoring', 2), 'NOTIFY_WATCHED_PERCENT': (int, 'Monitoring', 85), diff --git a/plexpy/webserve.py b/plexpy/webserve.py index fa44bd91..1f104639 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -2570,6 +2570,7 @@ class WebInterface(object): "notify_consecutive": checked(plexpy.CONFIG.NOTIFY_CONSECUTIVE), "notify_upload_posters": checked(plexpy.CONFIG.NOTIFY_UPLOAD_POSTERS), "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_parent": checked(plexpy.CONFIG.NOTIFY_GROUP_RECENTLY_ADDED_PARENT), "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", "refresh_libraries_on_startup", "refresh_users_on_startup", "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", "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",