mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 15:32:38 -07:00
Add metadata parameters to notification string options.
Add SxE to notification title if type is episode.
This commit is contained in:
parent
abc90e1252
commit
824d4dfea2
6 changed files with 82 additions and 54 deletions
|
@ -567,6 +567,9 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div>
|
<div>
|
||||||
|
<p class="help-block">
|
||||||
|
If a value for a selected parameter cannot be provided nothing will be outputted for it.
|
||||||
|
</p>
|
||||||
<table>
|
<table>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -594,7 +597,44 @@
|
||||||
<td>Returns the transcode decisions for the media item.</td>
|
<td>Returns the transcode decisions for the media item.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">More options will be added soon.</td>
|
<td width="150"><strong>{year}</strong></td>
|
||||||
|
<td>Returns the release year for the media item.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td width="150"><strong>{studio}</strong></td>
|
||||||
|
<td>Returns the studio for the media item.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td width="150"><strong>{content_rating}</strong></td>
|
||||||
|
<td>Returns the content rating for the media item. E.g. TV-MA, TV-PG, etc.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td width="150"><strong>{summary}</strong></td>
|
||||||
|
<td>Returns the a short plot summary for the media item.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td width="150"><strong>{season_num}</strong></td>
|
||||||
|
<td>Returns the season number for the media item if item is episode.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td width="150"><strong>{episode_num}</strong></td>
|
||||||
|
<td>Returns the episode number for the media item if item is episode.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td width="150"><strong>{rating}</strong></td>
|
||||||
|
<td>Returns the rating (out of 10) for the item.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td width="150"><strong>{duration}</strong></td>
|
||||||
|
<td>Returns the duration (in minutes) for the item.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td width="150"><strong>{progress}</strong></td>
|
||||||
|
<td>Returns the last reported offset (in minutes) for the item.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td width="150"><strong>{progress_percent}</strong></td>
|
||||||
|
<td>Returns the last reported progress percent for the item.</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -99,7 +99,7 @@ def latinToAscii(unicrap):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
r += str(i)
|
r += str(i)
|
||||||
return r.encode('utf-8')
|
return r
|
||||||
|
|
||||||
|
|
||||||
def convert_milliseconds(ms):
|
def convert_milliseconds(ms):
|
||||||
|
@ -115,7 +115,7 @@ def convert_milliseconds(ms):
|
||||||
|
|
||||||
def convert_milliseconds_to_minutes(ms):
|
def convert_milliseconds_to_minutes(ms):
|
||||||
|
|
||||||
if ms.isdigit():
|
if str(ms).isdigit():
|
||||||
seconds = float(ms) / 1000
|
seconds = float(ms) / 1000
|
||||||
minutes = round(seconds / 60, 0)
|
minutes = round(seconds / 60, 0)
|
||||||
|
|
||||||
|
|
|
@ -44,49 +44,7 @@ def check_active_sessions():
|
||||||
'transcode_container, transcode_video_codec, transcode_audio_codec, '
|
'transcode_container, transcode_video_codec, transcode_audio_codec, '
|
||||||
'transcode_audio_channels, transcode_width, transcode_height, paused_counter '
|
'transcode_audio_channels, transcode_width, transcode_height, paused_counter '
|
||||||
'FROM sessions')
|
'FROM sessions')
|
||||||
for result in db_streams:
|
for stream in db_streams:
|
||||||
# Build a result dictionary for easier referencing
|
|
||||||
stream = {'started': result[0],
|
|
||||||
'session_key': result[1],
|
|
||||||
'rating_key': result[2],
|
|
||||||
'media_type': result[3],
|
|
||||||
'title': result[4],
|
|
||||||
'parent_title': result[5],
|
|
||||||
'grandparent_title': result[6],
|
|
||||||
'user_id': result[7],
|
|
||||||
'user': result[8],
|
|
||||||
'friendly_name': result[9],
|
|
||||||
'ip_address': result[10],
|
|
||||||
'player': result[11],
|
|
||||||
'platform': result[12],
|
|
||||||
'machine_id': result[13],
|
|
||||||
'parent_rating_key': result[14],
|
|
||||||
'grandparent_rating_key': result[15],
|
|
||||||
'state': result[16],
|
|
||||||
'view_offset': result[17],
|
|
||||||
'duration': result[18],
|
|
||||||
'video_decision': result[19],
|
|
||||||
'audio_decision': result[20],
|
|
||||||
'width': result[21],
|
|
||||||
'height': result[22],
|
|
||||||
'container': result[23],
|
|
||||||
'video_codec': result[24],
|
|
||||||
'audio_codec': result[25],
|
|
||||||
'bitrate': result[26],
|
|
||||||
'video_resolution': result[27],
|
|
||||||
'video_framerate': result[28],
|
|
||||||
'aspect_ratio': result[29],
|
|
||||||
'audio_channels': result[30],
|
|
||||||
'transcode_protocol': result[31],
|
|
||||||
'transcode_container': result[32],
|
|
||||||
'transcode_video_codec': result[33],
|
|
||||||
'transcode_audio_codec': result[34],
|
|
||||||
'transcode_audio_channels': result[35],
|
|
||||||
'transcode_width': result[36],
|
|
||||||
'transcode_height': result[37],
|
|
||||||
'paused_counter': result[38]
|
|
||||||
}
|
|
||||||
|
|
||||||
if any(d['session_key'] == str(stream['session_key']) and d['rating_key'] == str(stream['rating_key'])
|
if any(d['session_key'] == str(stream['session_key']) and d['rating_key'] == str(stream['rating_key'])
|
||||||
for d in media_container):
|
for d in media_container):
|
||||||
# The user's session is still active
|
# The user's session is still active
|
||||||
|
@ -111,7 +69,8 @@ def check_active_sessions():
|
||||||
[paused_counter, stream['session_key'], stream['rating_key']])
|
[paused_counter, stream['session_key'], stream['rating_key']])
|
||||||
# Check if the user has reached the offset in the media we defined as the "watched" percent
|
# Check if the user has reached the offset in the media we defined as the "watched" percent
|
||||||
if session['progress'] and session['duration']:
|
if session['progress'] and session['duration']:
|
||||||
if helpers.get_percent(session['progress'], session['duration']) > plexpy.CONFIG.NOTIFY_WATCHED_PERCENT:
|
if helpers.get_percent(session['progress'],
|
||||||
|
session['duration']) > plexpy.CONFIG.NOTIFY_WATCHED_PERCENT:
|
||||||
# Push any notifications -
|
# Push any notifications -
|
||||||
# Push it on it's own thread so we don't hold up our db actions
|
# Push it on it's own thread so we don't hold up our db actions
|
||||||
threading.Thread(target=notification_handler.notify,
|
threading.Thread(target=notification_handler.notify,
|
||||||
|
@ -126,7 +85,8 @@ def check_active_sessions():
|
||||||
|
|
||||||
# Check if the user has reached the offset in the media we defined as the "watched" percent
|
# Check if the user has reached the offset in the media we defined as the "watched" percent
|
||||||
if stream['view_offset'] and stream['duration']:
|
if stream['view_offset'] and stream['duration']:
|
||||||
if helpers.get_percent(stream['view_offset'], stream['duration']) > plexpy.CONFIG.NOTIFY_WATCHED_PERCENT:
|
if helpers.get_percent(stream['view_offset'],
|
||||||
|
stream['duration']) > plexpy.CONFIG.NOTIFY_WATCHED_PERCENT:
|
||||||
# Push any notifications -
|
# Push any notifications -
|
||||||
# Push it on it's own thread so we don't hold up our db actions
|
# Push it on it's own thread so we don't hold up our db actions
|
||||||
threading.Thread(target=notification_handler.notify,
|
threading.Thread(target=notification_handler.notify,
|
||||||
|
|
|
@ -152,16 +152,27 @@ def set_notify_state(session, state, agent_info):
|
||||||
logger.error('PlexPy Notifier :: Unable to set notify state.')
|
logger.error('PlexPy Notifier :: Unable to set notify state.')
|
||||||
|
|
||||||
def build_notify_text(session, state):
|
def build_notify_text(session, state):
|
||||||
from plexpy import pmsconnect
|
from plexpy import pmsconnect, helpers
|
||||||
|
|
||||||
# Get the server name
|
# Get the server name
|
||||||
pms_connect = pmsconnect.PmsConnect()
|
pms_connect = pmsconnect.PmsConnect()
|
||||||
server_name = pms_connect.get_server_pref(pref='FriendlyName')
|
server_name = pms_connect.get_server_pref(pref='FriendlyName')
|
||||||
|
|
||||||
|
# Get metadata feed for item
|
||||||
|
metadata = pms_connect.get_metadata_details(rating_key=session['rating_key'])
|
||||||
|
|
||||||
|
if metadata:
|
||||||
|
item_metadata = metadata['metadata']
|
||||||
|
else:
|
||||||
|
logger.error(u"PlexPy Notifier :: Unable to retrieve metadata for rating_key %s" % str(session['rating_key']))
|
||||||
|
return []
|
||||||
|
|
||||||
# Create a title
|
# Create a title
|
||||||
if session['media_type'] == 'episode':
|
if session['media_type'] == 'episode':
|
||||||
full_title = '%s - %s' % (session['grandparent_title'],
|
full_title = '%s - %s (%sx%s)' % (session['grandparent_title'],
|
||||||
session['title'])
|
session['title'],
|
||||||
|
item_metadata['parent_index'],
|
||||||
|
item_metadata['index'])
|
||||||
elif session['media_type'] == 'track':
|
elif session['media_type'] == 'track':
|
||||||
full_title = '%s - %s' % (session['grandparent_title'],
|
full_title = '%s - %s' % (session['grandparent_title'],
|
||||||
session['title'])
|
session['title'])
|
||||||
|
@ -174,13 +185,29 @@ def build_notify_text(session, state):
|
||||||
else:
|
else:
|
||||||
transcode_decision = 'A:%s' % session['audio_decision']
|
transcode_decision = 'A:%s' % session['audio_decision']
|
||||||
|
|
||||||
|
duration = helpers.convert_milliseconds_to_minutes(item_metadata['duration'])
|
||||||
|
view_offset = helpers.convert_milliseconds_to_minutes(session['view_offset'])
|
||||||
|
|
||||||
|
progress_percent = helpers.get_percent(view_offset, duration)
|
||||||
|
|
||||||
available_params = {'server_name': server_name,
|
available_params = {'server_name': server_name,
|
||||||
'user': session['friendly_name'],
|
'user': session['friendly_name'],
|
||||||
'player': session['player'],
|
'player': session['player'],
|
||||||
'title': full_title,
|
'title': full_title,
|
||||||
'platform': session['platform'],
|
'platform': session['platform'],
|
||||||
'media_type': session['media_type'],
|
'media_type': session['media_type'],
|
||||||
'transcode_decision': transcode_decision}
|
'transcode_decision': transcode_decision,
|
||||||
|
'year': item_metadata['year'],
|
||||||
|
'studio': item_metadata['studio'],
|
||||||
|
'content_rating': item_metadata['content_rating'],
|
||||||
|
'summary': item_metadata['summary'],
|
||||||
|
'season_num': item_metadata['parent_index'],
|
||||||
|
'episode_num': item_metadata['index'],
|
||||||
|
'rating': item_metadata['rating'],
|
||||||
|
'duration': duration,
|
||||||
|
'progress': view_offset,
|
||||||
|
'progress_percent': progress_percent
|
||||||
|
}
|
||||||
|
|
||||||
# Default subject text
|
# Default subject text
|
||||||
subject_text = 'PlexPy (%s)' % server_name
|
subject_text = 'PlexPy (%s)' % server_name
|
||||||
|
|
|
@ -287,7 +287,8 @@ def import_from_plexwatch(database=None, table_name=None, import_ignore_interval
|
||||||
|
|
||||||
# If we get back None from our xml extractor skip over the record and log error.
|
# If we get back None from our xml extractor skip over the record and log error.
|
||||||
if not extracted_xml:
|
if not extracted_xml:
|
||||||
logger.error(u"PlexPy Importer :: Skipping line due to malformed xml.")
|
logger.error(u"PlexPy Importer :: Skipping line with ratingKey %s due to malformed xml."
|
||||||
|
% str(row['rating_key']))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# If the user_id no longer exists in the friends list, pull it from the xml.
|
# If the user_id no longer exists in the friends list, pull it from the xml.
|
||||||
|
|
|
@ -251,7 +251,7 @@ class PmsConnect(object):
|
||||||
Output: array
|
Output: array
|
||||||
"""
|
"""
|
||||||
def get_metadata_details(self, rating_key=''):
|
def get_metadata_details(self, rating_key=''):
|
||||||
metadata = self.get_metadata(rating_key, output_format='xml')
|
metadata = self.get_metadata(str(rating_key), output_format='xml')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
xml_head = metadata.getElementsByTagName('MediaContainer')
|
xml_head = metadata.getElementsByTagName('MediaContainer')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue