diff --git a/data/interfaces/default/index.html b/data/interfaces/default/index.html index e18cfdf8..5f8caeba 100644 --- a/data/interfaces/default/index.html +++ b/data/interfaces/default/index.html @@ -29,6 +29,7 @@ % endif + % if config['home_library_cards'] > 'library_statistics':
@@ -40,6 +41,7 @@
+ % endif
diff --git a/data/interfaces/default/settings.html b/data/interfaces/default/settings.html index ee37f5fd..394c3d63 100644 --- a/data/interfaces/default/settings.html +++ b/data/interfaces/default/settings.html @@ -93,7 +93,7 @@ available_notification_agents = notifiers.available_notification_agents()
-

Select the cards to show in the watch statistics on the home page.

+

Select the cards to show in the watch statistics on the home page. Select none to disable.

+ + +
+
+

+
@@ -1215,6 +1232,34 @@ $(document).ready(function() { }).on('mousemove', function(e) { e.preventDefault() }); + + $.ajax({ + url: 'get_server_children', + data: { }, + async: true, + complete: function (xhr, status) { + server_children_info = $.parseJSON(xhr.responseText); + libraries_list = server_children_info.libraries_list; + for (var i in libraries_list) { + title = libraries_list[i].title; + key = libraries_list[i].key; + $('#home_library_cards').append('') + } + var cards = "${config['home_library_cards']}".split(/[\s,]+/); + cards.forEach(function (item) { + $('#card-'+item).prop('selected', !$(this).prop('selected')); + }); + } + }); + $('#home_library_cards').on('mousedown', function(e) { + e.preventDefault(); + var scroll = this.scrollTop; + e.target.selected = !e.target.selected; + this.scrollTop = scroll; + }).on('mousemove', function(e) { + e.preventDefault() + }); + }); diff --git a/plexpy/config.py b/plexpy/config.py index 7288ac34..c48a1858 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -82,10 +82,11 @@ _CONFIG_DEFINITIONS = { 'GROWL_ON_RESUME': (int, 'Growl', 0), 'GROWL_ON_BUFFER': (int, 'Growl', 0), 'GROWL_ON_WATCHED': (int, 'Growl', 0), + 'HOME_LIBRARY_CARDS': (str, 'General', 'library_statistics_first'), 'HOME_STATS_LENGTH': (int, 'General', 30), 'HOME_STATS_TYPE': (int, 'General', 0), 'HOME_STATS_COUNT': (int, 'General', 5), - 'HOME_STATS_CARDS': (str, 'General', 'top_tv, popular_tv, top_movies, popular_movies, top_music, popular_music, top_users, top_platforms, last_watched'), + 'HOME_STATS_CARDS': (str, 'General', 'watch_statistics_first'), 'HTTPS_CERT': (str, 'General', ''), 'HTTPS_KEY': (str, 'General', ''), 'HTTP_HOST': (str, 'General', '0.0.0.0'), diff --git a/plexpy/pmsconnect.py b/plexpy/pmsconnect.py index 25b23253..97b159e2 100644 --- a/plexpy/pmsconnect.py +++ b/plexpy/pmsconnect.py @@ -1208,7 +1208,7 @@ class PmsConnect(object): 'title': helpers.get_xml_attr(xml_head[0], 'title1'), 'libraries_list': libraries_list } - + return output """ @@ -1270,13 +1270,15 @@ class PmsConnect(object): return output """ - Return processed and validated server statistics. + Return processed and validated library statistics. Output: array """ - def get_library_stats(self): + def get_library_stats(self, library_cards=''): server_libraries = self.get_server_children() + library_keys = library_cards.split(', ') + server_library_stats = [] if server_libraries['libraries_count'] != '0': @@ -1285,7 +1287,10 @@ class PmsConnect(object): for library in libraries_list: library_type = library['type'] section_key = library['key'] - library_list = self.get_library_children(library_type, section_key) + if section_key in library_keys: + library_list = self.get_library_children(library_type, section_key) + else: + continue if library_list['library_count'] != '0': library_stats = {'title': library['title'], diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 42dd50e0..5bc15399 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -67,6 +67,7 @@ class WebInterface(object): config = { "home_stats_length": plexpy.CONFIG.HOME_STATS_LENGTH, "home_stats_cards": plexpy.CONFIG.HOME_STATS_CARDS, + "home_library_cards": plexpy.CONFIG.HOME_LIBRARY_CARDS, "pms_identifier": plexpy.CONFIG.PMS_IDENTIFIER } return serve_template(templatename="index.html", title="Home", config=config) @@ -140,7 +141,10 @@ class WebInterface(object): @cherrypy.expose def library_stats(self, **kwargs): pms_connect = pmsconnect.PmsConnect() - stats_data = pms_connect.get_library_stats() + + library_cards = plexpy.CONFIG.HOME_LIBRARY_CARDS + + stats_data = pms_connect.get_library_stats(library_cards=library_cards) return serve_template(templatename="library_stats.html", title="Library Stats", data=stats_data) @@ -479,6 +483,7 @@ class WebInterface(object): "home_stats_type": checked(plexpy.CONFIG.HOME_STATS_TYPE), "home_stats_count": plexpy.CONFIG.HOME_STATS_COUNT, "home_stats_cards": plexpy.CONFIG.HOME_STATS_CARDS, + "home_library_cards": plexpy.CONFIG.HOME_LIBRARY_CARDS, "buffer_threshold": plexpy.CONFIG.BUFFER_THRESHOLD, "buffer_wait": plexpy.CONFIG.BUFFER_WAIT } @@ -535,6 +540,10 @@ class WebInterface(object): if kwargs['home_stats_cards'] != 'watch_statistics': kwargs['home_stats_cards'] = ', '.join(kwargs['home_stats_cards']) + if 'home_library_cards' in kwargs: + if kwargs['home_library_cards'] != 'library_statistics': + kwargs['home_library_cards'] = ', '.join(kwargs['home_library_cards']) + plexpy.CONFIG.process_kwargs(kwargs) # Write the config @@ -1132,6 +1141,26 @@ class WebInterface(object): else: logger.warn('Unable to retrieve data.') + @cherrypy.expose + def get_server_children(self, **kwargs): + + pms_connect = pmsconnect.PmsConnect() + result = pms_connect.get_server_children() + + if plexpy.CONFIG.HOME_LIBRARY_CARDS == '': + library_keys = ['library_statistics'] + for library in result['libraries_list']: + library_keys.append(library['key']) + + plexpy.CONFIG.HOME_LIBRARY_CARDS = ', '.join(library_keys) + plexpy.CONFIG.write() + + if result: + cherrypy.response.headers['Content-type'] = 'application/json' + return json.dumps(result) + else: + logger.warn('Unable to retrieve data.') + @cherrypy.expose def get_activity(self, **kwargs):