From bf7e432c0c2f4047b509e38b0645c33e5eb957bb Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Sun, 31 Dec 2017 17:13:38 -0800 Subject: [PATCH] Add total bandwidth to activity header --- .../default/current_activity_instance.html | 2 +- data/interfaces/default/index.html | 37 +++++++++++++------ plexpy/webserve.py | 5 ++- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/data/interfaces/default/current_activity_instance.html b/data/interfaces/default/current_activity_instance.html index a8134122..42fe8786 100644 --- a/data/interfaces/default/current_activity_instance.html +++ b/data/interfaces/default/current_activity_instance.html @@ -301,7 +301,7 @@ DOCUMENTATION :: END bw = str(bw) + ' kbps' %> ${bw} - + % elif data['synced_version'] == 1 or data['channel_stream'] == 1: None % else: diff --git a/data/interfaces/default/index.html b/data/interfaces/default/index.html index aa8e3a41..74c2a963 100644 --- a/data/interfaces/default/index.html +++ b/data/interfaces/default/index.html @@ -11,7 +11,15 @@
-

Activity   

+

Activity    + + + +

Checking for activity...
@@ -238,6 +246,8 @@ var create_instances = []; var activity_ready = true; + $('#currentActivityHeader-bandwidth-tooltip').tooltip({ container: 'body', placement: 'right', delay: 50 }); + function getCurrentActivity() { activity_ready = false; @@ -266,7 +276,7 @@ % else: var msg_settings = '' % endif - $('#currentActivityHeader').text(''); + $('#currentActivityHeader').hide(); $('#currentActivity').html('
There was an error communicating with your Plex Server.' + msg_settings + '
'); return } @@ -280,20 +290,25 @@ // Update the header stream counts var sc_dp = current_activity.stream_count_direct_play, sc_ds = current_activity.stream_count_direct_stream, - sc_tc = current_activity.stream_count_transcode; - var header_count = stream_count + ' stream' + (stream_count > 1 ? 's' : '') + ' ('; + sc_tc = current_activity.stream_count_transcode, + total_bw = current_activity.total_bandwidth; + var streams_header = stream_count + ' stream' + (stream_count > 1 ? 's' : '') + ' ('; if (sc_dp) { - header_count += sc_dp + ' direct play' + (sc_dp > 1 ? 's' : '') + ', '; + streams_header += sc_dp + ' direct play' + (sc_dp > 1 ? 's' : '') + ', '; } if (sc_ds) { - header_count += sc_ds + ' direct stream' + (sc_ds > 1 ? 's' : '') + ', '; + streams_header += sc_ds + ' direct stream' + (sc_ds > 1 ? 's' : '') + ', '; } if (sc_tc) { - header_count += sc_tc + ' transcode' + (sc_tc > 1 ? 's' : '') + ', '; + streams_header += sc_tc + ' transcode' + (sc_tc > 1 ? 's' : '') + ', '; } - header_count = header_count.replace(/, $/, ''); - header_count += ')'; - $('#currentActivityHeader').text(header_count); + streams_header = streams_header.replace(/, $/, '') + ')'; + $('#currentActivityHeader-streams').text(streams_header); + + var bandwidth_header = (total_bw > 1000) ? ((total_bw / 1000).toFixed(1) + ' Mbps') : (total_bw + ' kbps'); + $('#currentActivityHeader-bandwidth').text(bandwidth_header); + + $('#currentActivityHeader').show(); sessions.forEach(function (session) { var s = new Proxy(session, defaultHandler); @@ -504,7 +519,7 @@ }); } else { - $('#currentActivityHeader').text(''); + $('#currentActivityHeader').hide(); $('#currentActivity').html('
Nothing is currently being played.
'); } diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 21dddd66..aac67777 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -4434,7 +4434,8 @@ class WebInterface(object): counts = {'stream_count_direct_play': 0, 'stream_count_direct_stream': 0, - 'stream_count_transcode': 0} + 'stream_count_transcode': 0, + 'total_bandwidth': 0} for s in result['sessions']: if s['transcode_decision'] == 'transcode': @@ -4444,6 +4445,8 @@ class WebInterface(object): else: counts['stream_count_direct_play'] += 1 + counts['total_bandwidth'] += helpers.cast_to_int(s['bandwidth']) + result.update(counts) return result