diff --git a/plexpy/__init__.py b/plexpy/__init__.py
index 12f90db5..31d85cd1 100644
--- a/plexpy/__init__.py
+++ b/plexpy/__init__.py
@@ -297,7 +297,7 @@ def initialize_scheduler():
github_minutes = CONFIG.CHECK_GITHUB_INTERVAL if CONFIG.CHECK_GITHUB_INTERVAL and CONFIG.CHECK_GITHUB else 0
schedule_job(versioncheck.checkGithub, 'Check GitHub for updates',
- hours=0, minutes=github_minutes, seconds=0)
+ hours=0, minutes=github_minutes, seconds=0, args=(bool(CONFIG.PLEXPY_AUTO_UPDATE),))
backup_hours = CONFIG.BACKUP_INTERVAL if 1 <= CONFIG.BACKUP_INTERVAL <= 24 else 6
diff --git a/plexpy/config.py b/plexpy/config.py
index b35b94d3..682fc075 100644
--- a/plexpy/config.py
+++ b/plexpy/config.py
@@ -384,6 +384,7 @@ _CONFIG_DEFINITIONS = {
'PLEX_ON_PMSUPDATE': (int, 'Plex', 0),
'PLEX_ON_CONCURRENT': (int, 'Plex', 0),
'PLEX_ON_NEWDEVICE': (int, 'Plex', 0),
+ 'PLEXPY_AUTO_UPDATE': (int, 'General', 0),
'PROWL_ENABLED': (int, 'Prowl', 0),
'PROWL_KEYS': (str, 'Prowl', ''),
'PROWL_PRIORITY': (int, 'Prowl', 0),
diff --git a/plexpy/versioncheck.py b/plexpy/versioncheck.py
index 2c78d68c..3f9c1e70 100644
--- a/plexpy/versioncheck.py
+++ b/plexpy/versioncheck.py
@@ -120,7 +120,7 @@ def getVersion():
return None, 'master'
-def checkGithub():
+def checkGithub(auto_update=False):
plexpy.COMMITS_BEHIND = 0
# Get the latest version available from github
@@ -163,6 +163,16 @@ def checkGithub():
if plexpy.COMMITS_BEHIND > 0:
logger.info('New version is available. You are %s commits behind' % plexpy.COMMITS_BEHIND)
+
+ url = 'https://api.github.com/repos/%s/plexpy/releases/latest' % plexpy.CONFIG.GIT_USER
+ release = request.request_json(url, timeout=20, whitelist_status_code=404, validator=lambda x: type(x) == dict)
+ plexpy.NOTIFY_QUEUE.put({'notify_action': 'on_plexpyupdate', 'plexpy_download_info': release,
+ 'plexpy_update_commit': plexpy.LATEST_VERSION, 'plexpy_update_behind': plexpy.COMMITS_BEHIND})
+
+ if auto_update:
+ logger.info('Running automatic update.')
+ plexpy.shutdown(restart=True, update=True)
+
elif plexpy.COMMITS_BEHIND == 0:
logger.info('PlexPy is up to date')
diff --git a/plexpy/webserve.py b/plexpy/webserve.py
index b4f5fb49..15b5666f 100644
--- a/plexpy/webserve.py
+++ b/plexpy/webserve.py
@@ -2587,7 +2587,8 @@ class WebInterface(object):
"git_token": plexpy.CONFIG.GIT_TOKEN,
"imgur_client_id": plexpy.CONFIG.IMGUR_CLIENT_ID,
"cache_images": checked(plexpy.CONFIG.CACHE_IMAGES),
- "pms_version": plexpy.CONFIG.PMS_VERSION
+ "pms_version": plexpy.CONFIG.PMS_VERSION,
+ "plexpy_auto_update": checked(plexpy.CONFIG.PLEXPY_AUTO_UPDATE)
}
return serve_template(templatename="settings.html", title="Settings", config=config, kwargs=kwargs)
@@ -2608,7 +2609,7 @@ class WebInterface(object):
"notify_consecutive", "notify_upload_posters", "notify_recently_added", "notify_group_recently_added",
"monitor_pms_updates", "monitor_remote_access", "get_file_sizes", "log_blacklist", "http_hash_password",
"allow_guest_access", "cache_images", "http_proxy", "http_basic_auth", "notify_concurrent_by_ip",
- "history_table_activity"
+ "history_table_activity", "plexpy_auto_update"
]
for checked_config in checked_configs:
if checked_config not in kwargs: