diff --git a/plexpy/activity_pinger.py b/plexpy/activity_pinger.py index e1be68c1..c2bcd006 100644 --- a/plexpy/activity_pinger.py +++ b/plexpy/activity_pinger.py @@ -326,7 +326,7 @@ def check_server_updates(): if download_info['update_available']: logger.info(u"PlexPy Monitor :: PMS update available version: %s", download_info['version']) - plexpy.NOTIFY_QUEUE.put({'notify_action': 'on_pmsupdate'}) + plexpy.NOTIFY_QUEUE.put({'notify_action': 'on_pmsupdate', 'pms_download_info': download_info}) else: logger.info(u"PlexPy Monitor :: No PMS update available.") \ No newline at end of file diff --git a/plexpy/notification_handler.py b/plexpy/notification_handler.py index 3a1a6b82..dc482534 100644 --- a/plexpy/notification_handler.py +++ b/plexpy/notification_handler.py @@ -149,7 +149,8 @@ def notify(notifier_id=None, notify_action=None, stream_data=None, timeline_data **kwargs) else: # Build the notification parameters - parameters, metadata = build_server_notify_params(notify_action=notify_action) + parameters, metadata = build_server_notify_params(notify_action=notify_action, + **kwargs) if not parameters: logger.error(u"PlexPy NotificationHandler :: Failed to build notification parameters.") @@ -266,12 +267,10 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, * return None, None child_metadata = grandchild_metadata = [] - if 'child_keys' in kwargs: - for key in kwargs['child_keys']: - child_metadata.append(pms_connect.get_metadata_details(rating_key=key)['metadata']) - if 'grandchild_keys' in kwargs: - for key in kwargs['grandchild_keys']: - grandchild_metadata.append(pms_connect.get_metadata_details(rating_key=key)['metadata']) + for key in kwargs.pop('child_keys', []): + child_metadata.append(pms_connect.get_metadata_details(rating_key=key)['metadata']) + for key in kwargs.pop('grandchild_keys', []): + grandchild_metadata.append(pms_connect.get_metadata_details(rating_key=key)['metadata']) current_activity = pms_connect.get_current_activity() sessions = current_activity.get('sessions', []) @@ -427,7 +426,7 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, * season_num = metadata['media_index'].zfill(1) season_num00 = metadata['media_index'].zfill(2) - num, num00 = format_group_keys([helpers.cast_to_int(d['media_index']) + num, num00 = format_group_index([helpers.cast_to_int(d['media_index']) for d in child_metadata if d['parent_rating_key'] == rating_key]) episode_num, episode_num00 = num, num00 track_num, track_num00 = num, num00 @@ -439,11 +438,11 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, * album_name = '' track_name = '' - num, num00 = format_group_keys([helpers.cast_to_int(d['media_index']) + num, num00 = format_group_index([helpers.cast_to_int(d['media_index']) for d in child_metadata if d['parent_rating_key'] == rating_key]) season_num, season_num00 = num, num00 - num, num00 = format_group_keys([helpers.cast_to_int(d['media_index']) + num, num00 = format_group_index([helpers.cast_to_int(d['media_index']) for d in grandchild_metadata if d['grandparent_rating_key'] == rating_key]) episode_num, episode_num00 = num, num00 track_num, track_num00 = num, num00 @@ -551,7 +550,7 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, * return available_params, metadata -def build_server_notify_params(notify_action=None): +def build_server_notify_params(notify_action=None, **kwargs): # Get time formats date_format = plexpy.CONFIG.DATE_FORMAT.replace('Do','') time_format = plexpy.CONFIG.TIME_FORMAT.replace('Do','') @@ -563,9 +562,7 @@ def build_server_notify_params(notify_action=None): plex_tv = plextv.PlexTV() server_times = plex_tv.get_server_times() - update_status = {} - if notify_action == 'pmsupdate': - update_status = plex_tv.get_plex_downloads() + pms_download_info = kwargs.pop('pms_download_info', {}) if server_times: updated_at = server_times['updated_at'] @@ -581,19 +578,20 @@ def build_server_notify_params(notify_action=None): 'action': notify_action.split('on_')[-1].title(), 'datestamp': arrow.now().format(date_format), 'timestamp': arrow.now().format(time_format), - # Update parameters - 'update_version': update_status.get('version',''), - 'update_url': update_status.get('download_url',''), - 'update_release_date': arrow.get(update_status.get('release_date','')).format(date_format) - if update_status.get('release_date','') else '', + # Plex Media Server update parameters + 'update_version': pms_download_info.get('version',''), + 'update_url': pms_download_info.get('download_url',''), + 'update_release_date': arrow.get(pms_download_info.get('release_date','')).format(date_format) + if pms_download_info.get('release_date','') else '', 'update_channel': 'Plex Pass' if plexpy.CONFIG.PMS_UPDATE_CHANNEL == 'plexpass' else 'Public', - 'update_platform': update_status.get('platform',''), - 'update_distro': update_status.get('distro',''), - 'update_distro_build': update_status.get('build',''), - 'update_requirements': update_status.get('requirements',''), - 'update_extra_info': update_status.get('extra_info',''), - 'update_changelog_added': update_status.get('changelog_added',''), - 'update_changelog_fixed': update_status.get('changelog_fixed','')} + 'update_platform': pms_download_info.get('platform',''), + 'update_distro': pms_download_info.get('distro',''), + 'update_distro_build': pms_download_info.get('build',''), + 'update_requirements': pms_download_info.get('requirements',''), + 'update_extra_info': pms_download_info.get('extra_info',''), + 'update_changelog_added': pms_download_info.get('changelog_added',''), + 'update_changelog_fixed': pms_download_info.get('changelog_fixed',''), + } return available_params, None @@ -685,7 +683,8 @@ def strip_tag(data, agent_id=None): whitelist = {} return bleach.clean(data, tags=whitelist.keys(), attributes=whitelist, strip=True) -def format_group_keys(group_keys): + +def format_group_index(group_keys): num = [] num00 = [] diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py index 26c208ed..1dd10099 100644 --- a/plexpy/notifiers.py +++ b/plexpy/notifiers.py @@ -2024,97 +2024,6 @@ class SCRIPTS(Notifier): 'name': 'scripts_timeout', 'description': 'The number of seconds to wait before killing the script. 0 to disable timeout.', 'input_type': 'number' - # }, - #{'label': 'Playback Stop', - # 'value': self.scripts['stop'], - # 'name': 'scripts_on_stop_script', - # 'description': 'Choose the script for on stop.', - # 'input_type': 'select', - # 'select_options': self.list_scripts() - # }, - #{'label': 'Playback Pause', - # 'value': self.scripts['pause'], - # 'name': 'scripts_on_pause_script', - # 'description': 'Choose the script for on pause.', - # 'input_type': 'select', - # 'select_options': self.list_scripts() - # }, - #{'label': 'Playback Resume', - # 'value': self.scripts['resume'], - # 'name': 'scripts_on_resume_script', - # 'description': 'Choose the script for on resume.', - # 'input_type': 'select', - # 'select_options': self.list_scripts() - # }, - #{'label': 'Watched', - # 'value': self.scripts['watched'], - # 'name': 'scripts_on_watched_script', - # 'description': 'Choose the script for on watched.', - # 'input_type': 'select', - # 'select_options': self.list_scripts() - # }, - #{'label': 'Buffer Warnings', - # 'value': self.scripts['buffer'], - # 'name': 'scripts_on_buffer_script', - # 'description': 'Choose the script for buffer warnings.', - # 'input_type': 'select', - # 'select_options': self.list_scripts() - # }, - #{'label': 'Recently Added', - # 'value': self.scripts['created'], - # 'name': 'scripts_on_created_script', - # 'description': 'Choose the script for recently added.', - # 'input_type': 'select', - # 'select_options': self.list_scripts() - # }, - #{'label': 'Plex Server Down', - # 'value': self.scripts['intdown'], - # 'name': 'scripts_on_intdown_script', - # 'description': 'Choose the script for Plex server down.', - # 'input_type': 'select', - # 'select_options': self.list_scripts() - # }, - #{'label': 'Plex Server Back Up', - # 'value': self.scripts['intup'], - # 'name': 'scripts_on_intup_script', - # 'description': 'Choose the script for Plex server back up.', - # 'input_type': 'select', - # 'select_options': self.list_scripts() - # }, - #{'label': 'Plex Remote Access Down', - # 'value': self.scripts['extdown'], - # 'name': 'scripts_on_extdown_script', - # 'description': 'Choose the script for Plex remote access down.', - # 'input_type': 'select', - # 'select_options': self.list_scripts() - # }, - #{'label': 'Plex Remote Access Back Up', - # 'value': self.scripts['extup'], - # 'name': 'scripts_on_extup_script', - # 'description': 'Choose the script for Plex remote access back up.', - # 'input_type': 'select', - # 'select_options': self.list_scripts() - # }, - #{'label': 'Plex Update Available', - # 'value': self.scripts['pmsupdate'], - # 'name': 'scripts_on_pmsupdate_script', - # 'description': 'Choose the script for Plex update available.', - # 'input_type': 'select', - # 'select_options': self.list_scripts() - # }, - #{'label': 'User Concurrent Streams', - # 'value': self.scripts['concurrent'], - # 'name': 'scripts_on_concurrent_script', - # 'description': 'Choose the script for user concurrent streams.', - # 'input_type': 'select', - # 'select_options': self.list_scripts() - # }, - #{'label': 'User New Device', - # 'value': self.scripts['newdevice'], - # 'name': 'scripts_on_newdevice_script', - # 'description': 'Choose the script for user new device.', - # 'input_type': 'select', - # 'select_options': self.list_scripts() } ] diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 4d0c7496..0266903f 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -2575,35 +2575,6 @@ class WebInterface(object): "notify_concurrent_by_ip": checked(plexpy.CONFIG.NOTIFY_CONCURRENT_BY_IP), "notify_concurrent_threshold": plexpy.CONFIG.NOTIFY_CONCURRENT_THRESHOLD, "notify_watched_percent": plexpy.CONFIG.NOTIFY_WATCHED_PERCENT, - "notify_on_start_subject_text": plexpy.CONFIG.NOTIFY_ON_START_SUBJECT_TEXT, - "notify_on_start_body_text": plexpy.CONFIG.NOTIFY_ON_START_BODY_TEXT, - "notify_on_stop_subject_text": plexpy.CONFIG.NOTIFY_ON_STOP_SUBJECT_TEXT, - "notify_on_stop_body_text": plexpy.CONFIG.NOTIFY_ON_STOP_BODY_TEXT, - "notify_on_pause_subject_text": plexpy.CONFIG.NOTIFY_ON_PAUSE_SUBJECT_TEXT, - "notify_on_pause_body_text": plexpy.CONFIG.NOTIFY_ON_PAUSE_BODY_TEXT, - "notify_on_resume_subject_text": plexpy.CONFIG.NOTIFY_ON_RESUME_SUBJECT_TEXT, - "notify_on_resume_body_text": plexpy.CONFIG.NOTIFY_ON_RESUME_BODY_TEXT, - "notify_on_buffer_subject_text": plexpy.CONFIG.NOTIFY_ON_BUFFER_SUBJECT_TEXT, - "notify_on_buffer_body_text": plexpy.CONFIG.NOTIFY_ON_BUFFER_BODY_TEXT, - "notify_on_watched_subject_text": plexpy.CONFIG.NOTIFY_ON_WATCHED_SUBJECT_TEXT, - "notify_on_watched_body_text": plexpy.CONFIG.NOTIFY_ON_WATCHED_BODY_TEXT, - "notify_on_created_subject_text": plexpy.CONFIG.NOTIFY_ON_CREATED_SUBJECT_TEXT, - "notify_on_created_body_text": plexpy.CONFIG.NOTIFY_ON_CREATED_BODY_TEXT, - "notify_on_extdown_subject_text": plexpy.CONFIG.NOTIFY_ON_EXTDOWN_SUBJECT_TEXT, - "notify_on_extdown_body_text": plexpy.CONFIG.NOTIFY_ON_EXTDOWN_BODY_TEXT, - "notify_on_intdown_subject_text": plexpy.CONFIG.NOTIFY_ON_INTDOWN_SUBJECT_TEXT, - "notify_on_intdown_body_text": plexpy.CONFIG.NOTIFY_ON_INTDOWN_BODY_TEXT, - "notify_on_extup_subject_text": plexpy.CONFIG.NOTIFY_ON_EXTUP_SUBJECT_TEXT, - "notify_on_extup_body_text": plexpy.CONFIG.NOTIFY_ON_EXTUP_BODY_TEXT, - "notify_on_intup_subject_text": plexpy.CONFIG.NOTIFY_ON_INTUP_SUBJECT_TEXT, - "notify_on_intup_body_text": plexpy.CONFIG.NOTIFY_ON_INTUP_BODY_TEXT, - "notify_on_pmsupdate_subject_text": plexpy.CONFIG.NOTIFY_ON_PMSUPDATE_SUBJECT_TEXT, - "notify_on_pmsupdate_body_text": plexpy.CONFIG.NOTIFY_ON_PMSUPDATE_BODY_TEXT, - "notify_on_concurrent_subject_text": plexpy.CONFIG.NOTIFY_ON_CONCURRENT_SUBJECT_TEXT, - "notify_on_concurrent_body_text": plexpy.CONFIG.NOTIFY_ON_CONCURRENT_BODY_TEXT, - "notify_on_newdevice_subject_text": plexpy.CONFIG.NOTIFY_ON_NEWDEVICE_SUBJECT_TEXT, - "notify_on_newdevice_body_text": plexpy.CONFIG.NOTIFY_ON_NEWDEVICE_BODY_TEXT, - "notify_scripts_args_text": plexpy.CONFIG.NOTIFY_SCRIPTS_ARGS_TEXT, "home_sections": json.dumps(plexpy.CONFIG.HOME_SECTIONS), "home_stats_length": plexpy.CONFIG.HOME_STATS_LENGTH, "home_stats_type": checked(plexpy.CONFIG.HOME_STATS_TYPE),