From 8829516caec90a86c841f01a85cac5f1141d74ef Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Mon, 20 Jan 2020 19:23:16 -0800 Subject: [PATCH 1/4] Fix season 0 number not showing in tables --- data/interfaces/default/js/tables/history_table.js | 2 +- data/interfaces/default/js/tables/history_table_modal.js | 2 +- data/interfaces/default/js/tables/libraries.js | 2 +- data/interfaces/default/js/tables/user_ips.js | 2 +- data/interfaces/default/js/tables/users.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/data/interfaces/default/js/tables/history_table.js b/data/interfaces/default/js/tables/history_table.js index b605cdd2..60f55513 100644 --- a/data/interfaces/default/js/tables/history_table.js +++ b/data/interfaces/default/js/tables/history_table.js @@ -166,7 +166,7 @@ history_table_options = { thumb_popover = '' + cellData + parent_info + '' $(td).html('
' + media_type + ' ' + thumb_popover + '
'); } else if (rowData['media_type'] === 'episode') { - if (rowData['parent_media_index'] && rowData['media_index']) { parent_info = ' (S' + rowData['parent_media_index'] + ' · E' + rowData['media_index'] + ')'; } + if (!isNaN(parseInt(rowData['parent_media_index'])) && !isNaN(parseInt(rowData['media_index']))) { parent_info = ' (S' + rowData['parent_media_index'] + ' · E' + rowData['media_index'] + ')'; } media_type = ''; thumb_popover = '' + cellData + parent_info + '' $(td).html('
' + media_type + ' ' + thumb_popover + '
'); diff --git a/data/interfaces/default/js/tables/history_table_modal.js b/data/interfaces/default/js/tables/history_table_modal.js index 2ee57681..59d3357d 100644 --- a/data/interfaces/default/js/tables/history_table_modal.js +++ b/data/interfaces/default/js/tables/history_table_modal.js @@ -107,7 +107,7 @@ history_table_modal_options = { thumb_popover = '' + cellData + parent_info + '' $(td).html('
' + media_type + ' ' + thumb_popover + '
'); } else if (rowData['media_type'] === 'episode') { - if (rowData['parent_media_index'] && rowData['media_index']) { parent_info = ' (S' + rowData['parent_media_index'] + ' · E' + rowData['media_index'] + ')'; } + if (!isNaN(parseInt(rowData['parent_media_index'])) && !isNaN(parseInt(rowData['media_index']))) { parent_info = ' (S' + rowData['parent_media_index'] + ' · E' + rowData['media_index'] + ')'; } media_type = ''; thumb_popover = '' + cellData + parent_info + '' $(td).html('
' + media_type + ' ' + thumb_popover + '
'); diff --git a/data/interfaces/default/js/tables/libraries.js b/data/interfaces/default/js/tables/libraries.js index ee53b423..5c2c334d 100644 --- a/data/interfaces/default/js/tables/libraries.js +++ b/data/interfaces/default/js/tables/libraries.js @@ -153,7 +153,7 @@ libraries_list_table_options = { } else if (rowData['media_type'] === 'episode') { media_type = ''; if (rowData['rating_key']) { - if (rowData['parent_media_index'] && rowData['media_index']) { parent_info = ' (S' + rowData['parent_media_index'] + ' · E' + rowData['media_index'] + ')'; } + if (!isNaN(parseInt(rowData['parent_media_index'])) && !isNaN(parseInt(rowData['media_index']))) { parent_info = ' (S' + rowData['parent_media_index'] + ' · E' + rowData['media_index'] + ')'; } thumb_popover = '' + cellData + parent_info + '' $(td).html('
' + media_type + ' ' + thumb_popover + '
'); } else { diff --git a/data/interfaces/default/js/tables/user_ips.js b/data/interfaces/default/js/tables/user_ips.js index b1acac2a..046adc65 100644 --- a/data/interfaces/default/js/tables/user_ips.js +++ b/data/interfaces/default/js/tables/user_ips.js @@ -91,7 +91,7 @@ user_ip_table_options = { thumb_popover = '' + cellData + parent_info + '' $(td).html('
' + media_type + ' ' + thumb_popover + '
'); } else if (rowData['media_type'] === 'episode') { - if (rowData['parent_media_index'] && rowData['media_index']) { parent_info = ' (S' + rowData['parent_media_index'] + ' · E' + rowData['media_index'] + ')'; } + if (!isNaN(parseInt(rowData['parent_media_index'])) && !isNaN(parseInt(rowData['media_index']))) { parent_info = ' (S' + rowData['parent_media_index'] + ' · E' + rowData['media_index'] + ')'; } media_type = ''; thumb_popover = '' + cellData + parent_info + '' $(td).html('
' + media_type + ' ' + thumb_popover + '
'); diff --git a/data/interfaces/default/js/tables/users.js b/data/interfaces/default/js/tables/users.js index a97a78b8..bc9caf5b 100644 --- a/data/interfaces/default/js/tables/users.js +++ b/data/interfaces/default/js/tables/users.js @@ -166,7 +166,7 @@ users_list_table_options = { thumb_popover = '' + cellData + parent_info + '' $(td).html('
' + media_type + ' ' + thumb_popover + '
'); } else if (rowData['media_type'] === 'episode') { - if (rowData['parent_media_index'] && rowData['media_index']) { parent_info = ' (S' + rowData['parent_media_index'] + ' · E' + rowData['media_index'] + ')'; } + if (!isNaN(parseInt(rowData['parent_media_index'])) && !isNaN(parseInt(rowData['media_index']))) { parent_info = ' (S' + rowData['parent_media_index'] + ' · E' + rowData['media_index'] + ')'; } media_type = ''; thumb_popover = '' + cellData + parent_info + '' $(td).html('
' + media_type + ' ' + thumb_popover + '
'); From 8ef671c9cbac3df73250f1671e208a5773f14188 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Mon, 20 Jan 2020 19:56:38 -0800 Subject: [PATCH 2/4] Fix Telegram notification character limit (Closes #1361) --- plexpy/notifiers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py index adadc3f6..839178e5 100644 --- a/plexpy/notifiers.py +++ b/plexpy/notifiers.py @@ -3416,9 +3416,9 @@ class TELEGRAM(Notifier): data = {'chat_id': self.config['chat_id']} if self.config['incl_subject']: - text = subject.encode('utf-8') + '\r\n' + body.encode('utf-8') + text = subject + '\r\n' + body else: - text = body.encode('utf-8') + text = body if self.config['html_support']: data['parse_mode'] = 'HTML' @@ -3442,7 +3442,7 @@ class TELEGRAM(Notifier): if len(text) > 1024: data['disable_notification'] = True else: - data['caption'] = text + data['caption'] = text.encode('utf-8') r = self.make_request('https://api.telegram.org/bot{}/sendPhoto'.format(self.config['bot_token']), data=data, files=files) @@ -3450,7 +3450,7 @@ class TELEGRAM(Notifier): if not data.pop('disable_notification', None): return r - data['text'] = text + data['text'] = (text[:4093] + (text[4093:] and '...')).encode('utf-8') if self.config['disable_web_preview']: data['disable_web_page_preview'] = True From e90390be6776772446698639b3ea3559884dbab3 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Mon, 20 Jan 2020 20:08:45 -0800 Subject: [PATCH 3/4] Fix plural episodes and albums in newsletter templates (Fixes Tautulli/Tautulli-Issues#203) --- data/interfaces/newsletters/recently_added.html | 4 ++-- data/interfaces/newsletters/recently_added.internal.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/data/interfaces/newsletters/recently_added.html b/data/interfaces/newsletters/recently_added.html index c6f5fba1..f16e2c15 100644 --- a/data/interfaces/newsletters/recently_added.html +++ b/data/interfaces/newsletters/recently_added.html @@ -694,7 +694,7 @@
${len(recently_added['show'])} show${'s' if len(recently_added['show']) > 1 else ''} /  <% total_episodes = sum(season['episode_count'] for show in recently_added['show'] for season in show['season']) %> - ${total_episodes} episode${'s' if total > 1 else ''} + ${total_episodes} episode${'s' if total_episodes > 1 else ''}
@@ -847,7 +847,7 @@
${len(recently_added['artist'])} artist${'s' if len(recently_added['artist']) > 1 else ''} / <% total_albums = sum(artist['album_count'] for artist in recently_added['artist']) %> - ${total_albums} album${'s' if total > 1 else ''} + ${total_albums} album${'s' if total_albums > 1 else ''}
diff --git a/data/interfaces/newsletters/recently_added.internal.html b/data/interfaces/newsletters/recently_added.internal.html index 198ba49e..96e3e82e 100644 --- a/data/interfaces/newsletters/recently_added.internal.html +++ b/data/interfaces/newsletters/recently_added.internal.html @@ -694,7 +694,7 @@
${len(recently_added['show'])} show${'s' if len(recently_added['show']) > 1 else ''} /  <% total_episodes = sum(season['episode_count'] for show in recently_added['show'] for season in show['season']) %> - ${total_episodes} episode${'s' if total > 1 else ''} + ${total_episodes} episode${'s' if total_episodes > 1 else ''}
@@ -847,7 +847,7 @@
${len(recently_added['artist'])} artist${'s' if len(recently_added['artist']) > 1 else ''} / <% total_albums = sum(artist['album_count'] for artist in recently_added['artist']) %> - ${total_albums} album${'s' if total > 1 else ''} + ${total_albums} album${'s' if total_albums > 1 else ''}
From b9d5e49a711b9ecc1a750e90ad83ab3400cd6f0d Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Mon, 20 Jan 2020 20:49:37 -0800 Subject: [PATCH 4/4] Make verbose logging an advanced config option (Fixes Tautulli/Tautulli-Issues#205) * Verbose logging is enabled by default * Make toggleVerbose stick --- Tautulli.py | 4 ++-- plexpy/__init__.py | 5 ++++- plexpy/config.py | 1 + plexpy/webserve.py | 7 +++++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Tautulli.py b/Tautulli.py index 74a9789d..64a919eb 100755 --- a/Tautulli.py +++ b/Tautulli.py @@ -106,8 +106,8 @@ def main(): plexpy.QUIET = True # Do an intial setup of the logger. - logger.initLogger(console=not plexpy.QUIET, log_dir=False, - verbose=plexpy.VERBOSE) + # Require verbose for pre-initilization to see critical errors + logger.initLogger(console=not plexpy.QUIET, log_dir=False, verbose=True) try: plexpy.SYS_TIMEZONE = tzlocal.get_localzone() diff --git a/plexpy/__init__.py b/plexpy/__init__.py index ea41a3fc..73f7e63a 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -65,7 +65,7 @@ SYS_LANGUAGE = None SYS_ENCODING = None QUIET = False -VERBOSE = True +VERBOSE = False DAEMON = False CREATEPID = False PIDFILE = None @@ -122,6 +122,7 @@ def initialize(config_file): global CONFIG global CONFIG_FILE + global VERBOSE global _INITIALIZED global CURRENT_VERSION global LATEST_VERSION @@ -152,6 +153,8 @@ def initialize(config_file): if not log_writable and not QUIET: sys.stderr.write("Unable to create the log directory. Logging to screen only.\n") + VERBOSE = VERBOSE or bool(CONFIG.VERBOSE_LOGS) + # Start the logger, disable console if needed logger.initLogger(console=not QUIET, log_dir=CONFIG.LOG_DIR if log_writable else None, verbose=VERBOSE) diff --git a/plexpy/config.py b/plexpy/config.py index 469f3f47..42fb524a 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -603,6 +603,7 @@ _CONFIG_DEFINITIONS = { 'UPDATE_LABELS': (int, 'General', 1), 'UPDATE_LIBRARIES_DB_NOTIFY': (int, 'General', 1), 'UPDATE_NOTIFIERS_DB': (int, 'General', 1), + 'VERBOSE_LOGS': (int, 'Advanced', 1), 'VERIFY_SSL_CERT': (bool_int, 'Advanced', 1), 'VIDEO_LOGGING_ENABLE': (int, 'Monitoring', 1), 'WEBSOCKET_MONITOR_PING_PONG': (int, 'Advanced', 0), diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 7c82ef21..474e2122 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -2667,8 +2667,11 @@ class WebInterface(object): @requireAuth(member_of("admin")) def toggleVerbose(self, **kwargs): plexpy.VERBOSE = not plexpy.VERBOSE - logger.initLogger(console=not plexpy.QUIET, - log_dir=plexpy.CONFIG.LOG_DIR, verbose=plexpy.VERBOSE) + + plexpy.CONFIG.__setattr__('VERBOSE_LOGS', plexpy.VERBOSE) + plexpy.CONFIG.write() + + logger.initLogger(console=not plexpy.QUIET, log_dir=plexpy.CONFIG.LOG_DIR, verbose=plexpy.VERBOSE) logger.info(u"Verbose toggled, set to %s", plexpy.VERBOSE) logger.debug(u"If you read this message, debug logging is available") raise cherrypy.HTTPRedirect(plexpy.HTTP_ROOT + "logs")