Improve quality profile logic

This commit is contained in:
JonnyWong16 2017-03-03 18:15:14 -08:00
parent 74876ea3c9
commit fd1bd7f215
2 changed files with 28 additions and 20 deletions

View file

@ -65,19 +65,19 @@ AUDIO_CHANNELS = {'1': 'Mono',
'8': '7.1' '8': '7.1'
} }
QUALITY_PROFILES = {'20000': '20 Mbps 1080p', QUALITY_PROFILES = {20000: '20 Mbps 1080p',
'12000': '12 Mbps 1080p', 12000: '12 Mbps 1080p',
'10000': '10 Mbps 1080p', 10000: '10 Mbps 1080p',
'8000': '8 Mbps 1080p', 8000: '8 Mbps 1080p',
'4000': '4 Mbps 720p', 4000: '4 Mbps 720p',
'3000': '3 Mbps 720p', 3000: '3 Mbps 720p',
'2000': '2 Mbps 720p', 2000: '2 Mbps 720p',
'1500': '1.5 Mbps 480p', 1500: '1.5 Mbps 480p',
'720': '720 kbps', 720: '720 kbps',
'320': '320 kbps', 320: '320 kbps',
'208': '208 kbps', 208: '208 kbps',
'96': '96 kbps', 96: '96 kbps',
'64': '64 kbps' 64: '64 kbps'
} }
SCHEDULER_LIST = ['Check GitHub for updates', SCHEDULER_LIST = ['Check GitHub for updates',

View file

@ -1376,12 +1376,6 @@ class PmsConnect(object):
else: else:
bif_thumb = '' bif_thumb = ''
# Get the quality profile
if video_details:
quality_profile = common.QUALITY_PROFILES.get(video_details['stream_video_bitrate'], 'Original')
else:
quality_profile = ''
stream_audio_channels = helpers.get_xml_attr(stream_media_info, 'audioChannels') stream_audio_channels = helpers.get_xml_attr(stream_media_info, 'audioChannels')
# Generate a combined transcode decision value # Generate a combined transcode decision value
@ -1408,7 +1402,6 @@ class PmsConnect(object):
'transcode_decision': transcode_decision, 'transcode_decision': transcode_decision,
'optimized_version': 1 if helpers.get_xml_attr(stream_media_info, 'proxyType') == '42' else 0, 'optimized_version': 1 if helpers.get_xml_attr(stream_media_info, 'proxyType') == '42' else 0,
'optimized_version_profile': helpers.get_xml_attr(stream_media_info, 'title'), 'optimized_version_profile': helpers.get_xml_attr(stream_media_info, 'title'),
'quality_profile': quality_profile,
'indexes': 1 if indexes == 'sd' else 0, 'indexes': 1 if indexes == 'sd' else 0,
'bif_thumb': bif_thumb, 'bif_thumb': bif_thumb,
'subtitles': 1 if subtitle_details else 0 'subtitles': 1 if subtitle_details else 0
@ -1456,11 +1449,26 @@ class PmsConnect(object):
if subtitle_id: if subtitle_id:
source_subtitle_details = next((p for p in source_media_part_streams if p['id'] == subtitle_id), {}) source_subtitle_details = next((p for p in source_media_part_streams if p['id'] == subtitle_id), {})
# Get the quality profile
if media_type in ('movie', 'episode', 'clip'):
stream_video_bitrate = helpers.cast_to_int(video_details['stream_video_bitrate'])
video_bitrate = helpers.cast_to_int(source_video_details['video_bitrate'])
try:
quailtiy_bitrate = min(b for b in common.QUALITY_PROFILES if stream_video_bitrate <= b <= video_bitrate)
quality_profile = common.QUALITY_PROFILES[quailtiy_bitrate]
except ValueError:
quality_profile = 'Original'
else:
quality_profile = ''
# Entire session output (single dict for backwards compatibility) # Entire session output (single dict for backwards compatibility)
session_output = {'session_key': helpers.get_xml_attr(session, 'sessionKey'), session_output = {'session_key': helpers.get_xml_attr(session, 'sessionKey'),
'media_type': media_type, 'media_type': media_type,
'view_offset': progress, 'view_offset': progress,
'progress_percent': str(helpers.get_percent(progress, stream_details['stream_duration'])), 'progress_percent': str(helpers.get_percent(progress, stream_details['stream_duration'])),
'quality_profile': quality_profile,
'user': user_details['username'] # Keep for backwards compatibility 'user': user_details['username'] # Keep for backwards compatibility
} }