mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 23:42:37 -07:00
Some code cleanup for libraries and users
This commit is contained in:
parent
85b3f081bf
commit
e38e98d9e7
5 changed files with 111 additions and 140 deletions
|
@ -37,7 +37,9 @@ DOCUMENTATION :: END
|
||||||
% if data:
|
% if data:
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
% if data['library_art']:
|
||||||
<div class="art-face" style="background-image:url(pms_image_proxy?img=${data['library_art']}&width=1920&height=1080)"></div>
|
<div class="art-face" style="background-image:url(pms_image_proxy?img=${data['library_art']}&width=1920&height=1080)"></div>
|
||||||
|
% endif
|
||||||
<div class="summary-container">
|
<div class="summary-container">
|
||||||
<div class="summary-navbar">
|
<div class="summary-navbar">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
|
@ -52,7 +54,7 @@ DOCUMENTATION :: END
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="table-card-back">
|
<div class="table-card-back">
|
||||||
<div class="user-info-wrapper">
|
<div class="user-info-wrapper">
|
||||||
% if data['library_thumb'][:4] == 'http':
|
% if data['library_thumb'][:4] == 'http' or data['library_thumb'][:10] == 'interfaces':
|
||||||
<div class="library-info-poster-face" style="background-image: url(${data['library_thumb']});"></div>
|
<div class="library-info-poster-face" style="background-image: url(${data['library_thumb']});"></div>
|
||||||
% else:
|
% else:
|
||||||
<div class="library-info-poster-face" style="background-image: url(pms_image_proxy?img=${data['library_thumb']}&width=80&height=80&fallback=cover);"></div>
|
<div class="library-info-poster-face" style="background-image: url(pms_image_proxy?img=${data['library_thumb']}&width=80&height=80&fallback=cover);"></div>
|
||||||
|
|
|
@ -91,6 +91,6 @@ DOCUMENTATION :: END
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
% else:
|
% else:
|
||||||
<div class="text-muted">Unable to retrieve data from database.
|
<div class="text-muted">No stats to show.
|
||||||
</div><br>
|
</div><br>
|
||||||
% endif
|
% endif
|
|
@ -540,51 +540,27 @@ class Libraries(object):
|
||||||
def get_details(self, section_id=None):
|
def get_details(self, section_id=None):
|
||||||
from plexpy import pmsconnect
|
from plexpy import pmsconnect
|
||||||
|
|
||||||
monitor_db = database.MonitorDatabase()
|
default_return = {'section_id': None,
|
||||||
|
'section_name': 'Local',
|
||||||
|
'section_type': '',
|
||||||
|
'library_thumb': common.DEFAULT_COVER_THUMB,
|
||||||
|
'library_art': '',
|
||||||
|
'count': 0,
|
||||||
|
'parent_count': 0,
|
||||||
|
'child_count': 0,
|
||||||
|
'do_notify': 0,
|
||||||
|
'do_notify_created': 0,
|
||||||
|
'keep_history': 0
|
||||||
|
}
|
||||||
|
|
||||||
try:
|
if not section_id:
|
||||||
if section_id:
|
return default_return
|
||||||
query = 'SELECT section_id, section_name, section_type, count, parent_count, child_count, ' \
|
|
||||||
'thumb AS library_thumb, custom_thumb_url AS custom_thumb, art, ' \
|
|
||||||
'do_notify, do_notify_created, keep_history ' \
|
|
||||||
'FROM library_sections ' \
|
|
||||||
'WHERE section_id = ? '
|
|
||||||
result = monitor_db.select(query, args=[section_id])
|
|
||||||
else:
|
|
||||||
result = []
|
|
||||||
except Exception as e:
|
|
||||||
logger.warn(u"PlexPy Libraries :: Unable to execute database query for get_details: %s." % e)
|
|
||||||
result = []
|
|
||||||
|
|
||||||
if result:
|
def get_library_details(section_id=section_id):
|
||||||
library_details = {}
|
monitor_db = database.MonitorDatabase()
|
||||||
for item in result:
|
|
||||||
if item['custom_thumb'] and item['custom_thumb'] != item['library_thumb']:
|
|
||||||
library_thumb = item['custom_thumb']
|
|
||||||
elif item['library_thumb']:
|
|
||||||
library_thumb = item['library_thumb']
|
|
||||||
else:
|
|
||||||
library_thumb = common.DEFAULT_COVER_THUMB
|
|
||||||
|
|
||||||
library_details = {'section_id': item['section_id'],
|
|
||||||
'section_name': item['section_name'],
|
|
||||||
'section_type': item['section_type'],
|
|
||||||
'library_thumb': library_thumb,
|
|
||||||
'library_art': item['art'],
|
|
||||||
'count': item['count'],
|
|
||||||
'parent_count': item['parent_count'],
|
|
||||||
'child_count': item['child_count'],
|
|
||||||
'do_notify': item['do_notify'],
|
|
||||||
'do_notify_created': item['do_notify_created'],
|
|
||||||
'keep_history': item['keep_history']
|
|
||||||
}
|
|
||||||
return library_details
|
|
||||||
else:
|
|
||||||
logger.warn(u"PlexPy Libraries :: Unable to retrieve library from local database. Requesting library list refresh.")
|
|
||||||
# Let's first refresh the libraries list to make sure the library isn't newly added and not in the db yet
|
|
||||||
pmsconnect.refresh_libraries()
|
|
||||||
try:
|
try:
|
||||||
if section_id:
|
if str(section_id).isdigit():
|
||||||
query = 'SELECT section_id, section_name, section_type, count, parent_count, child_count, ' \
|
query = 'SELECT section_id, section_name, section_type, count, parent_count, child_count, ' \
|
||||||
'thumb AS library_thumb, custom_thumb_url AS custom_thumb, art, ' \
|
'thumb AS library_thumb, custom_thumb_url AS custom_thumb, art, ' \
|
||||||
'do_notify, do_notify_created, keep_history ' \
|
'do_notify, do_notify_created, keep_history ' \
|
||||||
|
@ -593,12 +569,12 @@ class Libraries(object):
|
||||||
result = monitor_db.select(query, args=[section_id])
|
result = monitor_db.select(query, args=[section_id])
|
||||||
else:
|
else:
|
||||||
result = []
|
result = []
|
||||||
except:
|
except Exception as e:
|
||||||
logger.warn(u"PlexPy Libraries :: Unable to execute database query for get_details: %s." % e)
|
logger.warn(u"PlexPy Libraries :: Unable to execute database query for get_details: %s." % e)
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
|
library_details = {}
|
||||||
if result:
|
if result:
|
||||||
library_details = {}
|
|
||||||
for item in result:
|
for item in result:
|
||||||
if item['custom_thumb'] and item['custom_thumb'] != item['library_thumb']:
|
if item['custom_thumb'] and item['custom_thumb'] != item['library_thumb']:
|
||||||
library_thumb = item['custom_thumb']
|
library_thumb = item['custom_thumb']
|
||||||
|
@ -619,22 +595,28 @@ class Libraries(object):
|
||||||
'do_notify_created': item['do_notify_created'],
|
'do_notify_created': item['do_notify_created'],
|
||||||
'keep_history': item['keep_history']
|
'keep_history': item['keep_history']
|
||||||
}
|
}
|
||||||
|
return library_details
|
||||||
|
|
||||||
|
library_details = get_library_details(section_id=section_id)
|
||||||
|
|
||||||
|
if library_details:
|
||||||
|
return library_details
|
||||||
|
|
||||||
|
else:
|
||||||
|
logger.warn(u"PlexPy Libraries :: Unable to retrieve library from local database. Requesting library list refresh.")
|
||||||
|
# Let's first refresh the libraries list to make sure the library isn't newly added and not in the db yet
|
||||||
|
pmsconnect.refresh_libraries()
|
||||||
|
|
||||||
|
library_details = get_library_details(section_id=section_id)
|
||||||
|
|
||||||
|
if library_details:
|
||||||
return library_details
|
return library_details
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
logger.warn(u"PlexPy Users :: Unable to retrieve user from local database. Returning 'Local' library.")
|
||||||
# If there is no library data we must return something
|
# If there is no library data we must return something
|
||||||
# Use "Local" user to retain compatibility with PlexWatch database value
|
# Use "Local" library to retain compatibility with PlexWatch database value
|
||||||
return {'section_id': None,
|
return default_return
|
||||||
'section_name': 'Local',
|
|
||||||
'section_type': '',
|
|
||||||
'library_thumb': common.DEFAULT_COVER_THUMB,
|
|
||||||
'library_art': '',
|
|
||||||
'count': 0,
|
|
||||||
'parent_count': 0,
|
|
||||||
'child_count': 0,
|
|
||||||
'do_notify': 0,
|
|
||||||
'do_notify_created': 0,
|
|
||||||
'keep_history': 0
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_watch_time_stats(self, section_id=None):
|
def get_watch_time_stats(self, section_id=None):
|
||||||
monitor_db = database.MonitorDatabase()
|
monitor_db = database.MonitorDatabase()
|
||||||
|
|
|
@ -245,58 +245,24 @@ class Users(object):
|
||||||
def get_details(self, user_id=None, user=None):
|
def get_details(self, user_id=None, user=None):
|
||||||
from plexpy import plextv
|
from plexpy import plextv
|
||||||
|
|
||||||
monitor_db = database.MonitorDatabase()
|
default_return = {'user_id': None,
|
||||||
|
'username': 'Local',
|
||||||
try:
|
'friendly_name': 'Local',
|
||||||
if str(user_id).isdigit():
|
'user_thumb': common.DEFAULT_USER_THUMB,
|
||||||
query = 'SELECT user_id, username, friendly_name, thumb AS user_thumb, custom_avatar_url AS custom_thumb, ' \
|
'email': '',
|
||||||
'email, is_home_user, is_allow_sync, is_restricted, do_notify, keep_history ' \
|
'is_home_user': 0,
|
||||||
'FROM users ' \
|
'is_allow_sync': 0,
|
||||||
'WHERE user_id = ? '
|
'is_restricted': 0,
|
||||||
result = monitor_db.select(query, args=[user_id])
|
'do_notify': 0,
|
||||||
elif user:
|
'keep_history': 0
|
||||||
query = 'SELECT user_id, username, friendly_name, thumb AS user_thumb, custom_avatar_url AS custom_thumb, ' \
|
}
|
||||||
'email, is_home_user, is_allow_sync, is_restricted, do_notify, keep_history ' \
|
|
||||||
'FROM users ' \
|
|
||||||
'WHERE username = ? '
|
|
||||||
result = monitor_db.select(query, args=[user])
|
|
||||||
else:
|
|
||||||
result = []
|
|
||||||
except Exception as e:
|
|
||||||
logger.warn(u"PlexPy Users :: Unable to execute database query for get_details: %s." % e)
|
|
||||||
result = []
|
|
||||||
|
|
||||||
if result:
|
if not user_id and not user:
|
||||||
user_details = {}
|
return default_return
|
||||||
for item in result:
|
|
||||||
if item['friendly_name']:
|
|
||||||
friendly_name = item['friendly_name']
|
|
||||||
else:
|
|
||||||
friendly_name = item['username']
|
|
||||||
|
|
||||||
if item['custom_thumb'] and item['custom_thumb'] != item['user_thumb']:
|
def get_user_details(user_id=user_id, user=user):
|
||||||
user_thumb = item['custom_thumb']
|
monitor_db = database.MonitorDatabase()
|
||||||
elif item['user_thumb']:
|
|
||||||
user_thumb = item['user_thumb']
|
|
||||||
else:
|
|
||||||
user_thumb = common.DEFAULT_USER_THUMB
|
|
||||||
|
|
||||||
user_details = {'user_id': item['user_id'],
|
|
||||||
'username': item['username'],
|
|
||||||
'friendly_name': friendly_name,
|
|
||||||
'user_thumb': user_thumb,
|
|
||||||
'email': item['email'],
|
|
||||||
'is_home_user': item['is_home_user'],
|
|
||||||
'is_allow_sync': item['is_allow_sync'],
|
|
||||||
'is_restricted': item['is_restricted'],
|
|
||||||
'do_notify': item['do_notify'],
|
|
||||||
'keep_history': item['keep_history']
|
|
||||||
}
|
|
||||||
return user_details
|
|
||||||
else:
|
|
||||||
logger.warn(u"PlexPy Users :: Unable to retrieve user from local database. Requesting user list refresh.")
|
|
||||||
# Let's first refresh the user list to make sure the user isn't newly added and not in the db yet
|
|
||||||
plextv.refresh_users()
|
|
||||||
try:
|
try:
|
||||||
if str(user_id).isdigit():
|
if str(user_id).isdigit():
|
||||||
query = 'SELECT user_id, username, friendly_name, thumb AS user_thumb, custom_avatar_url AS custom_thumb, ' \
|
query = 'SELECT user_id, username, friendly_name, thumb AS user_thumb, custom_avatar_url AS custom_thumb, ' \
|
||||||
|
@ -316,8 +282,8 @@ class Users(object):
|
||||||
logger.warn(u"PlexPy Users :: Unable to execute database query for get_details: %s." % e)
|
logger.warn(u"PlexPy Users :: Unable to execute database query for get_details: %s." % e)
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
|
user_details = {}
|
||||||
if result:
|
if result:
|
||||||
user_details = {}
|
|
||||||
for item in result:
|
for item in result:
|
||||||
if item['friendly_name']:
|
if item['friendly_name']:
|
||||||
friendly_name = item['friendly_name']
|
friendly_name = item['friendly_name']
|
||||||
|
@ -342,21 +308,28 @@ class Users(object):
|
||||||
'do_notify': item['do_notify'],
|
'do_notify': item['do_notify'],
|
||||||
'keep_history': item['keep_history']
|
'keep_history': item['keep_history']
|
||||||
}
|
}
|
||||||
|
return user_details
|
||||||
|
|
||||||
|
user_details = get_user_details(user_id=user_id, user=user)
|
||||||
|
|
||||||
|
if user_details:
|
||||||
|
return user_details
|
||||||
|
|
||||||
|
else:
|
||||||
|
logger.warn(u"PlexPy Users :: Unable to retrieve user from local database. Requesting user list refresh.")
|
||||||
|
# Let's first refresh the user list to make sure the user isn't newly added and not in the db yet
|
||||||
|
plextv.refresh_users()
|
||||||
|
|
||||||
|
user_details = get_user_details(user_id=user_id, user=user)
|
||||||
|
|
||||||
|
if user_details:
|
||||||
return user_details
|
return user_details
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
logger.warn(u"PlexPy Users :: Unable to retrieve user from local database. Returning 'Local' user.")
|
||||||
# If there is no user data we must return something
|
# If there is no user data we must return something
|
||||||
# Use "Local" user to retain compatibility with PlexWatch database value
|
# Use "Local" user to retain compatibility with PlexWatch database value
|
||||||
return {'user_id': None,
|
return default_return
|
||||||
'username': 'Local',
|
|
||||||
'friendly_name': 'Local',
|
|
||||||
'user_thumb': common.DEFAULT_USER_THUMB,
|
|
||||||
'email': '',
|
|
||||||
'is_home_user': 0,
|
|
||||||
'is_allow_sync': 0,
|
|
||||||
'is_restricted': 0,
|
|
||||||
'do_notify': 0,
|
|
||||||
'keep_history': 0
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_watch_time_stats(self, user_id=None):
|
def get_watch_time_stats(self, user_id=None):
|
||||||
monitor_db = database.MonitorDatabase()
|
monitor_db = database.MonitorDatabase()
|
||||||
|
|
|
@ -363,9 +363,11 @@ class WebInterface(object):
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def get_library_watch_time_stats(self, section_id=None, **kwargs):
|
def get_library_watch_time_stats(self, section_id=None, **kwargs):
|
||||||
|
if section_id:
|
||||||
library_data = libraries.Libraries()
|
library_data = libraries.Libraries()
|
||||||
result = library_data.get_watch_time_stats(section_id=section_id)
|
result = library_data.get_watch_time_stats(section_id=section_id)
|
||||||
|
else:
|
||||||
|
result = None
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
return serve_template(templatename="user_watch_time_stats.html", data=result, title="Watch Stats")
|
return serve_template(templatename="user_watch_time_stats.html", data=result, title="Watch Stats")
|
||||||
|
@ -375,9 +377,11 @@ class WebInterface(object):
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def get_library_user_stats(self, section_id=None, **kwargs):
|
def get_library_user_stats(self, section_id=None, **kwargs):
|
||||||
|
if section_id:
|
||||||
library_data = libraries.Libraries()
|
library_data = libraries.Libraries()
|
||||||
result = library_data.get_user_stats(section_id=section_id)
|
result = library_data.get_user_stats(section_id=section_id)
|
||||||
|
else:
|
||||||
|
result = None
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
return serve_template(templatename="library_user_stats.html", data=result, title="Player Stats")
|
return serve_template(templatename="library_user_stats.html", data=result, title="Player Stats")
|
||||||
|
@ -387,9 +391,11 @@ class WebInterface(object):
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def get_library_recently_watched(self, section_id=None, limit='10', **kwargs):
|
def get_library_recently_watched(self, section_id=None, limit='10', **kwargs):
|
||||||
|
if section_id:
|
||||||
library_data = libraries.Libraries()
|
library_data = libraries.Libraries()
|
||||||
result = library_data.get_recently_watched(section_id=section_id, limit=limit)
|
result = library_data.get_recently_watched(section_id=section_id, limit=limit)
|
||||||
|
else:
|
||||||
|
result = None
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
return serve_template(templatename="user_recently_watched.html", data=result, title="Recently Watched")
|
return serve_template(templatename="user_recently_watched.html", data=result, title="Recently Watched")
|
||||||
|
@ -399,9 +405,11 @@ class WebInterface(object):
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def get_library_recently_added(self, section_id=None, limit='10', **kwargs):
|
def get_library_recently_added(self, section_id=None, limit='10', **kwargs):
|
||||||
|
if section_id:
|
||||||
pms_connect = pmsconnect.PmsConnect()
|
pms_connect = pmsconnect.PmsConnect()
|
||||||
result = pms_connect.get_recently_added_details(section_id=section_id, count=limit)
|
result = pms_connect.get_recently_added_details(section_id=section_id, count=limit)
|
||||||
|
else:
|
||||||
|
result = None
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
return serve_template(templatename="library_recently_added.html", data=result['recently_added'], title="Recently Added")
|
return serve_template(templatename="library_recently_added.html", data=result['recently_added'], title="Recently Added")
|
||||||
|
@ -628,9 +636,11 @@ class WebInterface(object):
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def get_user_watch_time_stats(self, user=None, user_id=None, **kwargs):
|
def get_user_watch_time_stats(self, user=None, user_id=None, **kwargs):
|
||||||
|
if users_id or user:
|
||||||
user_data = users.Users()
|
user_data = users.Users()
|
||||||
result = user_data.get_watch_time_stats(user_id=user_id)
|
result = user_data.get_watch_time_stats(user_id=user_id)
|
||||||
|
else:
|
||||||
|
result = None
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
return serve_template(templatename="user_watch_time_stats.html", data=result, title="Watch Stats")
|
return serve_template(templatename="user_watch_time_stats.html", data=result, title="Watch Stats")
|
||||||
|
@ -640,9 +650,11 @@ class WebInterface(object):
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def get_user_player_stats(self, user=None, user_id=None, **kwargs):
|
def get_user_player_stats(self, user=None, user_id=None, **kwargs):
|
||||||
|
if users_id or user:
|
||||||
user_data = users.Users()
|
user_data = users.Users()
|
||||||
result = user_data.get_player_stats(user_id=user_id)
|
result = user_data.get_player_stats(user_id=user_id)
|
||||||
|
else:
|
||||||
|
result = None
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
return serve_template(templatename="user_player_stats.html", data=result, title="Player Stats")
|
return serve_template(templatename="user_player_stats.html", data=result, title="Player Stats")
|
||||||
|
@ -652,9 +664,11 @@ class WebInterface(object):
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def get_user_recently_watched(self, user=None, user_id=None, limit='10', **kwargs):
|
def get_user_recently_watched(self, user=None, user_id=None, limit='10', **kwargs):
|
||||||
|
if users_id or user:
|
||||||
user_data = users.Users()
|
user_data = users.Users()
|
||||||
result = user_data.get_recently_watched(user_id=user_id, limit=limit)
|
result = user_data.get_recently_watched(user_id=user_id, limit=limit)
|
||||||
|
else:
|
||||||
|
result = None
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
return serve_template(templatename="user_recently_watched.html", data=result, title="Recently Watched")
|
return serve_template(templatename="user_recently_watched.html", data=result, title="Recently Watched")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue