From 128f17c66cf8f835eb86a89a6cf7ac1dd8afff7d Mon Sep 17 00:00:00 2001 From: rembo10 Date: Sun, 25 Mar 2012 13:35:36 +0100 Subject: [PATCH] Initial work on the api - backend stuff to allow api as a config option --- Headphones.py | 1 + headphones/__init__.py | 9 ++++++++- headphones/webserve.py | 6 +++++- headphones/webstart.py | 2 ++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Headphones.py b/Headphones.py index 65c7d8fc..59c234f5 100644 --- a/Headphones.py +++ b/Headphones.py @@ -109,6 +109,7 @@ def main(): 'http_root': headphones.HTTP_ROOT, 'http_username': headphones.HTTP_USERNAME, 'http_password': headphones.HTTP_PASSWORD, + 'api': headphones.API, }) logger.info('Starting Headphones on port: %i' % http_port) diff --git a/headphones/__init__.py b/headphones/__init__.py index 2f11444f..4ea984ea 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -51,6 +51,9 @@ HTTP_PASSWORD = None HTTP_ROOT = None LAUNCH_BROWSER = False +API_ENABLED = False +API_KEY = None + GIT_PATH = None INSTALL_TYPE = None CURRENT_VERSION = None @@ -201,7 +204,7 @@ def initialize(): with INIT_LOCK: global __INITIALIZED__, FULL_PATH, PROG_DIR, VERBOSE, DAEMON, DATA_DIR, CONFIG_FILE, CFG, LOG_DIR, CACHE_DIR, \ - HTTP_PORT, HTTP_HOST, HTTP_USERNAME, HTTP_PASSWORD, HTTP_ROOT, LAUNCH_BROWSER, GIT_PATH, \ + HTTP_PORT, HTTP_HOST, HTTP_USERNAME, HTTP_PASSWORD, HTTP_ROOT, LAUNCH_BROWSER, API_ENABLED, API_KEY, GIT_PATH, \ CURRENT_VERSION, LATEST_VERSION, MUSIC_DIR, DESTINATION_DIR, PREFERRED_QUALITY, PREFERRED_BITRATE, DETECT_BITRATE, \ ADD_ARTISTS, CORRECT_METADATA, MOVE_FILES, RENAME_FILES, FOLDER_FORMAT, FILE_FORMAT, CLEANUP_FILES, INCLUDE_EXTRAS, \ ADD_ALBUM_ART, EMBED_ALBUM_ART, EMBED_LYRICS, DOWNLOAD_DIR, BLACKHOLE, BLACKHOLE_DIR, USENET_RETENTION, SEARCH_INTERVAL, \ @@ -240,6 +243,8 @@ def initialize(): HTTP_PASSWORD = check_setting_str(CFG, 'General', 'http_password', '') HTTP_ROOT = check_setting_str(CFG, 'General', 'http_root', '/') LAUNCH_BROWSER = bool(check_setting_int(CFG, 'General', 'launch_browser', 1)) + API_ENABLED = bool(check_setting_int(CFG, 'General', 'api_enabled', 0)) + API_KEY = check_setting_str(CFG, 'General', 'api_key', '') GIT_PATH = check_setting_str(CFG, 'General', 'git_path', '') LOG_DIR = check_setting_str(CFG, 'General', 'log_dir', '') @@ -451,6 +456,8 @@ def config_write(): new_config['General']['http_password'] = HTTP_PASSWORD new_config['General']['http_root'] = HTTP_ROOT new_config['General']['launch_browser'] = int(LAUNCH_BROWSER) + new_config['General']['api_enabled'] = int(API_ENABLED) + new_config['General']['api_key'] = API_KEY new_config['General']['log_dir'] = LOG_DIR new_config['General']['git_path'] = GIT_PATH diff --git a/headphones/webserve.py b/headphones/webserve.py index 65b076dd..e2e525d9 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -324,6 +324,8 @@ class WebInterface(object): "http_port" : headphones.HTTP_PORT, "http_pass" : headphones.HTTP_PASSWORD, "launch_browser" : checked(headphones.LAUNCH_BROWSER), + "api_enabled" : checked(headphones.API_ENABLED), + "api_key" : headphones.API_KEY, "download_scan_interval" : headphones.DOWNLOAD_SCAN_INTERVAL, "nzb_search_interval" : headphones.SEARCH_INTERVAL, "libraryscan_interval" : headphones.LIBRARYSCAN_INTERVAL, @@ -405,7 +407,7 @@ class WebInterface(object): config.exposed = True - def configUpdate(self, http_host='0.0.0.0', http_username=None, http_port=8181, http_password=None, launch_browser=0, download_scan_interval=None, nzb_search_interval=None, libraryscan_interval=None, + def configUpdate(self, http_host='0.0.0.0', http_username=None, http_port=8181, http_password=None, launch_browser=0, api_enabled=0, api_key=None, download_scan_interval=None, nzb_search_interval=None, libraryscan_interval=None, sab_host=None, sab_username=None, sab_apikey=None, sab_password=None, sab_category=None, download_dir=None, blackhole=0, blackhole_dir=None, usenet_retention=None, nzbmatrix=0, nzbmatrix_username=None, nzbmatrix_apikey=None, newznab=0, newznab_host=None, newznab_apikey=None, nzbsorg=0, nzbsorg_uid=None, nzbsorg_hash=None, newzbin=0, newzbin_uid=None, newzbin_password=None, preferred_quality=0, preferred_bitrate=None, detect_bitrate=0, move_files=0, @@ -420,6 +422,8 @@ class WebInterface(object): headphones.HTTP_USERNAME = http_username headphones.HTTP_PASSWORD = http_password headphones.LAUNCH_BROWSER = launch_browser + headphones.API_ENABLED = api_enabled + headphones.API_KEY = api_key headphones.DOWNLOAD_SCAN_INTERVAL = download_scan_interval headphones.SEARCH_INTERVAL = nzb_search_interval headphones.LIBRARYSCAN_INTERVAL = libraryscan_interval diff --git a/headphones/webstart.py b/headphones/webstart.py index 89f6a8d6..d9810c1e 100644 --- a/headphones/webstart.py +++ b/headphones/webstart.py @@ -44,6 +44,8 @@ def initialize(options={}): } } + if options['api']: + conf['/api'] = {'tools.staticdir.on': True, 'tools.staticdir.dir': "api"} if options['http_password'] != "": conf['/'].update({