mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-22 06:13:25 -07:00
create helper function and apply to routes
This commit is contained in:
parent
6d858367a4
commit
79ebe41385
2 changed files with 35 additions and 7 deletions
|
@ -1793,3 +1793,24 @@ def get_ipv6_network_address(ip: str) -> str:
|
|||
if cidr_pattern.match(plexpy.CONFIG.NOTIFY_CONCURRENT_IPV6_CIDR):
|
||||
cidr = plexpy.CONFIG.NOTIFY_CONCURRENT_IPV6_CIDR
|
||||
return str(ip_network(ip+cidr, strict=False).network_address)
|
||||
|
||||
|
||||
def clean_plexapi_sessions(session: dict) -> dict:
|
||||
"Cleans Plex session data, removing the 10Gbps bandwidth/0.064Mbps quality bug that appears when video transcoding sometimes."
|
||||
|
||||
if isinstance(session, dict):
|
||||
# Reliable way to identify if a session is bugged.
|
||||
if session['bandwidth'] == "10000000" and session['quality_profile'] == '0.064 Mbps':
|
||||
|
||||
# Bitrate is unaffected by the bug, use bitrate to estimate the bandwidth reserve.
|
||||
session['bandwidth'] = str(int(int(session['bitrate']) * 1.5))
|
||||
|
||||
# Convert bitrate to a human readable quality profile.
|
||||
if int(session['bitrate']) > 1000000:
|
||||
session['quality_profile'] = f"{int(session['bitrate']) / 1000000:.1f} Gbps"
|
||||
elif int(session['bitrate']) > 1000:
|
||||
session['quality_profile'] = f"{int(session['bitrate']) / 1000:.1f} Mbps"
|
||||
else:
|
||||
session['quality_profile'] = f"{int(session['bitrate'])} kbps"
|
||||
|
||||
return session
|
||||
|
|
|
@ -352,7 +352,7 @@ class WebInterface(object):
|
|||
|
||||
if result:
|
||||
session = next((s for s in result['sessions'] if s['session_key'] == session_key), None)
|
||||
return serve_template(template_name="current_activity_instance.html", session=session)
|
||||
return serve_template(template_name="current_activity_instance.html", session=helpers.clean_plexapi_sessions(session))
|
||||
else:
|
||||
return serve_template(template_name="current_activity_instance.html", session=None)
|
||||
|
||||
|
@ -6049,19 +6049,26 @@ class WebInterface(object):
|
|||
'lan_bandwidth': 0,
|
||||
'wan_bandwidth': 0}
|
||||
|
||||
cleaned_sessions = []
|
||||
|
||||
for s in result['sessions']:
|
||||
if s['transcode_decision'] == 'transcode':
|
||||
s_cleaned = helpers.clean_plexapi_sessions(s)
|
||||
cleaned_sessions.append(s_cleaned)
|
||||
|
||||
if s_cleaned['transcode_decision'] == 'transcode':
|
||||
counts['stream_count_transcode'] += 1
|
||||
elif s['transcode_decision'] == 'copy':
|
||||
elif s_cleaned['transcode_decision'] == 'copy':
|
||||
counts['stream_count_direct_stream'] += 1
|
||||
else:
|
||||
counts['stream_count_direct_play'] += 1
|
||||
|
||||
counts['total_bandwidth'] += helpers.cast_to_int(s['bandwidth'])
|
||||
if s['location'] == 'lan':
|
||||
counts['lan_bandwidth'] += helpers.cast_to_int(s['bandwidth'])
|
||||
counts['total_bandwidth'] += helpers.cast_to_int(s_cleaned['bandwidth'])
|
||||
if s_cleaned['location'] == 'lan':
|
||||
counts['lan_bandwidth'] += helpers.cast_to_int(s_cleaned['bandwidth'])
|
||||
else:
|
||||
counts['wan_bandwidth'] += helpers.cast_to_int(s['bandwidth'])
|
||||
counts['wan_bandwidth'] += helpers.cast_to_int(s_cleaned['bandwidth'])
|
||||
|
||||
result['sessions'] = cleaned_sessions
|
||||
|
||||
result.update(counts)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue