Add {stream_time}, {remaining_time}, and {progress_time} to notification options

This commit is contained in:
JonnyWong16 2016-01-31 16:15:06 -08:00
parent 3248e6500e
commit 14a90d84ec
4 changed files with 57 additions and 9 deletions

View file

@ -1093,11 +1093,11 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
</tr> </tr>
<tr> <tr>
<td><strong>{datestamp}</strong></td> <td><strong>{datestamp}</strong></td>
<td>The date the notification was triggered.</td> <td>The date (in date format) the notification was triggered.</td>
</tr> </tr>
<tr> <tr>
<td><strong>{timestamp}</strong></td> <td><strong>{timestamp}</strong></td>
<td>The time the notification was triggered.</td> <td>The time (in time format) the notification was triggered.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -1134,14 +1134,26 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
<td><strong>{stream_duration}</strong></td> <td><strong>{stream_duration}</strong></td>
<td>The stream duration (in minutes) for the item.</td> <td>The stream duration (in minutes) for the item.</td>
</tr> </tr>
<tr>
<td><strong>{stream_time}</strong></td>
<td>The stream duration (in time format) for the item.</td>
</tr>
<tr> <tr>
<td><strong>{remaining_duration}</strong></td> <td><strong>{remaining_duration}</strong></td>
<td>The remaining duration (in minutes) for the item.</td> <td>The remaining duration (in minutes) for the item.</td>
</tr> </tr>
<tr> <tr>
<td><strong>{progress}</strong></td> <td><strong>{remaining_time}</strong></td>
<td>The remaining duration (in time format) for the item.</td>
</tr>
<tr>
<td><strong>{progress_duration}</strong></td>
<td>The last reported offset (in minutes) for the item.</td> <td>The last reported offset (in minutes) for the item.</td>
</tr> </tr>
<tr>
<td><strong>{progress_time}</strong></td>
<td>The last reported offset (in time format) for the item.</td>
</tr>
<tr> <tr>
<td><strong>{progress_percent}</strong></td> <td><strong>{progress_percent}</strong></td>
<td>The last reported progress percent for the item.</td> <td>The last reported progress percent for the item.</td>
@ -1222,6 +1234,10 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
<td><strong>{transcode_audio_channels}</strong></td> <td><strong>{transcode_audio_channels}</strong></td>
<td>The audio channels of the transcoded media.</td> <td>The audio channels of the transcoded media.</td>
</tr> </tr>
<tr>
<td><strong>{session_key}</strong></td>
<td>The unique identifier for the session.</td>
</tr>
<tr> <tr>
<td><strong>{user_id}</strong></td> <td><strong>{user_id}</strong></td>
<td>The unique identifier for the user.</td> <td>The unique identifier for the user.</td>

View file

@ -512,6 +512,7 @@ class Config(object):
self.MOVIE_LOGGING_ENABLE = 0 self.MOVIE_LOGGING_ENABLE = 0
self.TV_LOGGING_ENABLE = 0 self.TV_LOGGING_ENABLE = 0
self.CONFIG_VERSION = '1' self.CONFIG_VERSION = '1'
if self.CONFIG_VERSION == '1': if self.CONFIG_VERSION == '1':
# Change home_stats_cards to list # Change home_stats_cards to list
if self.HOME_STATS_CARDS: if self.HOME_STATS_CARDS:
@ -525,4 +526,20 @@ class Config(object):
if 'library_statistics' in home_library_cards: if 'library_statistics' in home_library_cards:
home_library_cards.remove('library_statistics') home_library_cards.remove('library_statistics')
self.HOME_LIBRARY_CARDS = home_library_cards self.HOME_LIBRARY_CARDS = home_library_cards
self.CONFIG_VERSION = '2' self.CONFIG_VERSION = '2'
if self.CONFIG_VERSION == '2':
self.NOTIFY_ON_START_SUBJECT_TEXT = self.NOTIFY_ON_START_SUBJECT_TEXT.replace('{progress}','{progress_duration}')
self.NOTIFY_ON_START_BODY_TEXT = self.NOTIFY_ON_START_BODY_TEXT.replace('{progress}','{progress_duration}')
self.NOTIFY_ON_STOP_SUBJECT_TEXT = self.NOTIFY_ON_STOP_SUBJECT_TEXT.replace('{progress}','{progress_duration}')
self.NOTIFY_ON_STOP_BODY_TEXT = self.NOTIFY_ON_STOP_BODY_TEXT.replace('{progress}','{progress_duration}')
self.NOTIFY_ON_PAUSE_SUBJECT_TEXT = self.NOTIFY_ON_PAUSE_SUBJECT_TEXT.replace('{progress}','{progress_duration}')
self.NOTIFY_ON_PAUSE_BODY_TEXT = self.NOTIFY_ON_PAUSE_BODY_TEXT.replace('{progress}','{progress_duration}')
self.NOTIFY_ON_RESUME_SUBJECT_TEXT = self.NOTIFY_ON_RESUME_SUBJECT_TEXT.replace('{progress}','{progress_duration}')
self.NOTIFY_ON_RESUME_BODY_TEXT = self.NOTIFY_ON_RESUME_BODY_TEXT.replace('{progress}','{progress_duration}')
self.NOTIFY_ON_BUFFER_SUBJECT_TEXT = self.NOTIFY_ON_BUFFER_SUBJECT_TEXT.replace('{progress}','{progress_duration}')
self.NOTIFY_ON_BUFFER_BODY_TEXT = self.NOTIFY_ON_BUFFER_BODY_TEXT.replace('{progress}','{progress_duration}')
self.NOTIFY_ON_WATCHED_SUBJECT_TEXT = self.NOTIFY_ON_WATCHED_SUBJECT_TEXT.replace('{progress}','{progress_duration}')
self.NOTIFY_ON_WATCHED_BODY_TEXT = self.NOTIFY_ON_WATCHED_BODY_TEXT.replace('{progress}','{progress_duration}')
self.NOTIFY_SCRIPTS_ARGS_TEXT = self.NOTIFY_SCRIPTS_ARGS_TEXT.replace('{progress}','{progress_duration}')
self.CONFIG_VERSION = '3'

View file

@ -135,6 +135,15 @@ def convert_seconds(s):
return minutes return minutes
def convert_seconds_to_minutes(s):
if str(s).isdigit():
minutes = round(float(s) / 60, 0)
return math.trunc(minutes)
return 0
def today(): def today():
today = datetime.date.today() today = datetime.date.today()

View file

@ -446,14 +446,17 @@ def build_notify_text(session=None, timeline=None, state=None):
transcode_decision = 'Direct Play' transcode_decision = 'Direct Play'
if state != 'play': if state != 'play':
stream_duration = int((time.time() - helpers.cast_to_float(session.get('started', 0)) - stream_duration = helpers.convert_seconds_to_minutes(
helpers.cast_to_float(session.get('paused_counter', 0))) / 60) time.time() -
helpers.cast_to_float(session.get('started', 0)) -
helpers.cast_to_float(session.get('paused_counter', 0)))
else: else:
stream_duration = 0 stream_duration = 0
view_offset = helpers.convert_milliseconds_to_minutes(session.get('view_offset', 0)) view_offset = helpers.convert_milliseconds_to_minutes(session.get('view_offset', 0))
duration = helpers.convert_milliseconds_to_minutes(metadata['duration']) duration = helpers.convert_milliseconds_to_minutes(metadata['duration'])
progress_percent = helpers.get_percent(view_offset, duration) progress_percent = helpers.get_percent(view_offset, duration)
remaining_duration = duration - view_offset
# Fix metadata params for notify recently added grandparent # Fix metadata params for notify recently added grandparent
if state == 'created' and plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_GRANDPARENT: if state == 'created' and plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_GRANDPARENT:
@ -468,7 +471,7 @@ def build_notify_text(session=None, timeline=None, state=None):
artist_name = metadata['grandparent_title'] artist_name = metadata['grandparent_title']
album_name = metadata['parent_title'] album_name = metadata['parent_title']
track_name = metadata['title'] track_name = metadata['title']
available_params = {# Global paramaters available_params = {# Global paramaters
'server_name': server_name, 'server_name': server_name,
'server_uptime': server_uptime, 'server_uptime': server_uptime,
@ -482,8 +485,11 @@ def build_notify_text(session=None, timeline=None, state=None):
'player': session.get('player',''), 'player': session.get('player',''),
'ip_address': session.get('ip_address','N/A'), 'ip_address': session.get('ip_address','N/A'),
'stream_duration': stream_duration, 'stream_duration': stream_duration,
'remaining_duration': duration - view_offset, 'stream_time': arrow.get(stream_duration * 60).format(duration_format),
'progress': view_offset, 'remaining_duration': remaining_duration,
'remaining_time': arrow.get(remaining_duration * 60).format(duration_format),
'progress_duration': view_offset,
'progress_time': arrow.get(view_offset * 60).format(duration_format),
'progress_percent': progress_percent, 'progress_percent': progress_percent,
'container': session.get('container',''), 'container': session.get('container',''),
'video_codec': session.get('video_codec',''), 'video_codec': session.get('video_codec',''),