CC-2044: remove hardcoded settings from application/configs/conf.php

-refactored some code to begin work on this...
This commit is contained in:
martin 2011-03-29 16:10:00 -04:00
parent 54f378049d
commit 161505a6df
6 changed files with 40 additions and 32 deletions

View File

@ -19,10 +19,6 @@ $baseFilesDir = __DIR__.'/../../files';
$CC_CONFIG = array(
// Set the URL of your installation
'storageUrlHost' => 'localhost',
'storageUrlPort' => 80,
// Name of the web server user
'webServerUser' => 'www-data',

View File

@ -1481,10 +1481,7 @@ class StoredFile {
public function getFileUrl()
{
global $CC_CONFIG;
return "http://$CC_CONFIG[storageUrlHost]"
.":$CC_CONFIG[storageUrlPort]"
.$CC_CONFIG["apiPath"]."get-media/file/"
.$this->gunid.".".$this->getFileExtension();
return $this->gunid.".".$this->getFileExtension();
}
/**

View File

@ -117,7 +117,7 @@ class AirTimeApiClient(ApiClientInterface):
def __get_airtime_version(self, verbose = True):
logger = logging.getLogger()
url = self.config["base_url"] + self.config["api_base"] + self.config["version_url"]
url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["version_url"])
logger.debug("Trying to contact %s", url)
url = url.replace("%%api_key%%", self.config["api_key"])
@ -198,7 +198,8 @@ class AirTimeApiClient(ApiClientInterface):
logger = logging.getLogger()
# Construct the URL
export_url = self.config["base_url"] + self.config["api_base"] + self.config["export_url"]
#export_url = self.config["base_url"] + self.config["api_base"] + self.config["export_url"]
export_url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["export_url"])
logger.info("Fetching schedule from %s", export_url)
export_url = export_url.replace('%%api_key%%', self.config["api_key"])
@ -215,12 +216,15 @@ class AirTimeApiClient(ApiClientInterface):
return status, response
def get_media(self, src, dst):
def get_media(self, uri, dst):
logger = logging.getLogger()
try:
src = "http://%s:%s/%s/%s" % \
(self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["get_media_url"])
src = src.replace("%%file%%", uri)
logger.info("try to download from %s to %s", src, dst)
src = src + "/api_key/" + self.config["api_key"]
src = src.replace("%%api_key%%", self.config["api_key"])
# check if file exists already before downloading again
filename, headers = urllib.urlretrieve(src, dst)
except Exception, e:
@ -234,7 +238,9 @@ class AirTimeApiClient(ApiClientInterface):
logger = logging.getLogger()
playlist = schedule[pkey]
schedule_id = playlist["schedule_id"]
url = self.config["base_url"] + self.config["api_base"] + self.config["update_item_url"]
#url = self.config["base_url"] + self.config["api_base"] + self.config["update_item_url"]
url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["update_item_url"])
url = url.replace("%%schedule_id%%", str(schedule_id))
logger.debug(url)
url = url.replace("%%api_key%%", self.config["api_key"])
@ -261,7 +267,8 @@ class AirTimeApiClient(ApiClientInterface):
response = ''
try:
schedule_id = data
url = self.config["base_url"] + self.config["api_base"] + self.config["update_start_playing_url"]
#url = self.config["base_url"] + self.config["api_base"] + self.config["update_start_playing_url"]
url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["update_start_playing_url"])
url = url.replace("%%media_id%%", str(media_id))
url = url.replace("%%schedule_id%%", str(schedule_id))
logger.debug(url)
@ -290,7 +297,8 @@ class AirTimeApiClient(ApiClientInterface):
logger = logging.getLogger()
response = ''
try:
url = self.config["base_url"] + self.config["api_base"] + self.config["show_schedule_url"]
url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["show_schedule_url"])
#url = self.config["base_url"] + self.config["api_base"] + self.config["show_schedule_url"]
logger.debug(url)
url = url.replace("%%api_key%%", self.config["api_key"])
@ -307,7 +315,9 @@ class AirTimeApiClient(ApiClientInterface):
logger = logging.getLogger()
response = ''
try:
url = self.config["base_url"] + self.config["api_base"] + self.config["upload_file_url"]
#url = self.config["base_url"] + self.config["api_base"] + self.config["upload_file_url"]
url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["upload_file_url"])
logger.debug(url)
url = url.replace("%%api_key%%", self.config["api_key"])
@ -368,7 +378,9 @@ class ObpApiClient():
logger = logging.getLogger()
# lookup OBP version
url = self.config["base_url"] + self.config["api_base"]+ self.config["version_url"]
#url = self.config["base_url"] + self.config["api_base"]+ self.config["version_url"]
url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["version_url"])
try:
logger.debug("Trying to contact %s", url)
@ -427,7 +439,8 @@ class ObpApiClient():
range['end'] = end
# Construct the URL
export_url = self.config["base_url"] + self.config["api_base"] + self.config["export_url"]
#export_url = self.config["base_url"] + self.config["api_base"] + self.config["export_url"]
export_url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["export_url"])
# Insert the start and end times into the URL
export_url = export_url.replace('%%api_key%%', self.config["api_key"])
@ -465,7 +478,8 @@ class ObpApiClient():
def notify_scheduled_item_start_playing(self, pkey, schedule):
#def update_scheduled_item(self, item_id, value):
logger = logging.getLogger()
url = self.config["base_url"] + self.config["api_base"] + self.config["update_item_url"]
#url = self.config["base_url"] + self.config["api_base"] + self.config["update_item_url"]
url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["update_item_url"])
url = url.replace("%%item_id%%", str(schedule[pkey]["id"]))
url = url.replace("%%played%%", "1")
@ -495,7 +509,8 @@ class ObpApiClient():
playlist_id = data["playlist_id"]
transmission_id = data["transmission_id"]
url = self.config["base_url"] + self.config["api_base"] + self.config["update_start_playing_url"]
#url = self.config["base_url"] + self.config["api_base"] + self.config["update_start_playing_url"]
url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["update_start_playing_url"])
url = url.replace("%%playlist_type%%", str(playlist_type))
url = url.replace("%%export_source%%", str(export_source))
url = url.replace("%%media_id%%", str(media_id))
@ -521,7 +536,8 @@ class ObpApiClient():
def generate_range_dp(self):
logger = logging.getLogger()
url = self.config["base_url"] + self.config["api_base"] + self.config["generate_range_url"]
#url = self.config["base_url"] + self.config["api_base"] + self.config["generate_range_url"]
url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["generate_range_url"])
try:
response = urllib.urlopen(url, self.api_auth)

View File

@ -18,7 +18,8 @@ file_dir = '/opt/pypo/files/'
tmp_dir = '/opt/pypo/tmp/'
# Hostname
base_url = 'http://localhost/'
base_url = 'localhost'
base_port = 80
############################################
# Liquidsoap settings #
@ -77,7 +78,7 @@ cue_style = 'pre'
api_key = 'AAA'
# Path to the base of the API
api_base = 'api/'
api_base = 'api'
# URL to get the version number of the server API
version_url = 'version/api_key/%%api_key%%'
@ -85,7 +86,9 @@ version_url = 'version/api_key/%%api_key%%'
# Schedule export path.
# %%from%% - starting date/time in the form YYYY-MM-DD-hh-mm
# %%to%% - starting date/time in the form YYYY-MM-DD-hh-mm
export_url = 'schedule/api_key/%%api_key%%'
export_url = 'schedule/api_key/%%api_key%%'
get_media_url = 'get-media/file/%%file%%/api_key/%%api_key%%'
# Update whether a schedule group has begun playing.
update_item_url = 'notify-schedule-group-play/api_key/%%api_key%%/schedule_id/%%schedule_id%%'

View File

@ -208,12 +208,8 @@ class PypoFetch(Thread):
(self.cache_dir, str(pkey), str(media['id']), str(float(media['cue_in']) / 1000), str(float(media['cue_out']) / 1000), str(fileExt))
do_cue = True
# check if it is a remote file, if yes download
if media['uri'][0:4] == 'http':
self.handle_remote_file(media, dst, do_cue)
else:
logger.debug("invalid media uri: %s", media['uri'])
# download media file
self.handle_remote_file(media, dst, do_cue)
if True == os.access(dst, os.R_OK):
# check filesize (avoid zero-byte files)

View File

@ -1,7 +1,7 @@
api_client = "airtime"
# Hostname
base_url = 'http://localhost/'
base_url = 'localhost'
# base path to store recordered shows at
base_recorded_files = '/home/pypo/Music/'
@ -10,7 +10,7 @@ base_recorded_files = '/home/pypo/Music/'
api_key = 'AAA'
# Path to the base of the API
api_base = 'api/'
api_base = 'api'
# URL to get the version number of the server API
version_url = 'version/api_key/%%api_key%%'