From a2fac2b11c9a372c1a09932b04556fca2301592d Mon Sep 17 00:00:00 2001
From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com>
Date: Sat, 9 Apr 2022 17:52:17 -0700
Subject: [PATCH] Improve display of dynamic range on activity cards
* Ref #1654. Thanks @herby2212.
---
.../default/current_activity_instance.html | 7 ++-
data/interfaces/default/index.html | 4 +-
plexpy/helpers.py | 2 +-
plexpy/pmsconnect.py | 57 +++++++++++++------
plexpy/webserve.py | 1 +
5 files changed, 49 insertions(+), 22 deletions(-)
diff --git a/data/interfaces/default/current_activity_instance.html b/data/interfaces/default/current_activity_instance.html
index 6cd017e3..e9838b8a 100644
--- a/data/interfaces/default/current_activity_instance.html
+++ b/data/interfaces/default/current_activity_instance.html
@@ -231,11 +231,14 @@ DOCUMENTATION :: END
% if data['media_type'] in ('movie', 'episode', 'clip') and data['stream_video_decision']:
<%
- if data['video_dynamic_range'] == 'HDR':
+ if data['video_dynamic_range'] != 'SDR':
video_dynamic_range = ' ' + data['video_dynamic_range']
+ else:
+ video_dynamic_range = ''
+ if data['stream_video_dynamic_range'] != 'SDR' or video_dynamic_range:
stream_video_dynamic_range = ' ' + data['stream_video_dynamic_range']
else:
- video_dynamic_range = stream_video_dynamic_range = ''
+ stream_video_dynamic_range = ''
%>
% if data['stream_video_decision'] == 'transcode':
<%
diff --git a/data/interfaces/default/index.html b/data/interfaces/default/index.html
index 47b0d87d..715996c1 100644
--- a/data/interfaces/default/index.html
+++ b/data/interfaces/default/index.html
@@ -483,8 +483,8 @@
var video_decision = '';
if (['movie', 'episode', 'clip'].indexOf(s.media_type) > -1 && s.stream_video_decision) {
- var v_bd = (s.video_dynamic_range === 'HDR') ? ' ' + s.video_dynamic_range : '';
- var sv_bd = (s.video_dynamic_range === 'HDR') ? ' ' + s.stream_video_dynamic_range : '';
+ var v_bd = (s.video_dynamic_range !== 'SDR') ? ' ' + s.video_dynamic_range : '';
+ var sv_bd = (s.stream_video_dynamic_range !== 'SDR' || v_bd) ? ' ' + s.stream_video_dynamic_range : '';
var v_res= '';
switch (s.video_resolution.toLowerCase()) {
case 'sd':
diff --git a/plexpy/helpers.py b/plexpy/helpers.py
index fb4afb80..d5ef887f 100644
--- a/plexpy/helpers.py
+++ b/plexpy/helpers.py
@@ -1545,7 +1545,7 @@ def is_hdr(bit_depth, color_space):
def version_to_tuple(version):
- return tuple(cast_to_int(v) for v in version.strip('v').split('.'))
+ return tuple(cast_to_int(v) for v in version.strip('v').replace('-', '.').split('.'))
# https://stackoverflow.com/a/1855118
diff --git a/plexpy/pmsconnect.py b/plexpy/pmsconnect.py
index 2bdd4370..a993f6af 100644
--- a/plexpy/pmsconnect.py
+++ b/plexpy/pmsconnect.py
@@ -1401,6 +1401,7 @@ class PmsConnect(object):
'video_color_range': helpers.get_xml_attr(stream, 'colorRange'),
'video_color_space': helpers.get_xml_attr(stream, 'colorSpace'),
'video_color_trc': helpers.get_xml_attr(stream, 'colorTrc'),
+ 'video_dynamic_range': self.get_dynamic_range(stream),
'video_frame_rate': helpers.get_xml_attr(stream, 'frameRate'),
'video_ref_frames': helpers.get_xml_attr(stream, 'refFrames'),
'video_height': helpers.get_xml_attr(stream, 'height'),
@@ -1857,6 +1858,7 @@ class PmsConnect(object):
'stream_video_color_space': helpers.get_xml_attr(video_stream_info, 'colorSpace'),
'stream_video_color_trc': helpers.get_xml_attr(video_stream_info, 'colorTrc'),
'stream_video_codec_level': helpers.get_xml_attr(video_stream_info, 'level'),
+ 'stream_video_dynamic_range': self.get_dynamic_range(video_stream_info),
'stream_video_ref_frames': helpers.get_xml_attr(video_stream_info, 'refFrames'),
'stream_video_language': helpers.get_xml_attr(video_stream_info, 'language'),
'stream_video_language_code': helpers.get_xml_attr(video_stream_info, 'languageCode'),
@@ -1872,6 +1874,7 @@ class PmsConnect(object):
'stream_video_color_space': '',
'stream_video_color_trc': '',
'stream_video_codec_level': '',
+ 'stream_video_dynamic_range': '',
'stream_video_ref_frames': '',
'stream_video_language': '',
'stream_video_language_code': '',
@@ -2064,6 +2067,7 @@ class PmsConnect(object):
'video_color_range': '',
'video_color_space': '',
'video_color_trc': '',
+ 'video_dynamic_range': '',
'video_frame_rate': '',
'video_ref_frames': '',
'video_height': '',
@@ -2152,23 +2156,6 @@ class PmsConnect(object):
stream_details['stream_video_resolution'],
stream_details['stream_video_resolution'] + (video_details['stream_video_scan_type'][:1] or 'p'))
- if helpers.cast_to_int(source_video_details.get('video_bit_depth')) > 8 \
- and source_video_details.get('video_color_space') == 'bt2020nc':
- stream_details['video_dynamic_range'] = 'HDR'
- else:
- stream_details['video_dynamic_range'] = 'SDR'
-
- if stream_details['video_dynamic_range'] == 'HDR' \
- and video_details['stream_video_decision'] != 'transcode' \
- or helpers.cast_to_int(video_details['stream_video_bit_depth']) > 8 \
- and video_details['stream_video_color_space'] == 'bt2020nc':
- stream_details['stream_video_dynamic_range'] = 'HDR'
- else:
- stream_details['stream_video_dynamic_range'] = 'SDR'
- else:
- stream_details['video_dynamic_range'] = ''
- stream_details['stream_video_dynamic_range'] = ''
-
# Get the quality profile
if media_type in ('movie', 'episode', 'clip') and 'stream_bitrate' in stream_details:
if sync_id:
@@ -3182,3 +3169,39 @@ class PmsConnect(object):
return 'public'
return plexpy.CONFIG.PMS_UPDATE_CHANNEL
+
+ @staticmethod
+ def get_dynamic_range(stream):
+ extended_display_title = helpers.get_xml_attr(stream, 'extendedDisplayTitle')
+ bit_depth = helpers.cast_to_int(helpers.get_xml_attr(stream, 'bitDepth'))
+ color_space = helpers.get_xml_attr(stream, 'colorSpace')
+ DOVI_profile = helpers.get_xml_attr(stream, 'DOVIProfile')
+
+ HDR = bool(bit_depth > 8 and 'bt2020' in color_space)
+ DV = bool(DOVI_profile)
+
+ if not HDR and not DV:
+ return 'SDR'
+
+ video_dynamic_range = []
+
+ # HDR details got introduced with PMS version 1.25.6.5545
+ if helpers.version_to_tuple(plexpy.CONFIG.PMS_VERSION) >= helpers.version_to_tuple('1.25.6.5545'):
+ if 'Dolby Vision' in extended_display_title:
+ video_dynamic_range.append('Dolby Vision')
+ if 'HLG' in extended_display_title:
+ video_dynamic_range.append('HLG')
+ if 'HDR10' in extended_display_title:
+ video_dynamic_range.append('HDR10')
+ elif 'HDR' in extended_display_title:
+ video_dynamic_range.append('HDR')
+ else:
+ if DV:
+ video_dynamic_range.append('Dolby Vision')
+ elif HDR:
+ # Exact HDR version needs PMS version 1.25.6.5545 or newer
+ video_dynamic_range.append('HDR')
+
+ if not video_dynamic_range:
+ return 'SDR'
+ return '/'.join(video_dynamic_range)
diff --git a/plexpy/webserve.py b/plexpy/webserve.py
index 6c8a1ad6..ecf42b47 100644
--- a/plexpy/webserve.py
+++ b/plexpy/webserve.py
@@ -5349,6 +5349,7 @@ class WebInterface(object):
"video_color_range": "tv",
"video_color_space": "bt709",
"video_color_trc": "",
+ "video_dynamic_range": "SDR",
"video_frame_rate": "23.976",
"video_height": "1078",
"video_language": "",