From 4e959be84d9fab5f9d2d5f0217ac316742cc8c45 Mon Sep 17 00:00:00 2001 From: herby2212 Date: Mon, 1 Mar 2021 21:54:14 +0100 Subject: [PATCH 1/9] add most active libraries and total plays to home --- data/interfaces/default/home_stats.html | 8 +++-- data/interfaces/default/index.html | 4 +++ data/interfaces/default/library_stats.html | 13 +++++-- plexpy/config.py | 2 +- plexpy/datafactory.py | 42 +++++++++++++++++++++- 5 files changed, 62 insertions(+), 7 deletions(-) diff --git a/data/interfaces/default/home_stats.html b/data/interfaces/default/home_stats.html index 748199d7..1896b89d 100644 --- a/data/interfaces/default/home_stats.html +++ b/data/interfaces/default/home_stats.html @@ -25,7 +25,7 @@ grandparent_thumb Returns location of the item's thumbnail. Use with pms_i rating_key Returns the unique identifier for the media item. title Returns the title for the associated stat. -== Only if 'stat_id' is 'top_tv' or 'top_movies' or 'top_music' or 'top_user' or 'top_platform' == +== Only if 'stat_id' is 'top_tv' or 'top_movies' or 'top_music' or 'top_user' or 'top_platform' or 'top_libraries' == total_plays Returns the count for the associated stat. total_duration Returns the total duration for the associated stat. @@ -111,6 +111,8 @@ DOCUMENTATION :: END % elif stat_id == 'most_concurrent': + % elif stat_id == 'top_libraries': + % endif
@@ -133,7 +135,7 @@ DOCUMENTATION :: END % for row in top_stat['rows']:
  • ${loop.index + 1}
    @@ -159,6 +161,8 @@ DOCUMENTATION :: END ${row['platform']} % elif stat_id == 'most_concurrent': ${row['title']} + % elif stat_id == 'top_libraries': + ${row['library_name']} % endif
  • diff --git a/data/interfaces/default/index.html b/data/interfaces/default/index.html index e0f6fc73..1a82a3d1 100644 --- a/data/interfaces/default/index.html +++ b/data/interfaces/default/index.html @@ -810,6 +810,10 @@ $('#stats-background-' + stat_id).removeClass(function (index, className) { return (className.match (/(^|\s)platform-\S+/g) || []).join(' '); }).addClass('platform-' + $(elem).data('platform') + '-rgba'); + } else if (stat_id == 'top_libraries') { + $('#stats-thumb-' + stat_id).removeClass(function (index, className) { + return (className.match (/(^|\s)library-\S+/g) || []).join(' '); + }).addClass('library-' + $(elem).data('library-type')); } else { if (rating_key) { if (live) { diff --git a/data/interfaces/default/library_stats.html b/data/interfaces/default/library_stats.html index c5cfca92..cf821b25 100644 --- a/data/interfaces/default/library_stats.html +++ b/data/interfaces/default/library_stats.html @@ -19,6 +19,7 @@ thumb Returns the thumb of the library. count Returns the number of top level items in the library. parent_count Returns the number of parent items in the library. child_count Returns the number of child items in the library. +total_plays Returns the number of total plays of the library. DOCUMENTATION :: END @@ -28,9 +29,9 @@ DOCUMENTATION :: END from plexpy.helpers import page types = ('movie', 'show', 'artist', 'photo') - headers = {'movie': ('Movie Libraries', ('Movies', '', '')), - 'show': ('TV Show Libraries', ('Shows', 'Seasons', 'Episodes')), - 'artist': ('Music Libraries', ('Artists', 'Albums', 'Tracks')), + headers = {'movie': ('Movie Libraries', ('Movies', '', '', 'Total Plays')), + 'show': ('TV Show Libraries', ('Shows', 'Seasons', 'Episodes', 'Total Plays')), + 'artist': ('Music Libraries', ('Artists', 'Albums', 'Tracks', 'Total Plays')), 'photo': ('Photo Libraries', ('Albums', 'Photos', 'Videos'))} %> % for section_type in types: @@ -80,6 +81,12 @@ DOCUMENTATION :: END ${section['grandchild_count']}
    % endif + % if headers[section_type][1][3]: +
    /
    +
    + ${section['total_plays']} +
    + % endif % endfor diff --git a/plexpy/config.py b/plexpy/config.py index 2b4426dd..9bc4f9b6 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -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_users', 'top_platforms', 'most_concurrent', 'top_libraries']), 'HOME_REFRESH_INTERVAL': (int, 'General', 10), 'HTTPS_CREATE_CERT': (int, 'General', 1), 'HTTPS_CERT': (str, 'General', ''), diff --git a/plexpy/datafactory.py b/plexpy/datafactory.py index 901b9eb4..08d0b07d 100644 --- a/plexpy/datafactory.py +++ b/plexpy/datafactory.py @@ -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,39 @@ 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 ' \ + 'FROM library_sections' + + 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'], grouping=None , query_days=time_range) + + row = { + 'total_plays': library_item[0]['total_plays'], + 'total_duration': library_item[0]['total_time'], + 'type': item['section_type'], + 'library_name': item['section_name'] + } + + 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), mask_metadata=False) + }) + if stat_id and home_stats: return home_stats[0] return home_stats @@ -915,7 +950,11 @@ class DataFactory(object): logger.warn("Tautulli DataFactory :: Unable to execute database query for get_library_stats: %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'], grouping=None , query_days='0') + if item['custom_thumb'] and item['custom_thumb'] != item['library_thumb']: library_thumb = item['custom_thumb'] elif item['library_thumb']: @@ -935,7 +974,8 @@ class DataFactory(object): 'art': library_art, 'count': item['count'], 'child_count': item['parent_count'], - 'grandchild_count': item['child_count'] + 'grandchild_count': item['child_count'], + 'total_plays': library_item[0]['total_plays'] } library_stats.append(library) From 9fa72c64b8f419a93c2f9f5656475538ffce9d16 Mon Sep 17 00:00:00 2001 From: herby2212 Date: Tue, 2 Mar 2021 01:37:20 +0100 Subject: [PATCH 2/9] remove total plays from library statistics --- data/interfaces/default/library_stats.html | 13 +++---------- plexpy/datafactory.py | 7 +------ 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/data/interfaces/default/library_stats.html b/data/interfaces/default/library_stats.html index cf821b25..c5cfca92 100644 --- a/data/interfaces/default/library_stats.html +++ b/data/interfaces/default/library_stats.html @@ -19,7 +19,6 @@ thumb Returns the thumb of the library. count Returns the number of top level items in the library. parent_count Returns the number of parent items in the library. child_count Returns the number of child items in the library. -total_plays Returns the number of total plays of the library. DOCUMENTATION :: END @@ -29,9 +28,9 @@ DOCUMENTATION :: END from plexpy.helpers import page types = ('movie', 'show', 'artist', 'photo') - headers = {'movie': ('Movie Libraries', ('Movies', '', '', 'Total Plays')), - 'show': ('TV Show Libraries', ('Shows', 'Seasons', 'Episodes', 'Total Plays')), - 'artist': ('Music Libraries', ('Artists', 'Albums', 'Tracks', 'Total Plays')), + headers = {'movie': ('Movie Libraries', ('Movies', '', '')), + 'show': ('TV Show Libraries', ('Shows', 'Seasons', 'Episodes')), + 'artist': ('Music Libraries', ('Artists', 'Albums', 'Tracks')), 'photo': ('Photo Libraries', ('Albums', 'Photos', 'Videos'))} %> % for section_type in types: @@ -81,12 +80,6 @@ DOCUMENTATION :: END ${section['grandchild_count']}
    % endif - % if headers[section_type][1][3]: -
    /
    -
    - ${section['total_plays']} -
    - % endif % endfor diff --git a/plexpy/datafactory.py b/plexpy/datafactory.py index 08d0b07d..d4ec78c7 100644 --- a/plexpy/datafactory.py +++ b/plexpy/datafactory.py @@ -950,11 +950,7 @@ class DataFactory(object): logger.warn("Tautulli DataFactory :: Unable to execute database query for get_library_stats: %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'], grouping=None , query_days='0') - if item['custom_thumb'] and item['custom_thumb'] != item['library_thumb']: library_thumb = item['custom_thumb'] elif item['library_thumb']: @@ -974,8 +970,7 @@ class DataFactory(object): 'art': library_art, 'count': item['count'], 'child_count': item['parent_count'], - 'grandchild_count': item['child_count'], - 'total_plays': library_item[0]['total_plays'] + 'grandchild_count': item['child_count'] } library_stats.append(library) From a772fc0bcf4afc8b7e955adb78eabb9554ec29e2 Mon Sep 17 00:00:00 2001 From: herby2212 Date: Sun, 7 Mar 2021 02:54:28 +0100 Subject: [PATCH 3/9] naming, values, config und library link update --- data/interfaces/default/home_stats.html | 9 ++++++--- data/interfaces/default/settings.html | 6 ++++++ plexpy/config.py | 13 ++++++++++++- plexpy/datafactory.py | 26 +++++++++++++++++++++---- 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/data/interfaces/default/home_stats.html b/data/interfaces/default/home_stats.html index 1896b89d..f054cec9 100644 --- a/data/interfaces/default/home_stats.html +++ b/data/interfaces/default/home_stats.html @@ -112,7 +112,7 @@ DOCUMENTATION :: END % elif stat_id == 'most_concurrent': % elif stat_id == 'top_libraries': - + % endif
    @@ -135,7 +135,7 @@ DOCUMENTATION :: END % for row in top_stat['rows']:
  • ${loop.index + 1}
    @@ -162,7 +162,10 @@ DOCUMENTATION :: END % elif stat_id == 'most_concurrent': ${row['title']} % elif stat_id == 'top_libraries': - ${row['library_name']} + <% library_href = page('library', row['section_id']) %> + + ${row['section_name']} + % endif
  • diff --git a/data/interfaces/default/settings.html b/data/interfaces/default/settings.html index 3a60891a..bba0ebd7 100644 --- a/data/interfaces/default/settings.html +++ b/data/interfaces/default/settings.html @@ -403,6 +403,12 @@ Last Watched +
  • +
    + +