mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-12 08:16:06 -07:00
Don't cache last watched or play count
This commit is contained in:
parent
4a65dc1d6e
commit
c0f0cb0d9e
3 changed files with 53 additions and 61 deletions
|
@ -281,7 +281,7 @@ $('#media_info_table').on('click', '> tbody > tr > td.expand-media-info a', func
|
||||||
|
|
||||||
// Initialize the detailed media info child table options using the parent table options
|
// Initialize the detailed media info child table options using the parent table options
|
||||||
function childTableOptionsMedia(rowData) {
|
function childTableOptionsMedia(rowData) {
|
||||||
switch (rowData['section_type']) {
|
switch (rowData['media_type']) {
|
||||||
case 'show':
|
case 'show':
|
||||||
section_type = 'season';
|
section_type = 'season';
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -197,7 +197,44 @@ class Libraries(object):
|
||||||
logger.warn(u"PlexPy Libraries :: Datatable media info called by invalid rating_key provided.")
|
logger.warn(u"PlexPy Libraries :: Datatable media info called by invalid rating_key provided.")
|
||||||
return default_return
|
return default_return
|
||||||
|
|
||||||
|
# Get the library details
|
||||||
|
library_details = self.get_details(section_id=section_id)
|
||||||
|
if library_details['section_id'] == None:
|
||||||
|
logger.debug(u"PlexPy Libraries :: Library section_id %s not found." % section_id)
|
||||||
|
return default_return
|
||||||
|
|
||||||
|
if not section_type:
|
||||||
|
section_type = library_details['section_type']
|
||||||
|
|
||||||
|
# Get play counts from the database
|
||||||
|
monitor_db = database.MonitorDatabase()
|
||||||
|
|
||||||
|
if section_type == 'show' or section_type == 'artist':
|
||||||
|
group_by = 'grandparent_rating_key'
|
||||||
|
elif section_type == 'season' or section_type == 'album':
|
||||||
|
group_by = 'parent_rating_key'
|
||||||
|
else:
|
||||||
|
group_by = 'rating_key'
|
||||||
|
|
||||||
|
try:
|
||||||
|
query = 'SELECT MAX(session_history.started) AS last_watched, COUNT(session_history.id) AS play_count, ' \
|
||||||
|
'session_history.rating_key, session_history.parent_rating_key, session_history.grandparent_rating_key ' \
|
||||||
|
'FROM session_history ' \
|
||||||
|
'JOIN session_history_metadata ON session_history.id = session_history_metadata.id ' \
|
||||||
|
'WHERE session_history_metadata.section_id = ? ' \
|
||||||
|
'GROUP BY session_history.%s ' % group_by
|
||||||
|
result = monitor_db.select(query, args=[section_id])
|
||||||
|
except Exception as e:
|
||||||
|
logger.warn(u"PlexPy Libraries :: Unable to execute database query for get_datatables_media_info2: %s." % e)
|
||||||
|
return default_return
|
||||||
|
|
||||||
|
watched_list = {}
|
||||||
|
for item in result:
|
||||||
|
watched_list[str(item[group_by])] = {'last_watched': item['last_watched'],
|
||||||
|
'play_count': item['play_count']}
|
||||||
|
|
||||||
rows = []
|
rows = []
|
||||||
|
# Import media info cache from json file
|
||||||
if rating_key:
|
if rating_key:
|
||||||
try:
|
try:
|
||||||
inFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info-%s_%s.json' % (section_id, rating_key))
|
inFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info-%s_%s.json' % (section_id, rating_key))
|
||||||
|
@ -219,47 +256,10 @@ class Libraries(object):
|
||||||
#logger.debug(u"PlexPy Libraries :: Refreshing data and creating new JSON file for section_id %s." % section_id)
|
#logger.debug(u"PlexPy Libraries :: Refreshing data and creating new JSON file for section_id %s." % section_id)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# If no cache was imported, get all library children items
|
||||||
if not rows:
|
if not rows:
|
||||||
# Get the library details
|
|
||||||
library_details = self.get_details(section_id=section_id)
|
|
||||||
if library_details['section_id'] == None:
|
|
||||||
logger.warn(u"PlexPy Libraries :: Library section_id %s not found." % section_id)
|
|
||||||
return default_return
|
|
||||||
|
|
||||||
if not section_type:
|
|
||||||
section_type = library_details['section_type']
|
|
||||||
|
|
||||||
# Get play counts from the database
|
|
||||||
monitor_db = database.MonitorDatabase()
|
|
||||||
|
|
||||||
if section_type == 'show' or section_type == 'artist':
|
|
||||||
group_by = 'grandparent_rating_key'
|
|
||||||
elif section_type == 'season' or section_type == 'album':
|
|
||||||
group_by = 'parent_rating_key'
|
|
||||||
else:
|
|
||||||
group_by = 'rating_key'
|
|
||||||
|
|
||||||
try:
|
|
||||||
query = 'SELECT MAX(session_history.started) AS last_watched, COUNT(session_history.id) AS play_count, ' \
|
|
||||||
'session_history.rating_key, session_history.parent_rating_key, session_history.grandparent_rating_key ' \
|
|
||||||
'FROM session_history ' \
|
|
||||||
'JOIN session_history_metadata ON session_history.id = session_history_metadata.id ' \
|
|
||||||
'WHERE session_history_metadata.section_id = ? ' \
|
|
||||||
'GROUP BY session_history.%s ' % group_by
|
|
||||||
result = monitor_db.select(query, args=[section_id])
|
|
||||||
except Exception as e:
|
|
||||||
logger.warn(u"PlexPy Libraries :: Unable to execute database query for get_datatables_media_info2: %s." % e)
|
|
||||||
return default_return
|
|
||||||
|
|
||||||
watched_list = {}
|
|
||||||
for item in result:
|
|
||||||
watched_list[str(item[group_by])] = {'last_watched': item['last_watched'],
|
|
||||||
'play_count': item['play_count']}
|
|
||||||
|
|
||||||
# Get all library children items
|
|
||||||
pms_connect = pmsconnect.PmsConnect()
|
pms_connect = pmsconnect.PmsConnect()
|
||||||
|
|
||||||
|
|
||||||
if rating_key:
|
if rating_key:
|
||||||
library_children = pms_connect.get_library_children(rating_key=rating_key,
|
library_children = pms_connect.get_library_children(rating_key=rating_key,
|
||||||
get_media_info=True)
|
get_media_info=True)
|
||||||
|
@ -277,14 +277,6 @@ class Libraries(object):
|
||||||
|
|
||||||
rows = []
|
rows = []
|
||||||
for item in children_list:
|
for item in children_list:
|
||||||
watched_item = watched_list.get(item['rating_key'], None)
|
|
||||||
if watched_item:
|
|
||||||
last_watched = watched_item['last_watched']
|
|
||||||
play_count = watched_item['play_count']
|
|
||||||
else:
|
|
||||||
last_watched = None
|
|
||||||
play_count = None
|
|
||||||
|
|
||||||
row = {'section_id': library_details['section_id'],
|
row = {'section_id': library_details['section_id'],
|
||||||
'section_type': library_details['section_type'],
|
'section_type': library_details['section_type'],
|
||||||
'added_at': item['added_at'],
|
'added_at': item['added_at'],
|
||||||
|
@ -304,15 +296,14 @@ class Libraries(object):
|
||||||
'video_framerate': item.get('video_framerate', ''),
|
'video_framerate': item.get('video_framerate', ''),
|
||||||
'audio_codec': item.get('audio_codec', ''),
|
'audio_codec': item.get('audio_codec', ''),
|
||||||
'audio_channels': item.get('audio_channels', ''),
|
'audio_channels': item.get('audio_channels', ''),
|
||||||
'file_size': item.get('file_size', ''),
|
'file_size': item.get('file_size', '')
|
||||||
'last_watched': last_watched,
|
|
||||||
'play_count': play_count
|
|
||||||
}
|
}
|
||||||
rows.append(row)
|
rows.append(row)
|
||||||
|
|
||||||
if not rows:
|
if not rows:
|
||||||
return default_return
|
return default_return
|
||||||
|
|
||||||
|
# Cache the media info to a json file
|
||||||
if rating_key:
|
if rating_key:
|
||||||
outFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info-%s_%s.json' % (section_id, rating_key))
|
outFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info-%s_%s.json' % (section_id, rating_key))
|
||||||
with open(outFilePath, 'w') as outFile:
|
with open(outFilePath, 'w') as outFile:
|
||||||
|
@ -322,6 +313,16 @@ class Libraries(object):
|
||||||
with open(outFilePath, 'w') as outFile:
|
with open(outFilePath, 'w') as outFile:
|
||||||
json.dump(rows, outFile)
|
json.dump(rows, outFile)
|
||||||
|
|
||||||
|
# Update the last_watched and play_count
|
||||||
|
for item in rows:
|
||||||
|
watched_item = watched_list.get(item['rating_key'], None)
|
||||||
|
if watched_item:
|
||||||
|
item['last_watched'] = watched_item['last_watched']
|
||||||
|
item['play_count'] = watched_item['play_count']
|
||||||
|
else:
|
||||||
|
item['last_watched'] = None
|
||||||
|
item['play_count'] = None
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
# Get datatables JSON data
|
# Get datatables JSON data
|
||||||
|
|
|
@ -352,15 +352,6 @@ class WebInterface(object):
|
||||||
logger.warn(u"Unable to retrieve data for get_library_recently_added.")
|
logger.warn(u"Unable to retrieve data for get_library_recently_added.")
|
||||||
return serve_template(templatename="library_recently_added.html", data=None, title="Recently Added")
|
return serve_template(templatename="library_recently_added.html", data=None, title="Recently Added")
|
||||||
|
|
||||||
@cherrypy.expose
|
|
||||||
def get_library_media_info(self, section_id=None, **kwargs):
|
|
||||||
|
|
||||||
library_data = libraries.Libraries()
|
|
||||||
result = library_data.get_datatables_media_info(section_id=section_id, kwargs=kwargs)
|
|
||||||
|
|
||||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
|
||||||
return json.dumps(result)
|
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def get_library_media_info(self, section_id=None, section_type=None, rating_key=None, **kwargs):
|
def get_library_media_info(self, section_id=None, section_type=None, rating_key=None, **kwargs):
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue