mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-06 05:01:14 -07:00
Add recently watched to user screen
This commit is contained in:
parent
6a026d510d
commit
fe6d5f17f0
5 changed files with 122 additions and 20 deletions
|
@ -51,7 +51,7 @@ A python based web front-end for plexWatch.
|
||||||
|
|
||||||
* full user list with general information and comparison stats
|
* full user list with general information and comparison stats
|
||||||
|
|
||||||
* individual user information **NOT YET IMPLEMENTED**
|
* individual user information **PARTIALLY IMPLEMENTED**
|
||||||
- username and gravatar (if available)
|
- username and gravatar (if available)
|
||||||
- daily, weekly, monthly, all time stats for play count and duration length
|
- daily, weekly, monthly, all time stats for play count and duration length
|
||||||
- individual platform stats for each user
|
- individual platform stats for each user
|
||||||
|
|
|
@ -189,6 +189,16 @@
|
||||||
<script src="interfaces/default/js/tables/user_ips.js"></script>
|
<script src="interfaces/default/js/tables/user_ips.js"></script>
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: 'get_user_recently_watched',
|
||||||
|
async: true,
|
||||||
|
data: { user: '${user}' },
|
||||||
|
complete: function(xhr, status) {
|
||||||
|
$("#user-recently-watched").html(xhr.responseText);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
history_table_options.ajax = {
|
history_table_options.ajax = {
|
||||||
"url": "get_history",
|
"url": "get_history",
|
||||||
"data": function(d) {
|
"data": function(d) {
|
||||||
|
@ -205,6 +215,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
user_ip_table = $('#user_ip_table').DataTable(user_ip_table_options);
|
user_ip_table = $('#user_ip_table').DataTable(user_ip_table_options);
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</%def>
|
</%def>
|
||||||
|
|
36
data/interfaces/default/user_recently_watched.html
Normal file
36
data/interfaces/default/user_recently_watched.html
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
% if recently_watched != None:
|
||||||
|
<div class="dashboard-recent-media-row">
|
||||||
|
<ul class="dashboard-recent-media">
|
||||||
|
% for item in recently_watched:
|
||||||
|
<div class="dashboard-recent-media-instance">
|
||||||
|
<li>
|
||||||
|
<div class="poster">
|
||||||
|
<div class="poster-face">
|
||||||
|
<a href="info?rating_key=${item['rating_key']}">
|
||||||
|
% if item['thumb'] != '':
|
||||||
|
<img src="pms_image_proxy?img=${item['thumb']}&width=153&height=225" class="poster-face">
|
||||||
|
% else:
|
||||||
|
<img src="interfaces/default/images/poster.png" class="poster-face">
|
||||||
|
% endif
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="dashboard-recent-media-metacontainer">
|
||||||
|
% if item['type'] == 'episode':
|
||||||
|
<h3>Season ${item['parentIndex']}, Episode ${item['index']}</h3>
|
||||||
|
% elif item['type'] == 'movie':
|
||||||
|
<h3>${item['title']} (${item['title']})</h3>
|
||||||
|
% endif
|
||||||
|
<div class="muted" id="time-${item['time']}">${item['time']}</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
$('#time-${item['time']}').html('Watched ' + moment(${item['time']}, "X").fromNow())
|
||||||
|
</script>
|
||||||
|
% endfor
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
% else:
|
||||||
|
<div class="muted">There was an error retrieving some data. Please check your <a href="config">settings</a>.</div><br>
|
||||||
|
% endif
|
|
@ -281,23 +281,6 @@ class PlexWatch(object):
|
||||||
|
|
||||||
return dict
|
return dict
|
||||||
|
|
||||||
def get_stream_details(self, id=0):
|
|
||||||
|
|
||||||
myDB = db.DBConnection()
|
|
||||||
|
|
||||||
query = 'SELECT xml from %s where id = %s' % (self.get_history_table_name(), id)
|
|
||||||
xml = myDB.select_single(query)
|
|
||||||
|
|
||||||
try:
|
|
||||||
dict_data = helpers.convert_xml_to_dict(helpers.latinToAscii(xml))
|
|
||||||
except IOError, e:
|
|
||||||
logger.warn("Error parsing XML in PlexWatch db: %s" % e)
|
|
||||||
|
|
||||||
dict = {'id': id,
|
|
||||||
'data': dict_data}
|
|
||||||
|
|
||||||
return dict
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Validate xml keys to make sure they exist and return their attribute value, return blank value is none found
|
Validate xml keys to make sure they exist and return their attribute value, return blank value is none found
|
||||||
"""
|
"""
|
||||||
|
@ -388,4 +371,52 @@ class PlexWatch(object):
|
||||||
'grandparent_title': grandparent_title
|
'grandparent_title': grandparent_title
|
||||||
}
|
}
|
||||||
|
|
||||||
return stream_output
|
return stream_output
|
||||||
|
|
||||||
|
def get_recently_watched(self, user=None, limit='10'):
|
||||||
|
myDB = db.DBConnection()
|
||||||
|
recently_watched = []
|
||||||
|
|
||||||
|
if not limit.isdigit():
|
||||||
|
limit = '10'
|
||||||
|
|
||||||
|
if user:
|
||||||
|
query = 'SELECT time, user, xml FROM %s WHERE user = "%s" ORDER BY time DESC LIMIT %s' % \
|
||||||
|
(self.get_user_table_name(), user, limit)
|
||||||
|
xml = myDB.select(query)
|
||||||
|
else:
|
||||||
|
query = 'SELECT time, user, xml FROM %s ORDER BY time DESC LIMIT %s' % \
|
||||||
|
(self.get_user_table_name(), limit)
|
||||||
|
xml = myDB.select(query)
|
||||||
|
|
||||||
|
for row in xml:
|
||||||
|
xml_data = helpers.latinToAscii(row[2])
|
||||||
|
try:
|
||||||
|
xml_parse = minidom.parseString(xml_data)
|
||||||
|
except:
|
||||||
|
logger.warn("Error parsing XML for Plex stream data.")
|
||||||
|
return None
|
||||||
|
|
||||||
|
xml_head = xml_parse.getElementsByTagName('opt')
|
||||||
|
if not xml_head:
|
||||||
|
logger.warn("Error parsing XML for Plex stream data.")
|
||||||
|
return None
|
||||||
|
|
||||||
|
for a in xml_head:
|
||||||
|
if self.get_xml_attr(a, 'type') == 'episode':
|
||||||
|
thumb = self.get_xml_attr(a, 'parentThumb')
|
||||||
|
else:
|
||||||
|
thumb = self.get_xml_attr(a, 'thumb')
|
||||||
|
|
||||||
|
recent_output = {'type': self.get_xml_attr(a, 'type'),
|
||||||
|
'rating_key': self.get_xml_attr(a, 'ratingKey'),
|
||||||
|
'title': self.get_xml_attr(a, 'title'),
|
||||||
|
'thumb': thumb,
|
||||||
|
'index': self.get_xml_attr(a, 'index'),
|
||||||
|
'parentIndex': self.get_xml_attr(a, 'parentIndex'),
|
||||||
|
'time': row[0],
|
||||||
|
'user': row[1]
|
||||||
|
}
|
||||||
|
recently_watched.append(recent_output)
|
||||||
|
|
||||||
|
return recently_watched
|
|
@ -534,6 +534,18 @@ class WebInterface(object):
|
||||||
return serve_template(templatename="info.html", metadata='', title="Info")
|
return serve_template(templatename="info.html", metadata='', title="Info")
|
||||||
logger.warn('Unable to retrieve data.')
|
logger.warn('Unable to retrieve data.')
|
||||||
|
|
||||||
|
@cherrypy.expose
|
||||||
|
def get_user_recently_watched(self, user=None, limit='10', **kwargs):
|
||||||
|
|
||||||
|
plex_watch = plexwatch.PlexWatch()
|
||||||
|
result = plex_watch.get_recently_watched(user, limit)
|
||||||
|
|
||||||
|
if result:
|
||||||
|
return serve_template(templatename="user_recently_watched.html", recently_watched=result, title="Recently Watched")
|
||||||
|
else:
|
||||||
|
return serve_template(templatename="user_recently_watched.html", metadata='', title="Recently Watched")
|
||||||
|
logger.warn('Unable to retrieve data.')
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def get_metadata_json(self, rating_key='', **kwargs):
|
def get_metadata_json(self, rating_key='', **kwargs):
|
||||||
|
|
||||||
|
@ -593,4 +605,16 @@ class WebInterface(object):
|
||||||
history = plex_watch.get_user_unique_ips(start, length, kwargs, custom_where)
|
history = plex_watch.get_user_unique_ips(start, length, kwargs, custom_where)
|
||||||
|
|
||||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||||
return json.dumps(history)
|
return json.dumps(history)
|
||||||
|
|
||||||
|
@cherrypy.expose
|
||||||
|
def get_watched(self, user=None, limit='10', **kwargs):
|
||||||
|
|
||||||
|
plex_watch = plexwatch.PlexWatch()
|
||||||
|
result = plex_watch.get_recently_watched(user, limit)
|
||||||
|
|
||||||
|
if result:
|
||||||
|
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||||
|
return json.dumps(result)
|
||||||
|
else:
|
||||||
|
logger.warn('Unable to retrieve data.')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue