mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-13 08:42:59 -07:00
Clean up build_notify_text
* session is now a dict, so no need for "default values"
This commit is contained in:
parent
c17bf79d79
commit
3248e6500e
1 changed files with 57 additions and 101 deletions
|
@ -340,6 +340,11 @@ def set_notify_state(session, state, agent_info):
|
||||||
|
|
||||||
|
|
||||||
def build_notify_text(session=None, timeline=None, state=None):
|
def build_notify_text(session=None, timeline=None, state=None):
|
||||||
|
# Get time formats
|
||||||
|
date_format = plexpy.CONFIG.DATE_FORMAT.replace('Do','').replace('zz','')
|
||||||
|
time_format = plexpy.CONFIG.TIME_FORMAT.replace('Do','').replace('zz','')
|
||||||
|
duration_format = plexpy.CONFIG.TIME_FORMAT.replace('Do','').replace('zz','').replace('a','').replace('A','')
|
||||||
|
|
||||||
# Get the server name
|
# Get the server name
|
||||||
server_name = plexpy.CONFIG.PMS_NAME
|
server_name = plexpy.CONFIG.PMS_NAME
|
||||||
|
|
||||||
|
@ -428,79 +433,26 @@ def build_notify_text(session=None, timeline=None, state=None):
|
||||||
else:
|
else:
|
||||||
full_title = metadata['title']
|
full_title = metadata['title']
|
||||||
|
|
||||||
duration = helpers.convert_milliseconds_to_minutes(metadata['duration'])
|
|
||||||
|
|
||||||
# Default values
|
|
||||||
user = ''
|
|
||||||
platform = ''
|
|
||||||
player = ''
|
|
||||||
ip_address = 'N/A'
|
|
||||||
stream_duration = 0
|
|
||||||
view_offset = 0
|
|
||||||
container = ''
|
|
||||||
video_codec = ''
|
|
||||||
video_bitrate = ''
|
|
||||||
video_width = ''
|
|
||||||
video_height = ''
|
|
||||||
video_resolution = ''
|
|
||||||
video_framerate = ''
|
|
||||||
aspect_ratio = ''
|
|
||||||
audio_codec = ''
|
|
||||||
audio_channels = ''
|
|
||||||
transcode_decision = ''
|
|
||||||
video_decision = ''
|
|
||||||
audio_decision = ''
|
|
||||||
transcode_container = ''
|
|
||||||
transcode_video_codec = ''
|
|
||||||
transcode_video_width = ''
|
|
||||||
transcode_video_height = ''
|
|
||||||
transcode_audio_codec = ''
|
|
||||||
transcode_audio_channels = ''
|
|
||||||
user_id = ''
|
|
||||||
|
|
||||||
# Session values
|
# Session values
|
||||||
if session:
|
if session is None:
|
||||||
# Generate a combined transcode decision value
|
session = {}
|
||||||
video_decision = session['video_decision'].title()
|
|
||||||
audio_decision = session['audio_decision'].title()
|
|
||||||
|
|
||||||
if session['video_decision'] == 'transcode' or session['audio_decision'] == 'transcode':
|
# Generate a combined transcode decision value
|
||||||
|
if session.get('video_decision','') == 'transcode' or session.get('audio_decision','') == 'transcode':
|
||||||
transcode_decision = 'Transcode'
|
transcode_decision = 'Transcode'
|
||||||
elif session['video_decision'] == 'copy' or session['audio_decision'] == 'copy':
|
elif session.get('video_decision','') == 'copy' or session.get('audio_decision','') == 'copy':
|
||||||
transcode_decision = 'Direct Stream'
|
transcode_decision = 'Direct Stream'
|
||||||
else:
|
else:
|
||||||
transcode_decision = 'Direct Play'
|
transcode_decision = 'Direct Play'
|
||||||
|
|
||||||
if state != 'play':
|
if state != 'play':
|
||||||
if session['paused_counter']:
|
stream_duration = int((time.time() - helpers.cast_to_float(session.get('started', 0)) -
|
||||||
stream_duration = int((time.time() - helpers.cast_to_float(session['started']) -
|
helpers.cast_to_float(session.get('paused_counter', 0))) / 60)
|
||||||
helpers.cast_to_float(session['paused_counter'])) / 60)
|
|
||||||
else:
|
else:
|
||||||
stream_duration = int((time.time() - helpers.cast_to_float(session['started'])) / 60)
|
stream_duration = 0
|
||||||
|
|
||||||
view_offset = helpers.convert_milliseconds_to_minutes(session['view_offset'])
|
|
||||||
user = session['friendly_name']
|
|
||||||
platform = session['platform']
|
|
||||||
player = session['player']
|
|
||||||
ip_address = session['ip_address'] if session['ip_address'] else 'N/A'
|
|
||||||
container = session['container']
|
|
||||||
video_codec = session['video_codec']
|
|
||||||
video_bitrate = session['bitrate']
|
|
||||||
video_width = session['width']
|
|
||||||
video_height = session['height']
|
|
||||||
video_resolution = session['video_resolution']
|
|
||||||
video_framerate = session['video_framerate']
|
|
||||||
aspect_ratio = session['aspect_ratio']
|
|
||||||
audio_codec = session['audio_codec']
|
|
||||||
audio_channels = session['audio_channels']
|
|
||||||
transcode_container = session['transcode_container']
|
|
||||||
transcode_video_codec = session['transcode_video_codec']
|
|
||||||
transcode_video_width = session['transcode_width']
|
|
||||||
transcode_video_height = session['transcode_height']
|
|
||||||
transcode_audio_codec = session['transcode_audio_codec']
|
|
||||||
transcode_audio_channels = session['transcode_audio_channels']
|
|
||||||
user_id = session['user_id']
|
|
||||||
|
|
||||||
|
view_offset = helpers.convert_milliseconds_to_minutes(session.get('view_offset', 0))
|
||||||
|
duration = helpers.convert_milliseconds_to_minutes(metadata['duration'])
|
||||||
progress_percent = helpers.get_percent(view_offset, duration)
|
progress_percent = helpers.get_percent(view_offset, duration)
|
||||||
|
|
||||||
# Fix metadata params for notify recently added grandparent
|
# Fix metadata params for notify recently added grandparent
|
||||||
|
@ -517,41 +469,45 @@ def build_notify_text(session=None, timeline=None, state=None):
|
||||||
album_name = metadata['parent_title']
|
album_name = metadata['parent_title']
|
||||||
track_name = metadata['title']
|
track_name = metadata['title']
|
||||||
|
|
||||||
available_params = {'server_name': server_name,
|
available_params = {# Global paramaters
|
||||||
|
'server_name': server_name,
|
||||||
'server_uptime': server_uptime,
|
'server_uptime': server_uptime,
|
||||||
'action': state,
|
'action': state.title(),
|
||||||
'datestamp': arrow.now().format(plexpy.CONFIG.DATE_FORMAT.replace('Do','').replace('zz','')),
|
'datestamp': arrow.now().format(date_format),
|
||||||
'timestamp': arrow.now().format(plexpy.CONFIG.TIME_FORMAT.replace('Do','').replace('zz','')),
|
'timestamp': arrow.now().format(time_format),
|
||||||
|
# Stream parameters
|
||||||
'streams': stream_count,
|
'streams': stream_count,
|
||||||
'user': user,
|
'user': session.get('friendly_name',''),
|
||||||
'platform': platform,
|
'platform': session.get('platform',''),
|
||||||
'player': player,
|
'player': session.get('player',''),
|
||||||
'ip_address': ip_address,
|
'ip_address': session.get('ip_address','N/A'),
|
||||||
'media_type': metadata['media_type'],
|
|
||||||
'stream_duration': stream_duration,
|
'stream_duration': stream_duration,
|
||||||
'remaining_duration': duration - view_offset,
|
'remaining_duration': duration - view_offset,
|
||||||
'progress': view_offset,
|
'progress': view_offset,
|
||||||
'progress_percent': progress_percent,
|
'progress_percent': progress_percent,
|
||||||
'container': container,
|
'container': session.get('container',''),
|
||||||
'video_codec': video_codec,
|
'video_codec': session.get('video_codec',''),
|
||||||
'video_bitrate': video_bitrate,
|
'video_bitrate': session.get('bitrate',''),
|
||||||
'video_width': video_width,
|
'video_width': session.get('width',''),
|
||||||
'video_height': video_height,
|
'video_height': session.get('height',''),
|
||||||
'video_resolution': video_resolution,
|
'video_resolution': session.get('video_resolution',''),
|
||||||
'video_framerate': video_framerate,
|
'video_framerate': session.get('video_framerate',''),
|
||||||
'aspect_ratio': aspect_ratio,
|
'aspect_ratio': session.get('aspect_ratio',''),
|
||||||
'audio_codec': audio_codec,
|
'audio_codec': session.get('audio_codec',''),
|
||||||
'audio_channels': audio_channels,
|
'audio_channels': session.get('audio_channels',''),
|
||||||
'transcode_decision': transcode_decision,
|
'transcode_decision': transcode_decision,
|
||||||
'video_decision': video_decision,
|
'video_decision': session.get('video_decision','').title(),
|
||||||
'audio_decision': audio_decision,
|
'audio_decision': session.get('audio_decision','').title(),
|
||||||
'transcode_container': transcode_container,
|
'transcode_container': session.get('transcode_container',''),
|
||||||
'transcode_video_codec': transcode_video_codec,
|
'transcode_video_codec': session.get('transcode_video_codec',''),
|
||||||
'transcode_video_width': transcode_video_width,
|
'transcode_video_width': session.get('transcode_width',''),
|
||||||
'transcode_video_height': transcode_video_height,
|
'transcode_video_height': session.get('transcode_height',''),
|
||||||
'transcode_audio_codec': transcode_audio_codec,
|
'transcode_audio_codec': session.get('transcode_audio_codec',''),
|
||||||
'transcode_audio_channels': transcode_audio_channels,
|
'transcode_audio_channels': session.get('transcode_audio_channels',''),
|
||||||
'user_id': user_id,
|
'session_key': session.get('session_key',''),
|
||||||
|
'user_id': session.get('user_id',''),
|
||||||
|
# Metadata parameters
|
||||||
|
'media_type': metadata['media_type'],
|
||||||
'title': full_title,
|
'title': full_title,
|
||||||
'library_name': metadata['library_name'],
|
'library_name': metadata['library_name'],
|
||||||
'show_name': show_name,
|
'show_name': show_name,
|
||||||
|
@ -575,7 +531,7 @@ def build_notify_text(session=None, timeline=None, state=None):
|
||||||
'summary': metadata['summary'],
|
'summary': metadata['summary'],
|
||||||
'tagline': metadata['tagline'],
|
'tagline': metadata['tagline'],
|
||||||
'rating': metadata['rating'],
|
'rating': metadata['rating'],
|
||||||
'duration': duration,
|
'duration': metadata['duration'],
|
||||||
'section_id': metadata['section_id'],
|
'section_id': metadata['section_id'],
|
||||||
'rating_key': metadata['rating_key'],
|
'rating_key': metadata['rating_key'],
|
||||||
'parent_rating_key': metadata['parent_rating_key'],
|
'parent_rating_key': metadata['parent_rating_key'],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue