Don't cache last watched or play count

This commit is contained in:
Jonathan Wong 2016-01-16 04:10:21 -08:00
parent 4a65dc1d6e
commit c0f0cb0d9e
3 changed files with 53 additions and 61 deletions

View file

@ -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
function childTableOptionsMedia(rowData) {
switch (rowData['section_type']) {
switch (rowData['media_type']) {
case 'show':
section_type = 'season';
break;

View file

@ -197,33 +197,10 @@ class Libraries(object):
logger.warn(u"PlexPy Libraries :: Datatable media info called by invalid rating_key provided.")
return default_return
rows = []
if rating_key:
try:
inFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info-%s_%s.json' % (section_id, rating_key))
with open(inFilePath, 'r') as inFile:
rows = json.load(inFile)
library_count = len(rows)
except IOError as e:
#logger.debug(u"PlexPy Libraries :: No JSON file for rating_key %s." % rating_key)
#logger.debug(u"PlexPy Libraries :: Refreshing data and creating new JSON file for rating_key %s." % rating_key)
pass
elif section_id:
try:
inFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info-%s.json' % section_id)
with open(inFilePath, 'r') as inFile:
rows = json.load(inFile)
library_count = len(rows)
except IOError as e:
#logger.debug(u"PlexPy Libraries :: No JSON file for library section_id %s." % section_id)
#logger.debug(u"PlexPy Libraries :: Refreshing data and creating new JSON file for section_id %s." % section_id)
pass
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)
logger.debug(u"PlexPy Libraries :: Library section_id %s not found." % section_id)
return default_return
if not section_type:
@ -256,9 +233,32 @@ class Libraries(object):
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()
rows = []
# Import media info cache from json file
if rating_key:
try:
inFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info-%s_%s.json' % (section_id, rating_key))
with open(inFilePath, 'r') as inFile:
rows = json.load(inFile)
library_count = len(rows)
except IOError as e:
#logger.debug(u"PlexPy Libraries :: No JSON file for rating_key %s." % rating_key)
#logger.debug(u"PlexPy Libraries :: Refreshing data and creating new JSON file for rating_key %s." % rating_key)
pass
elif section_id:
try:
inFilePath = os.path.join(plexpy.CONFIG.CACHE_DIR,'media_info-%s.json' % section_id)
with open(inFilePath, 'r') as inFile:
rows = json.load(inFile)
library_count = len(rows)
except IOError as e:
#logger.debug(u"PlexPy Libraries :: No JSON file for library section_id %s." % section_id)
#logger.debug(u"PlexPy Libraries :: Refreshing data and creating new JSON file for section_id %s." % section_id)
pass
# If no cache was imported, get all library children items
if not rows:
pms_connect = pmsconnect.PmsConnect()
if rating_key:
library_children = pms_connect.get_library_children(rating_key=rating_key,
@ -277,14 +277,6 @@ class Libraries(object):
rows = []
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'],
'section_type': library_details['section_type'],
'added_at': item['added_at'],
@ -304,15 +296,14 @@ class Libraries(object):
'video_framerate': item.get('video_framerate', ''),
'audio_codec': item.get('audio_codec', ''),
'audio_channels': item.get('audio_channels', ''),
'file_size': item.get('file_size', ''),
'last_watched': last_watched,
'play_count': play_count
'file_size': item.get('file_size', '')
}
rows.append(row)
if not rows:
return default_return
# Cache the media info to a json file
if 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:
@ -322,6 +313,16 @@ class Libraries(object):
with open(outFilePath, 'w') as 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 = []
# Get datatables JSON data

View file

@ -352,15 +352,6 @@ class WebInterface(object):
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")
@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
def get_library_media_info(self, section_id=None, section_type=None, rating_key=None, **kwargs):