+
+ If a value for a selected parameter cannot be provided nothing will be outputted for it.
+
@@ -594,7 +597,44 @@
Returns the transcode decisions for the media item. |
- More options will be added soon. |
+ {year} |
+ Returns the release year for the media item. |
+
+
+ {studio} |
+ Returns the studio for the media item. |
+
+
+ {content_rating} |
+ Returns the content rating for the media item. E.g. TV-MA, TV-PG, etc. |
+
+
+ {summary} |
+ Returns the a short plot summary for the media item. |
+
+
+ {season_num} |
+ Returns the season number for the media item if item is episode. |
+
+
+ {episode_num} |
+ Returns the episode number for the media item if item is episode. |
+
+
+ {rating} |
+ Returns the rating (out of 10) for the item. |
+
+
+ {duration} |
+ Returns the duration (in minutes) for the item. |
+
+
+ {progress} |
+ Returns the last reported offset (in minutes) for the item. |
+
+
+ {progress_percent} |
+ Returns the last reported progress percent for the item. |
diff --git a/plexpy/helpers.py b/plexpy/helpers.py
index f864ebc2..f81cbd84 100644
--- a/plexpy/helpers.py
+++ b/plexpy/helpers.py
@@ -99,7 +99,7 @@ def latinToAscii(unicrap):
pass
else:
r += str(i)
- return r.encode('utf-8')
+ return r
def convert_milliseconds(ms):
@@ -115,7 +115,7 @@ def convert_milliseconds(ms):
def convert_milliseconds_to_minutes(ms):
- if ms.isdigit():
+ if str(ms).isdigit():
seconds = float(ms) / 1000
minutes = round(seconds / 60, 0)
diff --git a/plexpy/monitor.py b/plexpy/monitor.py
index fd662d94..af6b9e34 100644
--- a/plexpy/monitor.py
+++ b/plexpy/monitor.py
@@ -44,49 +44,7 @@ def check_active_sessions():
'transcode_container, transcode_video_codec, transcode_audio_codec, '
'transcode_audio_channels, transcode_width, transcode_height, paused_counter '
'FROM sessions')
- for result 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]
- }
-
+ for stream in db_streams:
if any(d['session_key'] == str(stream['session_key']) and d['rating_key'] == str(stream['rating_key'])
for d in media_container):
# The user's session is still active
@@ -111,7 +69,8 @@ def check_active_sessions():
[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
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 it on it's own thread so we don't hold up our db actions
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
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 it on it's own thread so we don't hold up our db actions
threading.Thread(target=notification_handler.notify,
diff --git a/plexpy/notification_handler.py b/plexpy/notification_handler.py
index ffcbe37d..7ff39e0e 100644
--- a/plexpy/notification_handler.py
+++ b/plexpy/notification_handler.py
@@ -152,16 +152,27 @@ def set_notify_state(session, state, agent_info):
logger.error('PlexPy Notifier :: Unable to set notify state.')
def build_notify_text(session, state):
- from plexpy import pmsconnect
+ from plexpy import pmsconnect, helpers
# Get the server name
pms_connect = pmsconnect.PmsConnect()
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
if session['media_type'] == 'episode':
- full_title = '%s - %s' % (session['grandparent_title'],
- session['title'])
+ full_title = '%s - %s (%sx%s)' % (session['grandparent_title'],
+ session['title'],
+ item_metadata['parent_index'],
+ item_metadata['index'])
elif session['media_type'] == 'track':
full_title = '%s - %s' % (session['grandparent_title'],
session['title'])
@@ -174,13 +185,29 @@ def build_notify_text(session, state):
else:
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,
'user': session['friendly_name'],
'player': session['player'],
'title': full_title,
'platform': session['platform'],
'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
subject_text = 'PlexPy (%s)' % server_name
diff --git a/plexpy/plexwatch_import.py b/plexpy/plexwatch_import.py
index a7ac2859..c37a8893 100644
--- a/plexpy/plexwatch_import.py
+++ b/plexpy/plexwatch_import.py
@@ -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 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
# If the user_id no longer exists in the friends list, pull it from the xml.
diff --git a/plexpy/pmsconnect.py b/plexpy/pmsconnect.py
index 063682f0..3e360b7f 100644
--- a/plexpy/pmsconnect.py
+++ b/plexpy/pmsconnect.py
@@ -251,7 +251,7 @@ class PmsConnect(object):
Output: array
"""
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:
xml_head = metadata.getElementsByTagName('MediaContainer')