From 2794a4b550b0d924d11967a477ecb4b5389266e5 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Thu, 2 Mar 2017 22:14:23 -0800 Subject: [PATCH] Add audio channel substitutions --- .../default/current_activity_instance.html | 8 ++++---- data/interfaces/default/index.html | 10 +++++----- plexpy/common.py | 9 +++++++++ plexpy/pmsconnect.py | 16 +++++++++++----- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/data/interfaces/default/current_activity_instance.html b/data/interfaces/default/current_activity_instance.html index bc34f8b0..77c53217 100644 --- a/data/interfaces/default/current_activity_instance.html +++ b/data/interfaces/default/current_activity_instance.html @@ -154,7 +154,7 @@ DOCUMENTATION :: END % if data['video_decision'] == 'transcode': Video  Transcode (${data['video_codec'].upper()} ${data['video_resolution'].rstrip('p') + ('p' if data['video_resolution'].lower() != 'sd' else '')} → ${data['stream_video_codec'].upper()} ${data['stream_video_resolution'].rstrip('p') + ('p' if data['stream_video_resolution'].lower() != 'sd' else '')}) % elif data['video_decision'] == 'copy': - Video  Direct Stream (${data['video_codec'].upper()} ${data['video_resolution'].rstrip('p') + ('p' if data['video_resolution'].lower() != 'sd' else '')} → ${data['stream_video_codec'].upper()} ${data['stream_video_resolution'].rstrip('p') + ('p' if data['stream_video_resolution'].lower() != 'sd' else '')}) + Video  Direct Stream (${data['stream_video_codec'].upper()} ${data['stream_video_resolution'].rstrip('p') + ('p' if data['stream_video_resolution'].lower() != 'sd' else '')}) % else: Video  Direct Play (${data['video_codec'].upper()} ${data['video_resolution'].rstrip('p') + ('p' if data['video_resolution'].lower() != 'sd' else '')}) % endif @@ -162,11 +162,11 @@ DOCUMENTATION :: END % endif % if data['media_type'] in ('movie', 'episode', 'clip', 'track'): % if data['audio_decision'] == 'transcode': - Audio  Transcode (${data['audio_codec'].upper()} ${data['audio_channels']}ch → ${data['stream_audio_codec'].upper()} ${data['stream_audio_channels']}ch) + Audio  Transcode (${data['audio_codec'].upper()} ${data['audio_channel_layout']} → ${data['stream_audio_codec'].upper()} ${data['stream_audio_channel_layout']}) % elif data['audio_decision'] == 'copy': - Audio  Direct Stream (${data['audio_codec'].upper()} ${data['audio_channels']}ch → ${data['stream_audio_codec'].upper()} ${data['stream_audio_channels']}ch) + Audio  Direct Stream (${data['stream_audio_codec'].upper()} ${data['stream_audio_channel_layout']}) % else: - Audio  Direct Play (${data['audio_codec'].upper()} ${data['audio_channels']}ch) + Audio  Direct Play (${data['audio_codec'].upper()} ${data['audio_channel_layout']}) % endif
% endif diff --git a/data/interfaces/default/index.html b/data/interfaces/default/index.html index 356c5eef..1ff0f70a 100644 --- a/data/interfaces/default/index.html +++ b/data/interfaces/default/index.html @@ -210,25 +210,25 @@ if (s.video_decision == 'transcode') { ts += 'Video  Transcode (' + s.video_codec.toUpperCase() + ' ' + v_res + ' → ' + s.stream_video_codec.toUpperCase() + ' ' + sv_res + ')
'; } else if (s.video_decision == 'copy') { - ts += 'Video  Direct Stream (' + s.video_codec.toUpperCase() + ' ' + v_res + ' → ' + s.stream_video_codec.toUpperCase() + ' ' + sv_res + ')
'; + ts += 'Video  Direct Stream (' + s.stream_video_codec.toUpperCase() + ' ' + sv_res + ')
'; } else { ts += 'Video  Direct Play (' + s.video_codec.toUpperCase() + ' ' + v_res + ')
'; } } if (s.audio_decision != '') { if (s.audio_decision == 'transcode') { - ts += 'Audio  Transcode (' + s.audio_codec.toUpperCase() + ' ' + s.audio_channels + 'ch → ' + s.stream_audio_codec.toUpperCase() + ' ' + s.stream_audio_channels + 'ch)
'; + ts += 'Audio  Transcode (' + s.audio_codec.toUpperCase() + ' ' + s.audio_channel_layout + ' → ' + s.stream_audio_codec.toUpperCase() + ' ' + s.stream_audio_channel_layout + ')
'; } else if (s.audio_decision == 'copy') { - ts += 'Audio  Direct Stream (' + s.audio_codec.toUpperCase() + ' ' + s.audio_channels + 'ch → ' + s.stream_audio_codec.toUpperCase() + ' ' + s.stream_audio_channels + 'ch)
'; + ts += 'Audio  Direct Stream (' + s.stream_audio_codec.toUpperCase() + ' ' + s.stream_audio_channel_layout + ')
'; } else { - ts += 'Audio  Direct Play (' + s.audio_codec.toUpperCase() + ' ' + s.audio_channels + 'ch)
'; + ts += 'Audio  Direct Play (' + s.audio_codec.toUpperCase() + ' ' + s.audio_channel_layout + ')
'; } } if (s.subtitles) { if (s.subtitle_decision == 'transcode') { ts += 'Subtitle  Transcode (' + s.subtitle_codec.toUpperCase() + ' → ' + s.stream_subtitle_codec.toUpperCase() + ')'; } else if (s.subtitle_decision == 'burn') { - ts += 'Subtitle  Burn (' + s.subtitle_codec.toUpperCase() + ')'; + ts += 'Subtitle  Burn (' + s.stream_subtitle_codec.toUpperCase() + ')'; } else { ts += 'Subtitle  Direct Play (' + s.subtitle_codec.toUpperCase() + ')'; } diff --git a/plexpy/common.py b/plexpy/common.py index 9257ace0..e0b6f0d7 100644 --- a/plexpy/common.py +++ b/plexpy/common.py @@ -56,6 +56,15 @@ MEDIA_FLAGS_VIDEO = {'avc1': 'h264', 'wmv3': 'wmvhd' } +AUDIO_CHANNELS = {'1': 'Mono', + '2': 'Stereo', + '3': '2.1', + '4': '3.1', + '6': '5.1', + '7': '6.1', + '8': '7.1' + } + QUALITY_PROFILES = {'20000': '20 Mbps 1080p', '12000': '12 Mbps 1080p', '10000': '10 Mbps 1080p', diff --git a/plexpy/pmsconnect.py b/plexpy/pmsconnect.py index 8d553343..0ac7a4ef 100644 --- a/plexpy/pmsconnect.py +++ b/plexpy/pmsconnect.py @@ -999,7 +999,6 @@ class PmsConnect(object): 'type': helpers.get_xml_attr(stream, 'streamType'), 'audio_bitrate': helpers.get_xml_attr(stream, 'bitrate'), 'audio_bitrate_mode': helpers.get_xml_attr(stream, 'bitrateMode'), - 'audio_channel_layout': helpers.get_xml_attr(stream, 'audioChannelLayout'), 'audio_sample_rate': helpers.get_xml_attr(stream, 'samplingRate'), 'audio_language': helpers.get_xml_attr(stream, 'language'), 'audio_language_code': helpers.get_xml_attr(stream, 'languageCode'), @@ -1024,6 +1023,8 @@ class PmsConnect(object): 'streams': streams }) + audio_channels = helpers.get_xml_attr(media, 'audioChannels') + medias.append({'id': helpers.get_xml_attr(media, 'id'), 'container': helpers.get_xml_attr(media, 'container'), 'bitrate': helpers.get_xml_attr(media, 'bitrate'), @@ -1034,7 +1035,8 @@ class PmsConnect(object): 'video_resolution': helpers.get_xml_attr(media, 'videoResolution'), 'video_framerate': helpers.get_xml_attr(media, 'videoFrameRate'), 'audio_codec': helpers.get_xml_attr(media, 'audioCodec'), - 'audio_channels': helpers.get_xml_attr(media, 'audioChannels'), + 'audio_channels': audio_channels, + 'audio_channel_layout': common.AUDIO_CHANNELS.get(audio_channels, audio_channels), 'optimized_version': 1 if helpers.get_xml_attr(media, 'proxyType') == '42' else 0, 'parts': parts }) @@ -1338,7 +1340,6 @@ class PmsConnect(object): audio_id = helpers.get_xml_attr(audio_stream_info, 'id') audio_details = {'stream_audio_bitrate': helpers.get_xml_attr(audio_stream_info, 'bitrate'), 'stream_audio_bitrate_mode': helpers.get_xml_attr(audio_stream_info, 'bitrateMode'), - 'stream_audio_channel_layout': helpers.get_xml_attr(audio_stream_info, 'audioChannelLayout'), 'stream_audio_sample_rate': helpers.get_xml_attr(audio_stream_info, 'samplingRate'), 'stream_audio_language': helpers.get_xml_attr(audio_stream_info, 'language'), 'stream_audio_language_code': helpers.get_xml_attr(audio_stream_info, 'languageCode'), @@ -1372,11 +1373,14 @@ class PmsConnect(object): else: quality_profile = '' + stream_audio_channels = helpers.get_xml_attr(stream_media_info, 'audioChannels') + stream_details = {'stream_container': helpers.get_xml_attr(stream_media_info, 'container'), 'stream_bitrate': helpers.get_xml_attr(stream_media_info, 'bitrate'), 'stream_aspect_ratio': helpers.get_xml_attr(stream_media_info, 'aspectRatio'), 'stream_audio_codec': helpers.get_xml_attr(stream_media_info, 'audioCodec'), - 'stream_audio_channels': helpers.get_xml_attr(stream_media_info, 'audioChannels'), + 'stream_audio_channels': stream_audio_channels, + 'stream_audio_channel_layout': common.AUDIO_CHANNELS.get(stream_audio_channels, stream_audio_channels), 'stream_video_codec': helpers.get_xml_attr(stream_media_info, 'videoCodec'), 'stream_video_framerate': helpers.get_xml_attr(stream_media_info, 'videoFrameRate'), 'stream_video_resolution': helpers.get_xml_attr(stream_media_info, 'videoResolution'), @@ -1400,6 +1404,7 @@ class PmsConnect(object): if media_type == 'clip': clip_media = session.getElementsByTagName('Media')[0] + audio_channels = helpers.get_xml_attr(clip_media, 'audioChannels') metadata_details = {'rating_key': helpers.get_xml_attr(session, 'ratingKey'), 'title': helpers.get_xml_attr(session, 'title'), 'summary': helpers.get_xml_attr(session, 'summary'), @@ -1414,7 +1419,8 @@ class PmsConnect(object): 'video_codec': helpers.get_xml_attr(clip_media, 'videoCodec'), 'video_resolution': helpers.get_xml_attr(clip_media, 'videoResolution'), 'audio_codec': helpers.get_xml_attr(clip_media, 'audioCodec'), - 'audio_channels': helpers.get_xml_attr(clip_media, 'audioChannels'), + 'audio_channels': audio_channels, + 'audio_channel_layout': common.AUDIO_CHANNELS.get(audio_channels, audio_channels) } else: media_id = helpers.get_xml_attr(stream_media_info, 'id')