From 83c304290bea1e615b13eb7114d1765a537c0ca7 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Sun, 9 Oct 2016 16:37:01 -0700 Subject: [PATCH] Add PlexPy update notifications --- data/interfaces/default/settings.html | 51 +++++++++++++++++++++++++-- plexpy/__init__.py | 6 ++-- plexpy/common.py | 4 +-- plexpy/notification_handler.py | 15 ++++++++ plexpy/notifiers.py | 7 ++++ plexpy/version.py | 2 +- plexpy/versioncheck.py | 2 +- 7 files changed, 78 insertions(+), 9 deletions(-) diff --git a/data/interfaces/default/settings.html b/data/interfaces/default/settings.html index e9cbf05d..77f346a1 100644 --- a/data/interfaces/default/settings.html +++ b/data/interfaces/default/settings.html @@ -1333,6 +1333,18 @@ + + {plexpy_version} + The current version of PlexPy. + + + {plexpy_branch} + The current git branch of PlexPy. + + + {plexpy_commit} + The current git commit hash of PlexPy. + {server_name} The name of your Plex Server. @@ -1727,11 +1739,11 @@ {update_url} - The available update download URL. + The download URL for the available update. {update_release_date} - The release date of the update version. + The release date of the available update. {update_channel} @@ -1767,6 +1779,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ PlexPy Update Available +
{plexpy_update_version}The available update version for PlexPy.
{plexpy_update_tar}The tar download URL for the available update.
{plexpy_update_zip}The zip download URL for the available update.
{plexpy_update_commit}The commit hash for the available update.
{plexpy_update_behind}The number of commits behind for the available update.
{plexpy_update_changelog}The changelog for the available update.
diff --git a/plexpy/__init__.py b/plexpy/__init__.py index ad78751b..12f90db5 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -503,17 +503,17 @@ def dbcheck(): 'on_resume INTEGER DEFAULT 0, on_buffer INTEGER DEFAULT 0, on_watched INTEGER DEFAULT 0, ' 'on_created INTEGER DEFAULT 0, on_extdown INTEGER DEFAULT 0, on_intdown INTEGER DEFAULT 0, ' 'on_extup INTEGER DEFAULT 0, on_intup INTEGER DEFAULT 0, on_pmsupdate INTEGER DEFAULT 0, ' - 'on_concurrent INTEGER DEFAULT 0, on_newdevice INTEGER DEFAULT 0, ' + 'on_concurrent INTEGER DEFAULT 0, on_newdevice INTEGER DEFAULT 0, on_plexpyupdate INTEGER DEFAULT 0, ' 'on_play_subject TEXT, on_stop_subject TEXT, on_pause_subject TEXT, ' 'on_resume_subject TEXT, on_buffer_subject TEXT, on_watched_subject TEXT, ' 'on_created_subject TEXT, on_extdown_subject TEXT, on_intdown_subject TEXT, ' 'on_extup_subject TEXT, on_intup_subject TEXT, on_pmsupdate_subject TEXT, ' - 'on_concurrent_subject TEXT, on_newdevice_subject TEXT, ' + 'on_concurrent_subject TEXT, on_newdevice_subject TEXT, on_plexpyupdate TEXT, ' 'on_play_body TEXT, on_stop_body TEXT, on_pause_body TEXT, ' 'on_resume_body TEXT, on_buffer_body TEXT, on_watched_body TEXT, ' 'on_created_body TEXT, on_extdown_body TEXT, on_intdown_body TEXT, ' 'on_extup_body TEXT, on_intup_body TEXT, on_pmsupdate_body TEXT, ' - 'on_concurrent_body TEXT, on_newdevice_body TEXT)' + 'on_concurrent_body TEXT, on_newdevice_body TEXT, on_plexpyupdate_body TEXT)' ) # Upgrade sessions table from earlier versions diff --git a/plexpy/common.py b/plexpy/common.py index 6d734c0c..029e4f9c 100644 --- a/plexpy/common.py +++ b/plexpy/common.py @@ -23,12 +23,12 @@ import platform import version # Identify Our Application -USER_AGENT = 'PlexPy/-' + version.PLEXPY_VERSION + ' v' + version.PLEXPY_RELEASE_VERSION + ' (' + platform.system() + \ +USER_AGENT = 'PlexPy/-' + version.PLEXPY_BRANCH + ' v' + version.PLEXPY_RELEASE_VERSION + ' (' + platform.system() + \ ' ' + platform.release() + ')' PLATFORM = platform.system() PLATFORM_VERSION = platform.release() -BRANCH = version.PLEXPY_VERSION +BRANCH = version.PLEXPY_BRANCH VERSION_NUMBER = version.PLEXPY_RELEASE_VERSION DEFAULT_USER_THUMB = "interfaces/default/images/gravatar-default-80x80.png" diff --git a/plexpy/notification_handler.py b/plexpy/notification_handler.py index dc482534..7266f6b5 100644 --- a/plexpy/notification_handler.py +++ b/plexpy/notification_handler.py @@ -25,6 +25,7 @@ import time import plexpy import activity_processor +import common import database import datafactory import libraries @@ -451,6 +452,9 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, * pass available_params = {# Global paramaters + 'plexpy_version': common.VERSION_NUMBER, + 'plexpy_branch': plexpy.CONFIG.GIT_BRANCH, + 'plexpy_commit': plexpy.CURRENT_VERSION, 'server_name': server_name, 'server_uptime': server_uptime, 'server_version': server_times.get('version',''), @@ -563,6 +567,7 @@ def build_server_notify_params(notify_action=None, **kwargs): server_times = plex_tv.get_server_times() pms_download_info = kwargs.pop('pms_download_info', {}) + plexpy_download_info = kwargs.pop('plexpy_download_info', {}) if server_times: updated_at = server_times['updated_at'] @@ -572,6 +577,9 @@ def build_server_notify_params(notify_action=None, **kwargs): server_uptime = 'N/A' available_params = {# Global paramaters + 'plexpy_version': common.VERSION_NUMBER, + 'plexpy_branch': plexpy.CONFIG.GIT_BRANCH, + 'plexpy_commit': plexpy.CURRENT_VERSION, 'server_name': server_name, 'server_uptime': server_uptime, 'server_version': server_times.get('version',''), @@ -591,6 +599,13 @@ def build_server_notify_params(notify_action=None, **kwargs): 'update_extra_info': pms_download_info.get('extra_info',''), 'update_changelog_added': pms_download_info.get('changelog_added',''), 'update_changelog_fixed': pms_download_info.get('changelog_fixed',''), + # PlexPy update parameters + 'plexpy_update_version': plexpy_download_info.get('tag_name', ''), + 'plexpy_update_tar': plexpy_download_info.get('tarball_url', ''), + 'plexpy_update_zip': plexpy_download_info.get('zipball_url', ''), + 'plexpy_update_commit': kwargs.pop('plexpy_update_commit', ''), + 'plexpy_update_behind': kwargs.pop('plexpy_update_behind', ''), + 'plexpy_update_changelog': plexpy_download_info.get('body', '') } return available_params, None diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py index fcccb20a..b52959da 100644 --- a/plexpy/notifiers.py +++ b/plexpy/notifiers.py @@ -256,6 +256,13 @@ def available_notification_actions(): 'subject': 'PlexPy ({server_name})', 'body': 'An update is available for the Plex Media Server (version {update_version}).', 'icon': 'fa-refresh' + }, + {'label': 'PlexPy Update Available', + 'name': 'on_plexpyupdate', + 'description': 'Trigger a notification when an update for the PlexPy is available.', + 'subject': 'PlexPy ({server_name})', + 'body': 'An update is available for PlexPy (version {plexpy_update_version}).', + 'icon': 'fa-refresh' } ] diff --git a/plexpy/version.py b/plexpy/version.py index 8af7df98..46bfabca 100644 --- a/plexpy/version.py +++ b/plexpy/version.py @@ -1,2 +1,2 @@ -PLEXPY_VERSION = "master" +PLEXPY_BRANCH = "master" PLEXPY_RELEASE_VERSION = "1.4.15" diff --git a/plexpy/versioncheck.py b/plexpy/versioncheck.py index 65f1cbbd..2c78d68c 100644 --- a/plexpy/versioncheck.py +++ b/plexpy/versioncheck.py @@ -65,7 +65,7 @@ def runGit(args): def getVersion(): - if version.PLEXPY_VERSION.startswith('win32build'): + if version.PLEXPY_BRANCH.startswith('win32build'): plexpy.INSTALL_TYPE = 'win' # Don't have a way to update exe yet, but don't want to set VERSION to None