Merge pull request #278 from JonnyWong16/miscellaneous-fixes

Add IP address to current activity
This commit is contained in:
JonnyWong16 2015-11-12 06:13:08 -08:00
commit fcb3474312
8 changed files with 68 additions and 12 deletions

View file

@ -688,6 +688,14 @@ a:hover .dashboard-activity-poster {
white-space: nowrap;
width: 150px;
}
.dashboard-activity-poster-info-ip-address {
position: absolute;
bottom: 5px;
left: 10px;
text-align: left;
font-size: 12px;
color: #eee;
}
.dashboard-activity-poster-info-time {
position: absolute;
bottom: 5px;

View file

@ -32,6 +32,7 @@ user_thumb Returns the profile picture of the user owning the s
state Returns the state of the current session. Either 'playing', 'paused' or 'buffering'.
title Returns the name of the episode, movie or music track.
year Returns the year of the episode, movie, or clip.
ip_address Returns the ip address of the stream.
player Returns the name of the platform used to play the stream.
platform Returns the type of platform used to play the stream.
throttled Returns true if the transcode session is throttled.
@ -191,6 +192,13 @@ DOCUMENTATION :: END
</div>
% if a['media_type'] != 'photo':
<div class="dashboard-activity-poster-info-bar">
<div class="dashboard-activity-poster-info-ip-address">
% if a['ip_address']:
<span>IP: ${a['ip_address']}</span>
% else:
<span>IP: N/A</span>
% endif
</div>
<div class="dashboard-activity-poster-info-time">
<span class="progress_time">${a['view_offset']}</span>/<span class="progress_time">${a['duration']}</span>
</div>

View file

@ -435,7 +435,7 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
</label>
<span id="debugLogCheck" style="color: #eb8600; padding-left: 10px;"></span>
<p class="help-block">
Enable this to attempt to log the IP address of the user.
Enable this to attempt to log the IP address of the user (for PMS 0.9.12 and below, IP address is automatically logged for PMS 0.9.14 and above).
</p>
</div>
@ -882,13 +882,17 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
<td width="150"><strong>{player}</strong></td>
<td>The name of the device being used for playback.</td>
</tr>
<tr>
<td width="150"><strong>{ip_address}</strong></td>
<td>The IP address of the device being used for playback. (PMS 0.9.14 and above)</td>
</tr>
<tr>
<td width="150"><strong>{media_type}</strong></td>
<td>The type of media being played (movie, episode, track).</td>
</tr>
<tr>
<td width="150"><strong>{title}</strong></td>
<td>The title of the item being played.</td>
<td>The full title of the item being played.</td>
</tr>
<tr>
<td width="150"><strong>{show_name}</strong></td>
@ -906,6 +910,10 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
<td width="150"><strong>{album_name}</strong></td>
<td>The title of the album being played.</td>
</tr>
<tr>
<td width="150"><strong>{track_name}</strong></td>
<td>The title of the track being played.</td>
</tr>
<tr>
<td width="150"><strong>{season_num}</strong></td>
<td>The season number for the media item if item is episode.</td>

View file

@ -39,6 +39,7 @@ class ActivityProcessor(object):
'parent_title': session['parent_title'],
'grandparent_title': session['grandparent_title'],
'friendly_name': session['friendly_name'],
'ip_address': session['ip_address'],
'player': session['player'],
'platform': session['platform'],
'parent_rating_key': session['parent_rating_key'],
@ -78,16 +79,16 @@ class ActivityProcessor(object):
kwargs=dict(stream_data=values, notify_action='play')).start()
started = int(time.time())
timestamp = {'started': started}
# Try and grab IP address from logs
if plexpy.CONFIG.IP_LOGGING_ENABLE and plexpy.CONFIG.PMS_LOGS_FOLDER:
ip_address = self.find_session_ip(rating_key=session['rating_key'],
machine_id=session['machine_id'])
else:
ip_address = None
timestamp = {'started': started,
'ip_address': ip_address}
# Try and grab IP address from logs (fallback if not on PMS 0.9.14 and above)
if not session['ip_address']:
if plexpy.CONFIG.IP_LOGGING_ENABLE and plexpy.CONFIG.PMS_LOGS_FOLDER:
ip_address = self.find_session_ip(rating_key=session['rating_key'],
machine_id=session['machine_id'])
timestamp.update({'ip_address': ip_address})
else:
timestamp.update({'ip_address': None})
# If it's our first write then time stamp it.
self.db.upsert('sessions', timestamp, keys)

View file

@ -998,4 +998,20 @@ class DataFactory(object):
else:
return 'No updated rating key needed in database. No changes were made.'
# for debugging
#return mapping
#return mapping
def get_session_ip(self, session_key=''):
monitor_db = database.MonitorDatabase()
if session_key:
query = 'SELECT ip_address FROM sessions WHERE session_key = %d' % int(session_key)
result = monitor_db.select(query)
else:
return None
ip_address = 'N/A'
for item in result:
ip_address = item[0]
return ip_address

View file

@ -355,6 +355,7 @@ def build_notify_text(session=None, timeline=None, state=None):
user = ''
platform = ''
player = ''
ip_address = 'N/A'
# Session values
if session:
@ -383,6 +384,7 @@ def build_notify_text(session=None, timeline=None, state=None):
user = session['friendly_name']
platform = session['platform']
player = session['player']
ip_address = session['ip_address'] if session['ip_address'] != '' else 'N/A'
progress_percent = helpers.get_percent(view_offset, duration)
@ -390,12 +392,14 @@ def build_notify_text(session=None, timeline=None, state=None):
'user': user,
'platform': platform,
'player': player,
'ip_address': ip_address,
'media_type': metadata['media_type'],
'title': full_title,
'show_name': metadata['grandparent_title'],
'episode_name': metadata['title'],
'artist_name': metadata['grandparent_title'],
'album_name': metadata['parent_title'],
'track_name': metadata['title'],
'season_num': metadata['parent_index'],
'season_num00': metadata['parent_index'].zfill(2),
'episode_num': metadata['index'],

View file

@ -756,6 +756,7 @@ class PmsConnect(object):
'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'],
'user_thumb': user_details['thumb'],
'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address'),
'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'),
'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'),
'machine_id': machine_id,
@ -876,6 +877,7 @@ class PmsConnect(object):
'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'],
'user_thumb': user_details['thumb'],
'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address'),
'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'),
'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'),
'machine_id': machine_id,
@ -932,6 +934,7 @@ class PmsConnect(object):
'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'],
'user_thumb': user_details['thumb'],
'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address'),
'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'),
'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'),
'machine_id': machine_id,
@ -988,6 +991,7 @@ class PmsConnect(object):
'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'],
'user_thumb': user_details['thumb'],
'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address'),
'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'),
'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'),
'machine_id': machine_id,
@ -1077,6 +1081,7 @@ class PmsConnect(object):
'user_id': user_details['user_id'],
'friendly_name': user_details['friendly_name'],
'user_thumb': user_details['thumb'],
'ip_address': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'address'),
'player': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'title'),
'platform': helpers.get_xml_attr(session.getElementsByTagName('Player')[0], 'platform'),
'machine_id': machine_id,

View file

@ -711,6 +711,12 @@ class WebInterface(object):
try:
pms_connect = pmsconnect.PmsConnect()
result = pms_connect.get_current_activity()
data_factory = datafactory.DataFactory()
for session in result['sessions']:
if not session['ip_address']:
ip_address = data_factory.get_session_ip(session['session_key'])
session['ip_address'] = ip_address
except:
return serve_template(templatename="current_activity.html", data=None)