From 9be3bbbf0f85eb33a7b6d09d17af52355cbcdadb Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Thu, 16 Feb 2023 16:20:25 -0800 Subject: [PATCH] Update marker notification parameters --- plexpy/common.py | 10 ++++------ plexpy/notification_handler.py | 24 +++++------------------- plexpy/pmsconnect.py | 10 +++++++++- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/plexpy/common.py b/plexpy/common.py index 65de4810..cf1180dc 100644 --- a/plexpy/common.py +++ b/plexpy/common.py @@ -427,12 +427,10 @@ NOTIFICATION_PARAMETERS = [ {'name': 'Optimized Version Profile', 'type': 'str', 'value': 'optimized_version_profile', 'description': 'The optimized version profile of the stream.'}, {'name': 'Synced Version', 'type': 'int', 'value': 'synced_version', 'description': 'If the stream is an synced version.', 'example': '0 or 1'}, {'name': 'Live', 'type': 'int', 'value': 'live', 'description': 'If the stream is live TV.', 'example': '0 or 1'}, - {'name': 'Intro Marker Start Time', 'type': 'int', 'value': 'intro_marker_start', 'description': 'The intro marker start time offset in milliseconds.'}, - {'name': 'Intro Marker End Time', 'type': 'int', 'value': 'intro_marker_end', 'description': 'The intro marker end time offset in milliseconds.'}, - {'name': 'Credits Marker First', 'type': 'int', 'value': 'credits_marker_first', 'description': 'If the credits marker is the first marker.', 'example': '0 or 1'}, - {'name': 'Credits Marker Final', 'type': 'int', 'value': 'credits_marker_final', 'description': 'If the credits marker is the final marker.', 'example': '0 or 1'}, - {'name': 'Credits Marker Start Time', 'type': 'int', 'value': 'credits_marker_start', 'description': 'The credits marker start time offset in milliseconds.'}, - {'name': 'Credits Marker End Time', 'type': 'int', 'value': 'credits_marker_end', 'description': 'The credits marker end time offset in milliseconds.'}, + {'name': 'Marker Start Time', 'type': 'int', 'value': 'marker_start', 'description': 'The intro or credits marker start time offset in milliseconds.'}, + {'name': 'Marker End Time', 'type': 'int', 'value': 'marker_end', 'description': 'The intro or credits marker end time offset in milliseconds.'}, + {'name': 'Credits Marker First', 'type': 'int', 'value': 'credits_marker_first', 'description': 'If the marker is the first credits marker.', 'example': '0 or 1'}, + {'name': 'Credits Marker Final', 'type': 'int', 'value': 'credits_marker_final', 'description': 'If the marker is the final credits marker.', 'example': '0 or 1'}, {'name': 'Channel Call Sign', 'type': 'str', 'value': 'channel_call_sign', 'description': 'The Live TV channel call sign.'}, {'name': 'Channel Identifier', 'type': 'str', 'value': 'channel_identifier', 'description': 'The Live TV channel number.'}, {'name': 'Channel Thumb', 'type': 'str', 'value': 'channel_thumb', 'description': 'The URL for the Live TV channel logo.'}, diff --git a/plexpy/notification_handler.py b/plexpy/notification_handler.py index b9940b70..c92415e5 100644 --- a/plexpy/notification_handler.py +++ b/plexpy/notification_handler.py @@ -940,19 +940,7 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, m and audience_rating: audience_rating = helpers.get_percent(notify_params['audience_rating'], 10) - intro_markers, credits_markers = [], [] - for marker in metadata['markers']: - if marker['type'] == 'intro': - intro_markers.append(marker) - elif marker['type'] == 'credits': - credits_markers.append(marker) - - intro_marker = defaultdict(int) - credits_marker = defaultdict(int) - if notify_action == 'on_intro' and intro_markers and notify_params['intro'] < len(intro_markers): - intro_marker = intro_markers[notify_params['intro']] - if notify_action == 'on_credits' and credits_markers and notify_params['credits'] < len(credits_markers): - credits_marker = credits_markers[notify_params['credits']] + marker = kwargs.pop('marker', defaultdict(int)) now = arrow.now() now_iso = now.isocalendar() @@ -1033,12 +1021,10 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, m 'optimized_version_profile': notify_params['optimized_version_profile'], 'synced_version': notify_params['synced_version'], 'live': notify_params['live'], - 'intro_marker_start': intro_marker['start_time_offset'], - 'intro_marker_end': intro_marker['end_time_offset'], - 'credits_marker_first': int(bool(credits_marker and notify_params['credits'] == 0)), - 'credits_marker_final': int(credits_marker['final']), - 'credits_marker_start': credits_marker['start_time_offset'], - 'credits_marker_end': credits_marker['end_time_offset'], + 'marker_start': marker['start_time_offset'], + 'marker_end': marker['end_time_offset'], + 'credits_marker_first': int(marker['first']), + 'credits_marker_final': int(marker['final']), 'channel_call_sign': notify_params['channel_call_sign'], 'channel_identifier': notify_params['channel_identifier'], 'channel_thumb': notify_params['channel_thumb'], diff --git a/plexpy/pmsconnect.py b/plexpy/pmsconnect.py index 3a7a2450..cc433027 100644 --- a/plexpy/pmsconnect.py +++ b/plexpy/pmsconnect.py @@ -776,12 +776,20 @@ class PmsConnect(object): guids.append(helpers.get_xml_attr(guid, 'id')) if metadata_main.getElementsByTagName('Marker'): + first = None for marker in metadata_main.getElementsByTagName('Marker'): + marker_type = helpers.get_xml_attr(marker, 'type') + if marker_type == 'credits': + if first is None: + first = True + elif first is True: + first = False markers.append({ - 'id': helpers.get_xml_attr(marker, 'id'), + 'id': helpers.cast_to_int(helpers.get_xml_attr(marker, 'id')), 'type': helpers.get_xml_attr(marker, 'type'), 'start_time_offset': helpers.cast_to_int(helpers.get_xml_attr(marker, 'startTimeOffset')), 'end_time_offset': helpers.cast_to_int(helpers.get_xml_attr(marker, 'endTimeOffset')), + 'first': first if marker_type == 'credits' else False, 'final': helpers.bool_true(helpers.get_xml_attr(marker, 'final')) })