diff --git a/plexpy/__init__.py b/plexpy/__init__.py index c82f265b..1d8b02af 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -582,8 +582,8 @@ def dbcheck(): 'CREATE TABLE IF NOT EXISTS sessions (id INTEGER PRIMARY KEY AUTOINCREMENT, session_key INTEGER, session_id TEXT, ' 'transcode_key TEXT, rating_key INTEGER, section_id INTEGER, media_type TEXT, started INTEGER, stopped INTEGER, ' 'paused_counter INTEGER DEFAULT 0, state TEXT, user_id INTEGER, user TEXT, friendly_name TEXT, ' - 'ip_address TEXT, machine_id TEXT, player TEXT, product TEXT, platform TEXT, title TEXT, parent_title TEXT, ' - 'grandparent_title TEXT, original_title TEXT, full_title TEXT, ' + 'ip_address TEXT, machine_id TEXT, bandwidth INTEGER, location TEXT, player TEXT, product TEXT, platform TEXT, ' + 'title TEXT, parent_title TEXT, grandparent_title TEXT, original_title TEXT, full_title TEXT, ' 'media_index INTEGER, parent_media_index INTEGER, ' 'thumb TEXT, parent_thumb TEXT, grandparent_thumb TEXT, year INTEGER, ' 'parent_rating_key INTEGER, grandparent_rating_key INTEGER, ' @@ -1264,6 +1264,18 @@ def dbcheck(): 'ALTER TABLE sessions ADD COLUMN guid TEXT' ) + # Upgrade sessions table from earlier versions + try: + c_db.execute('SELECT bandwidth FROM sessions') + except sqlite3.OperationalError: + logger.debug(u"Altering database. Updating database table sessions.") + c_db.execute( + 'ALTER TABLE sessions ADD COLUMN bandwidth INTEGER' + ) + c_db.execute( + 'ALTER TABLE sessions ADD COLUMN location TEXT' + ) + # Upgrade session_history table from earlier versions try: c_db.execute('SELECT reference_id FROM session_history') diff --git a/plexpy/activity_processor.py b/plexpy/activity_processor.py index 33cabeea..14ba9e82 100644 --- a/plexpy/activity_processor.py +++ b/plexpy/activity_processor.py @@ -56,6 +56,8 @@ class ActivityProcessor(object): 'year': session.get('year', ''), 'friendly_name': session.get('friendly_name', ''), 'ip_address': session.get('ip_address', ''), + 'bandwidth': session.get('bandwidth', 0), + 'location': session.get('location', ''), 'player': session.get('player', ''), 'product': session.get('product', ''), 'platform': session.get('platform', ''), diff --git a/plexpy/common.py b/plexpy/common.py index 79cd9a41..88efa0b3 100644 --- a/plexpy/common.py +++ b/plexpy/common.py @@ -340,10 +340,13 @@ NOTIFICATION_PARAMETERS = [ { 'category': 'Stream Details', 'parameters': [ - {'name': 'Streams', 'type': 'int', 'value': 'streams', 'description': 'The number of concurrent streams.'}, - {'name': 'Direct Plays', 'type': 'int', 'value': 'direct_plays', 'description': 'The number of concurrent direct plays.'}, - {'name': 'Direct Streams', 'type': 'int', 'value': 'direct_streams', 'description': 'The number of concurrent direct streams.'}, - {'name': 'Transcodes', 'type': 'int', 'value': 'transcodes', 'description': 'The number of concurrent transcodes.'}, + {'name': 'Streams', 'type': 'int', 'value': 'streams', 'description': 'The total number of concurrent streams.'}, + {'name': 'Direct Plays', 'type': 'int', 'value': 'direct_plays', 'description': 'The total number of concurrent direct plays.'}, + {'name': 'Direct Streams', 'type': 'int', 'value': 'direct_streams', 'description': 'The total number of concurrent direct streams.'}, + {'name': 'Transcodes', 'type': 'int', 'value': 'transcodes', 'description': 'The total number of concurrent transcodes.'}, + {'name': 'Total Bandwidth', 'type': 'int', 'value': 'total_bandwidth', 'description': 'The total Plex Streaming Brain reserved bandwidth (in kbps).', 'help_text': 'not the used bandwidth'}, + {'name': 'LAN Bandwidth', 'type': 'int', 'value': 'lan_bandwidth', 'description': 'The total Plex Streaming Brain reserved LAN bandwidth (in kbps).', 'help_text': 'not the used bandwidth'}, + {'name': 'WAN Bandwidth', 'type': 'int', 'value': 'wan_bandwidth', 'description': 'The total Plex Streaming Brain reserved WAN bandwidth (in kbps).', 'help_text': 'not the used bandwidth'}, {'name': 'User Streams', 'type': 'int', 'value': 'user_streams', 'description': 'The number of concurrent streams by the user streaming.'}, {'name': 'User Direct Plays', 'type': 'int', 'value': 'user_direct_plays', 'description': 'The number of concurrent direct plays by the user streaming.'}, {'name': 'User Direct Streams', 'type': 'int', 'value': 'user_direct_streams', 'description': 'The number of concurrent direct streams by the user streaming.'}, @@ -379,7 +382,7 @@ NOTIFICATION_PARAMETERS = [ {'name': 'Relayed', 'type': 'int', 'value': 'relayed', 'description': 'If the stream is using Plex Relay.', 'example': '0 or 1'}, {'name': 'Stream Local', 'type': 'int', 'value': 'stream_local', 'description': 'If the stream is local.', 'example': '0 or 1'}, {'name': 'Stream Location', 'type': 'str', 'value': 'stream_location', 'description': 'The network location of the stream.', 'example': 'lan or wan'}, - {'name': 'Stream Bandwidth', 'type': 'int', 'value': 'stream_bandwidth', 'description': 'The required bandwidth (in kbps) of the stream.', 'help_text': 'not the used bandwidth'}, + {'name': 'Stream Bandwidth', 'type': 'int', 'value': 'stream_bandwidth', 'description': 'The Plex Streaming Brain reserved bandwidth (in kbps) of the stream.', 'help_text': 'not the used bandwidth'}, {'name': 'Stream Container', 'type': 'str', 'value': 'stream_container', 'description': 'The media container of the stream.'}, {'name': 'Stream Bitrate', 'type': 'int', 'value': 'stream_bitrate', 'description': 'The bitrate (in kbps) of the stream.'}, {'name': 'Stream Aspect Ratio', 'type': 'float', 'value': 'stream_aspect_ratio', 'description': 'The aspect ratio of the stream.'}, diff --git a/plexpy/notification_handler.py b/plexpy/notification_handler.py index 18ae18a3..89eaf369 100644 --- a/plexpy/notification_handler.py +++ b/plexpy/notification_handler.py @@ -547,6 +547,10 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, m stream_count = len(sessions) user_stream_count = len(user_sessions) + lan_bandwidth = sum(helpers.cast_to_int(s['bandwidth']) for s in sessions if s['location'] == 'lan') + wan_bandwidth = sum(helpers.cast_to_int(s['bandwidth']) for s in sessions if s['location'] != 'lan') + total_bandwidth = lan_bandwidth + wan_bandwidth + # Generate a combined transcode decision value if session.get('stream_video_decision', '') == 'transcode' or session.get('stream_audio_decision', '') == 'transcode': transcode_decision = 'Transcode' @@ -813,6 +817,9 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, m 'direct_plays': transcode_decision_count['direct play'], 'direct_streams': transcode_decision_count['copy'], 'transcodes': transcode_decision_count['transcode'], + 'total_bandwidth': total_bandwidth, + 'lan_bandwidth': lan_bandwidth, + 'wan_bandwidth': wan_bandwidth, 'user_streams': user_stream_count, 'user_direct_plays': user_transcode_decision_count['direct play'], 'user_direct_streams': user_transcode_decision_count['copy'],