mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 15:56:07 -07:00
Reorganize get user/library details
This commit is contained in:
parent
1ff6a54d70
commit
7ebed4ffd7
2 changed files with 134 additions and 131 deletions
|
@ -796,59 +796,7 @@ class Libraries(object):
|
||||||
if server_id is None:
|
if server_id is None:
|
||||||
server_id = plexpy.CONFIG.PMS_IDENTIFIER
|
server_id = plexpy.CONFIG.PMS_IDENTIFIER
|
||||||
|
|
||||||
def get_library_details(section_id=section_id, server_id=server_id):
|
library_details = self.get_library_details(section_id=section_id, server_id=server_id)
|
||||||
monitor_db = database.MonitorDatabase()
|
|
||||||
|
|
||||||
try:
|
|
||||||
if str(section_id).isdigit():
|
|
||||||
query = 'SELECT id AS row_id, server_id, section_id, section_name, section_type, ' \
|
|
||||||
'count, parent_count, child_count, ' \
|
|
||||||
'thumb AS library_thumb, custom_thumb_url AS custom_thumb, art AS library_art, ' \
|
|
||||||
'custom_art_url AS custom_art, is_active, ' \
|
|
||||||
'do_notify, do_notify_created, keep_history, deleted_section ' \
|
|
||||||
'FROM library_sections ' \
|
|
||||||
'WHERE section_id = ? AND server_id = ? '
|
|
||||||
result = monitor_db.select(query, args=[section_id, server_id])
|
|
||||||
else:
|
|
||||||
result = []
|
|
||||||
except Exception as e:
|
|
||||||
logger.warn("Tautulli Libraries :: Unable to execute database query for get_details: %s." % e)
|
|
||||||
result = []
|
|
||||||
|
|
||||||
library_details = {}
|
|
||||||
if result:
|
|
||||||
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
|
|
||||||
|
|
||||||
if item['custom_art'] and item['custom_art'] != item['library_art']:
|
|
||||||
library_art = item['custom_art']
|
|
||||||
else:
|
|
||||||
library_art = item['library_art']
|
|
||||||
|
|
||||||
library_details = {'row_id': item['row_id'],
|
|
||||||
'server_id': item['server_id'],
|
|
||||||
'section_id': item['section_id'],
|
|
||||||
'section_name': item['section_name'],
|
|
||||||
'section_type': item['section_type'],
|
|
||||||
'library_thumb': library_thumb,
|
|
||||||
'library_art': library_art,
|
|
||||||
'count': item['count'],
|
|
||||||
'parent_count': item['parent_count'],
|
|
||||||
'child_count': item['child_count'],
|
|
||||||
'is_active': item['is_active'],
|
|
||||||
'do_notify': item['do_notify'],
|
|
||||||
'do_notify_created': item['do_notify_created'],
|
|
||||||
'keep_history': item['keep_history'],
|
|
||||||
'deleted_section': item['deleted_section']
|
|
||||||
}
|
|
||||||
return library_details
|
|
||||||
|
|
||||||
library_details = get_library_details(section_id=section_id, server_id=server_id)
|
|
||||||
|
|
||||||
if library_details:
|
if library_details:
|
||||||
return library_details
|
return library_details
|
||||||
|
@ -859,7 +807,7 @@ class Libraries(object):
|
||||||
# Let's first refresh the libraries list to make sure the library isn't newly added and not in the db yet
|
# Let's first refresh the libraries list to make sure the library isn't newly added and not in the db yet
|
||||||
refresh_libraries()
|
refresh_libraries()
|
||||||
|
|
||||||
library_details = get_library_details(section_id=section_id, server_id=server_id)
|
library_details = self.get_library_details(section_id=section_id, server_id=server_id)
|
||||||
|
|
||||||
if library_details:
|
if library_details:
|
||||||
return library_details
|
return library_details
|
||||||
|
@ -870,6 +818,61 @@ class Libraries(object):
|
||||||
# If there is no library data we must return something
|
# If there is no library data we must return something
|
||||||
return default_return
|
return default_return
|
||||||
|
|
||||||
|
def get_library_details(self, section_id=None, server_id=None):
|
||||||
|
if server_id is None:
|
||||||
|
server_id = plexpy.CONFIG.PMS_IDENTIFIER
|
||||||
|
|
||||||
|
monitor_db = database.MonitorDatabase()
|
||||||
|
|
||||||
|
try:
|
||||||
|
if str(section_id).isdigit():
|
||||||
|
query = 'SELECT id AS row_id, server_id, section_id, section_name, section_type, ' \
|
||||||
|
'count, parent_count, child_count, ' \
|
||||||
|
'thumb AS library_thumb, custom_thumb_url AS custom_thumb, art AS library_art, ' \
|
||||||
|
'custom_art_url AS custom_art, is_active, ' \
|
||||||
|
'do_notify, do_notify_created, keep_history, deleted_section ' \
|
||||||
|
'FROM library_sections ' \
|
||||||
|
'WHERE section_id = ? AND server_id = ? '
|
||||||
|
result = monitor_db.select(query, args=[section_id, server_id])
|
||||||
|
else:
|
||||||
|
result = []
|
||||||
|
except Exception as e:
|
||||||
|
logger.warn("Tautulli Libraries :: Unable to execute database query for get_details: %s." % e)
|
||||||
|
result = []
|
||||||
|
|
||||||
|
library_details = {}
|
||||||
|
if result:
|
||||||
|
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
|
||||||
|
|
||||||
|
if item['custom_art'] and item['custom_art'] != item['library_art']:
|
||||||
|
library_art = item['custom_art']
|
||||||
|
else:
|
||||||
|
library_art = item['library_art']
|
||||||
|
|
||||||
|
library_details = {'row_id': item['row_id'],
|
||||||
|
'server_id': item['server_id'],
|
||||||
|
'section_id': item['section_id'],
|
||||||
|
'section_name': item['section_name'],
|
||||||
|
'section_type': item['section_type'],
|
||||||
|
'library_thumb': library_thumb,
|
||||||
|
'library_art': library_art,
|
||||||
|
'count': item['count'],
|
||||||
|
'parent_count': item['parent_count'],
|
||||||
|
'child_count': item['child_count'],
|
||||||
|
'is_active': item['is_active'],
|
||||||
|
'do_notify': item['do_notify'],
|
||||||
|
'do_notify_created': item['do_notify_created'],
|
||||||
|
'keep_history': item['keep_history'],
|
||||||
|
'deleted_section': item['deleted_section']
|
||||||
|
}
|
||||||
|
return library_details
|
||||||
|
|
||||||
def get_watch_time_stats(self, section_id=None, grouping=None, query_days=None):
|
def get_watch_time_stats(self, section_id=None, grouping=None, query_days=None):
|
||||||
if not session.allow_session_library(section_id):
|
if not session.allow_session_library(section_id):
|
||||||
return []
|
return []
|
||||||
|
|
154
plexpy/users.py
154
plexpy/users.py
|
@ -381,82 +381,7 @@ class Users(object):
|
||||||
if user_id is None and not user and not email:
|
if user_id is None and not user and not email:
|
||||||
return default_return
|
return default_return
|
||||||
|
|
||||||
def get_user_details(user_id=user_id, user=user, email=email):
|
user_details = self.get_user_details(user_id=user_id, user=user, email=email)
|
||||||
monitor_db = database.MonitorDatabase()
|
|
||||||
|
|
||||||
try:
|
|
||||||
if str(user_id).isdigit():
|
|
||||||
query = 'SELECT id AS row_id, user_id, username, friendly_name, ' \
|
|
||||||
'thumb AS user_thumb, custom_avatar_url AS custom_thumb, ' \
|
|
||||||
'email, is_active, is_admin, is_home_user, is_allow_sync, is_restricted, ' \
|
|
||||||
'do_notify, keep_history, deleted_user, ' \
|
|
||||||
'allow_guest, shared_libraries ' \
|
|
||||||
'FROM users ' \
|
|
||||||
'WHERE user_id = ? '
|
|
||||||
result = monitor_db.select(query, args=[user_id])
|
|
||||||
elif user:
|
|
||||||
query = 'SELECT id AS row_id, user_id, username, friendly_name, ' \
|
|
||||||
'thumb AS user_thumb, custom_avatar_url AS custom_thumb, ' \
|
|
||||||
'email, is_active, is_admin, is_home_user, is_allow_sync, is_restricted, ' \
|
|
||||||
'do_notify, keep_history, deleted_user, ' \
|
|
||||||
'allow_guest, shared_libraries ' \
|
|
||||||
'FROM users ' \
|
|
||||||
'WHERE username = ? COLLATE NOCASE '
|
|
||||||
result = monitor_db.select(query, args=[user])
|
|
||||||
elif email:
|
|
||||||
query = 'SELECT id AS row_id, user_id, username, friendly_name, ' \
|
|
||||||
'thumb AS user_thumb, custom_avatar_url AS custom_thumb, ' \
|
|
||||||
'email, is_active, is_admin, is_home_user, is_allow_sync, is_restricted, ' \
|
|
||||||
'do_notify, keep_history, deleted_user, ' \
|
|
||||||
'allow_guest, shared_libraries ' \
|
|
||||||
'FROM users ' \
|
|
||||||
'WHERE email = ? COLLATE NOCASE '
|
|
||||||
result = monitor_db.select(query, args=[email])
|
|
||||||
else:
|
|
||||||
result = []
|
|
||||||
except Exception as e:
|
|
||||||
logger.warn("Tautulli Users :: Unable to execute database query for get_details: %s." % e)
|
|
||||||
result = []
|
|
||||||
|
|
||||||
user_details = {}
|
|
||||||
if result:
|
|
||||||
for item in result:
|
|
||||||
if session.get_session_user_id():
|
|
||||||
friendly_name = session.get_session_user()
|
|
||||||
elif item['friendly_name']:
|
|
||||||
friendly_name = item['friendly_name']
|
|
||||||
else:
|
|
||||||
friendly_name = item['username']
|
|
||||||
|
|
||||||
if item['custom_thumb'] and item['custom_thumb'] != item['user_thumb']:
|
|
||||||
user_thumb = item['custom_thumb']
|
|
||||||
elif item['user_thumb']:
|
|
||||||
user_thumb = item['user_thumb']
|
|
||||||
else:
|
|
||||||
user_thumb = common.DEFAULT_USER_THUMB
|
|
||||||
|
|
||||||
shared_libraries = tuple(item['shared_libraries'].split(';')) if item['shared_libraries'] else ()
|
|
||||||
|
|
||||||
user_details = {'row_id': item['row_id'],
|
|
||||||
'user_id': item['user_id'],
|
|
||||||
'username': item['username'],
|
|
||||||
'friendly_name': friendly_name,
|
|
||||||
'user_thumb': user_thumb,
|
|
||||||
'email': item['email'],
|
|
||||||
'is_active': item['is_active'],
|
|
||||||
'is_admin': item['is_admin'],
|
|
||||||
'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'],
|
|
||||||
'deleted_user': item['deleted_user'],
|
|
||||||
'allow_guest': item['allow_guest'],
|
|
||||||
'shared_libraries': shared_libraries
|
|
||||||
}
|
|
||||||
return user_details
|
|
||||||
|
|
||||||
user_details = get_user_details(user_id=user_id, user=user)
|
|
||||||
|
|
||||||
if user_details:
|
if user_details:
|
||||||
return user_details
|
return user_details
|
||||||
|
@ -467,7 +392,7 @@ class Users(object):
|
||||||
# Let's first refresh the user list to make sure the user isn't newly added and not in the db yet
|
# Let's first refresh the user list to make sure the user isn't newly added and not in the db yet
|
||||||
refresh_users()
|
refresh_users()
|
||||||
|
|
||||||
user_details = get_user_details(user_id=user_id, user=user)
|
user_details = self.get_user_details(user_id=user_id, user=user, email=email)
|
||||||
|
|
||||||
if user_details:
|
if user_details:
|
||||||
return user_details
|
return user_details
|
||||||
|
@ -479,6 +404,81 @@ class Users(object):
|
||||||
# Use "Local" user to retain compatibility with PlexWatch database value
|
# Use "Local" user to retain compatibility with PlexWatch database value
|
||||||
return default_return
|
return default_return
|
||||||
|
|
||||||
|
def get_user_details(self, user_id=None, user=None, email=None):
|
||||||
|
monitor_db = database.MonitorDatabase()
|
||||||
|
|
||||||
|
try:
|
||||||
|
if str(user_id).isdigit():
|
||||||
|
query = 'SELECT id AS row_id, user_id, username, friendly_name, ' \
|
||||||
|
'thumb AS user_thumb, custom_avatar_url AS custom_thumb, ' \
|
||||||
|
'email, is_active, is_admin, is_home_user, is_allow_sync, is_restricted, ' \
|
||||||
|
'do_notify, keep_history, deleted_user, ' \
|
||||||
|
'allow_guest, shared_libraries ' \
|
||||||
|
'FROM users ' \
|
||||||
|
'WHERE user_id = ? '
|
||||||
|
result = monitor_db.select(query, args=[user_id])
|
||||||
|
elif user:
|
||||||
|
query = 'SELECT id AS row_id, user_id, username, friendly_name, ' \
|
||||||
|
'thumb AS user_thumb, custom_avatar_url AS custom_thumb, ' \
|
||||||
|
'email, is_active, is_admin, is_home_user, is_allow_sync, is_restricted, ' \
|
||||||
|
'do_notify, keep_history, deleted_user, ' \
|
||||||
|
'allow_guest, shared_libraries ' \
|
||||||
|
'FROM users ' \
|
||||||
|
'WHERE username = ? COLLATE NOCASE '
|
||||||
|
result = monitor_db.select(query, args=[user])
|
||||||
|
elif email:
|
||||||
|
query = 'SELECT id AS row_id, user_id, username, friendly_name, ' \
|
||||||
|
'thumb AS user_thumb, custom_avatar_url AS custom_thumb, ' \
|
||||||
|
'email, is_active, is_admin, is_home_user, is_allow_sync, is_restricted, ' \
|
||||||
|
'do_notify, keep_history, deleted_user, ' \
|
||||||
|
'allow_guest, shared_libraries ' \
|
||||||
|
'FROM users ' \
|
||||||
|
'WHERE email = ? COLLATE NOCASE '
|
||||||
|
result = monitor_db.select(query, args=[email])
|
||||||
|
else:
|
||||||
|
result = []
|
||||||
|
except Exception as e:
|
||||||
|
logger.warn("Tautulli Users :: Unable to execute database query for get_details: %s." % e)
|
||||||
|
result = []
|
||||||
|
|
||||||
|
user_details = {}
|
||||||
|
if result:
|
||||||
|
for item in result:
|
||||||
|
if session.get_session_user_id():
|
||||||
|
friendly_name = session.get_session_user()
|
||||||
|
elif item['friendly_name']:
|
||||||
|
friendly_name = item['friendly_name']
|
||||||
|
else:
|
||||||
|
friendly_name = item['username']
|
||||||
|
|
||||||
|
if item['custom_thumb'] and item['custom_thumb'] != item['user_thumb']:
|
||||||
|
user_thumb = item['custom_thumb']
|
||||||
|
elif item['user_thumb']:
|
||||||
|
user_thumb = item['user_thumb']
|
||||||
|
else:
|
||||||
|
user_thumb = common.DEFAULT_USER_THUMB
|
||||||
|
|
||||||
|
shared_libraries = tuple(item['shared_libraries'].split(';')) if item['shared_libraries'] else ()
|
||||||
|
|
||||||
|
user_details = {'row_id': item['row_id'],
|
||||||
|
'user_id': item['user_id'],
|
||||||
|
'username': item['username'],
|
||||||
|
'friendly_name': friendly_name,
|
||||||
|
'user_thumb': user_thumb,
|
||||||
|
'email': item['email'],
|
||||||
|
'is_active': item['is_active'],
|
||||||
|
'is_admin': item['is_admin'],
|
||||||
|
'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'],
|
||||||
|
'deleted_user': item['deleted_user'],
|
||||||
|
'allow_guest': item['allow_guest'],
|
||||||
|
'shared_libraries': shared_libraries
|
||||||
|
}
|
||||||
|
return user_details
|
||||||
|
|
||||||
def get_watch_time_stats(self, user_id=None, grouping=None, query_days=None):
|
def get_watch_time_stats(self, user_id=None, grouping=None, query_days=None):
|
||||||
if not session.allow_session_user(user_id):
|
if not session.allow_session_user(user_id):
|
||||||
return []
|
return []
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue