Merge pull request #1389 from herby2212/nightly

Add most active libraries card and total plays to home stats
This commit is contained in:
JonnyWong16 2021-03-15 12:03:55 -07:00 committed by GitHub
commit 3dd9dfa48b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 105 additions and 4 deletions

View file

@ -114,7 +114,7 @@ _CONFIG_DEFINITIONS = {
'HOME_SECTIONS': (list, 'General', ['current_activity', 'watch_stats', 'library_stats', 'recently_added']),
'HOME_LIBRARY_CARDS': (list, 'General', ['first_run']),
'HOME_STATS_CARDS': (list, 'General', ['top_movies', 'popular_movies', 'top_tv', 'popular_tv', 'top_music',
'popular_music', 'last_watched', 'top_users', 'top_platforms', 'most_concurrent']),
'popular_music', 'last_watched', 'top_libraries', 'top_users', 'top_platforms', 'most_concurrent']),
'HOME_REFRESH_INTERVAL': (int, 'General', 10),
'HTTPS_CREATE_CERT': (int, 'General', 1),
'HTTPS_CERT': (str, 'General', ''),
@ -546,3 +546,15 @@ class Config(object):
self.PLEXPY_AUTO_UPDATE = 0
self.CONFIG_VERSION = 17
if self.CONFIG_VERSION == 17:
home_stats_cards = self.HOME_STATS_CARDS
if 'top_users' in home_stats_cards:
top_users_index = home_stats_cards.index('top_users')
home_stats_cards.insert(top_users_index, 'top_libraries')
else:
home_stats_cards.add('top_libaries')
self.HOME_STATS_CARDS = home_stats_cards
self.CONFIG_VERSION = 18

View file

@ -29,11 +29,13 @@ if plexpy.PYTHON2:
import common
import database
import datatables
import libraries
import helpers
import logger
import pmsconnect
import session
else:
from plexpy import libraries
from plexpy import common
from plexpy import database
from plexpy import datatables
@ -888,6 +890,63 @@ class DataFactory(object):
'stat_title': 'Most Concurrent Streams',
'rows': most_concurrent})
elif stat == 'top_libraries':
top_libraries = []
try:
query = 'SELECT section_id, section_name, section_type, thumb AS library_thumb, ' \
'custom_thumb_url AS custom_thumb, art AS library_art, custom_art_url AS custom_art ' \
'FROM library_sections ' \
'WHERE deleted_section = 0'
result = monitor_db.select(query)
except Exception as e:
logger.warn("Tautulli DataFactory :: Unable to execute database query for get_home_stats: top_libraries: %s." % e)
return None
library_data = libraries.Libraries()
for item in result:
library_item = library_data.get_watch_time_stats(section_id=item['section_id'],
query_days=time_range)
if not library_item or library_item[0]['total_plays'] == 0 and library_item[0]['total_time'] == 0:
continue
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']
row = {
'total_plays': library_item[0]['total_plays'],
'total_duration': library_item[0]['total_time'],
'section_type': item['section_type'],
'section_name': item['section_name'],
'section_id': item['section_id'],
'last_play': '',
'thumb': library_thumb,
'art': library_art
}
top_libraries.append(row)
home_stats.append({
'stat_id': stat,
'stat_type': sort_type,
'stat_title': 'Most Active Libraries',
'rows': session.mask_session_info(
sorted(top_libraries, key=lambda k: k[sort_type], reverse=True)[:10],
mask_metadata=False)
})
if stat_id and home_stats:
return home_stats[0]
return home_stats

View file

@ -4665,7 +4665,7 @@ class WebInterface(object):
else:
img = '/library/metadata/{}/thumb'.format(rating_key)
if img:
if img and not img.startswith('http'):
parts = 5
if img.startswith('/playlists'):
parts -= 1