diff --git a/.zfproject.xml b/.zfproject.xml
index 986d3777a..05cfc7b75 100644
--- a/.zfproject.xml
+++ b/.zfproject.xml
@@ -54,6 +54,9 @@
+
+
+
@@ -167,6 +170,9 @@
+
+
+
@@ -207,6 +213,7 @@
+
diff --git a/application/configs/ACL.php b/application/configs/ACL.php
index 61f657bae..7803aa471 100644
--- a/application/configs/ACL.php
+++ b/application/configs/ACL.php
@@ -15,6 +15,7 @@ $ccAcl->add(new Zend_Acl_Resource('library'))
->add(new Zend_Acl_Resource('playlist'))
->add(new Zend_Acl_Resource('plupload'))
->add(new Zend_Acl_Resource('schedule'))
+ ->add(new Zend_Acl_Resource('api'))
->add(new Zend_Acl_Resource('search'));
/** Creating permissions */
@@ -23,11 +24,12 @@ $ccAcl->allow('guest', 'index')
->allow('guest', 'error')
->allow('guest', 'library')
->allow('guest', 'search')
+ ->allow('guest', 'api')
->allow('host', 'plupload')
->allow('host', 'playlist')
->allow('host', 'schedule');
$aclPlugin = new Zend_Controller_Plugin_Acl($ccAcl);
-$front = Zend_Controller_Front::getInstance();
+$front = Zend_Controller_Front::getInstance();
$front->registerPlugin($aclPlugin);
diff --git a/application/configs/conf.php b/application/configs/conf.php
index 0a97c14c4..7779721b5 100644
--- a/application/configs/conf.php
+++ b/application/configs/conf.php
@@ -25,6 +25,8 @@ $CC_CONFIG = array(
'apiKey' => array('AAA'),
+ 'apiPath' => "/api/",
+
'baseFilesDir' => __DIR__."/../../files",
// main directory for storing binary media files
'storageDir' => __DIR__.'/../../files/stor',
@@ -162,4 +164,13 @@ set_include_path('.'.PATH_SEPARATOR.$CC_CONFIG['pearPath']
.PATH_SEPARATOR.$CC_CONFIG['zendPath']
.PATH_SEPARATOR.$old_include_path);
+//$dsn = $CC_CONFIG['dsn'];
+//$CC_DBC = DB::connect($dsn, TRUE);
+//if (PEAR::isError($CC_DBC)) {
+// echo "ERROR: ".$CC_DBC->getMessage()." ".$CC_DBC->getUserInfo()."\n";
+// exit(1);
+//}
+//$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
+
+
?>
\ No newline at end of file
diff --git a/application/models/Playlist.php b/application/models/Playlist.php
index a0ec8385d..78333a88b 100644
--- a/application/models/Playlist.php
+++ b/application/models/Playlist.php
@@ -102,7 +102,14 @@ class Playlist {
}
- /**
+ public static function findPlaylistByName($p_name)
+ {
+ $res = CcPlaylistQuery::create()->findByDbName($p_name);
+ return $res;
+ }
+
+
+ /**
* Fetch instance of Playlist object.
*
* @param string $id
@@ -414,7 +421,7 @@ class Playlist {
if (is_null($media) || PEAR::isError($media)) {
return $media;
}
-
+
$metadata = $media->getMetadata();
$length = $metadata["length"];
@@ -425,7 +432,7 @@ class Playlist {
// insert at end of playlist.
if (is_null($p_position))
$p_position = $this->getNextPos();
-
+
// insert default values if parameter was empty
$p_cuein = !is_null($p_cuein) ? $p_cuein : '00:00:00.000000';
$p_cueout = !is_null($p_cueout) ? $p_cueout : $length;
@@ -434,9 +441,9 @@ class Playlist {
$sql = "SELECT INTERVAL '{$p_cueout}' - INTERVAL '{$p_cuein}'";
$r = $con->query($sql);
$p_cliplength = $r->fetchColumn(0);
-
+
$res = $this->insertPlaylistElement($this->id, $p_mediaId, $p_position, $p_cliplength, $p_cuein, $p_cueout, $p_fadeIn, $p_fadeOut);
-
+
return TRUE;
}
@@ -629,7 +636,7 @@ class Playlist {
$sql = "SELECT INTERVAL '{$oldCueOut}' - INTERVAL '{$cueIn}'";
$r = $con->query($sql);
$cliplength = $r->fetchColumn(0);
-
+
$row->setDbCuein($cueIn);
$row->setDBCliplength($cliplength);
}
diff --git a/application/models/Schedule.php b/application/models/Schedule.php
index fa80671f3..76a028061 100644
--- a/application/models/Schedule.php
+++ b/application/models/Schedule.php
@@ -401,6 +401,26 @@ class Schedule {
return $t[0]."-".$t[1]."-".$t[2]." ".$t[3].":".$t[4].":00";
}
+ /**
+ * Return true if the input string is in the format YYYY-MM-DD-HH-mm
+ *
+ * @param string $p_time
+ * @return boolean
+ */
+ public static function ValidPypoTimeFormat($p_time)
+ {
+ $t = explode("-", $p_time);
+ if (count($t) != 5) {
+ return false;
+ }
+ foreach ($t as $part) {
+ if (!is_numeric($part)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
/**
* Converts a time value as a string (with format HH:MM:SS.mmmmmm) to
* millisecs.
diff --git a/application/models/StoredFile.php b/application/models/StoredFile.php
index 052885be6..9925fcc63 100644
--- a/application/models/StoredFile.php
+++ b/application/models/StoredFile.php
@@ -1697,7 +1697,7 @@ class StoredFile {
{
global $CC_CONFIG;
return "http://".$CC_CONFIG["storageUrlHost"]
- .$CC_CONFIG["apiPath"]."get_media.php?file="
+ .$CC_CONFIG["apiPath"]."getMedia/file/"
.$this->gunid.".".$this->getFileExtension();
}
diff --git a/pypo/api_clients/api_client.py b/pypo/api_clients/api_client.py
index 59fd22e48..4f6357a74 100644
--- a/pypo/api_clients/api_client.py
+++ b/pypo/api_clients/api_client.py
@@ -251,7 +251,7 @@ class CampcasterApiClient(ApiClientInterface):
logger = logging.getLogger()
try:
- src = src + "&api_key=" + self.config["api_key"]
+ src = src + "/api_key/" + self.config["api_key"]
# check if file exists already before downloading again
filename, headers = urllib.urlretrieve(src, dst)
@@ -269,7 +269,7 @@ class CampcasterApiClient(ApiClientInterface):
schedule_id = playlist["schedule_id"]
url = self.config["base_url"] + self.config["api_base"] + self.config["update_item_url"]
url = url.replace("%%schedule_id%%", str(schedule_id))
- url += "&api_key=" + self.config["api_key"]
+ url = url.replace("%%api_key%%", self.config["api_key"])
logger.debug(url)
try:
diff --git a/pypo/config.cfg b/pypo/config.cfg
index 26ec732cd..7655854f0 100644
--- a/pypo/config.cfg
+++ b/pypo/config.cfg
@@ -72,24 +72,24 @@ cue_style = 'pre'
api_key = 'AAA'
# Path to the base of the API
-api_base = 'campcaster/'
+api_base = 'api/'
# URL to get the version number of the server API
-version_url = 'api/api_version.php?api_key=%%api_key%%'
+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 = 'api/schedule.php?from=%%from%%&to=%%to%%&api_key=%%api_key%%'
+export_url = 'schedule/api_key/%%api_key%%/from/%%from%%/to/%%to%%'
# Update whether a schedule group has begun playing.
-update_item_url = 'api/notify_schedule_group_play.php?schedule_id=%%schedule_id%%'
+update_item_url = 'notifyScheduleGroupPlay/api_key/%%api_key%%/schedule_id/%%schedule_id%%'
# Update whether an audio clip is currently playing.
-update_start_playing_url = 'api/notify_media_item_start_play.php?media_id=%%media_id%%&schedule_id=%%schedule_id%%'
+update_start_playing_url = 'notifyMediaItemStartPlay/api_key/%%api_key%%/media_id/%%media_id%%/schedule_id/%%schedule_id%%'
# ???
-generate_range_url = 'api/generate_range_dp.php'
+generate_range_url = 'generate_range_dp.php'
##############
diff --git a/pypo/install/pypo-daemontools-fetch.sh b/pypo/install/pypo-daemontools-fetch.sh
index bf762ae89..6e7bed55d 100644
--- a/pypo/install/pypo-daemontools-fetch.sh
+++ b/pypo/install/pypo-daemontools-fetch.sh
@@ -2,8 +2,8 @@
pypo_user="pypo"
export HOME="/home/pypo/"
# Location of pypo_cli.py Python script
-pypo_path="/opt/pypo/bin"
-pypo_script="pypo_cli.py"
+pypo_path="/opt/pypo/bin/"
+pypo_script="pypo-cli.py"
echo "*** Daemontools: starting daemon"
cd ${pypo_path}
exec 2>&1
diff --git a/pypo/install/pypo-daemontools-push.sh b/pypo/install/pypo-daemontools-push.sh
index b933ea838..4c5cc9f7c 100644
--- a/pypo/install/pypo-daemontools-push.sh
+++ b/pypo/install/pypo-daemontools-push.sh
@@ -2,8 +2,8 @@
pypo_user="pypo"
export HOME="/home/pypo/"
# Location of pypo_cli.py Python script
-pypo_path="/opt/pypo/bin"
-pypo_script="pypo_cli.py"
+pypo_path="/opt/pypo/bin/"
+pypo_script="pypo-cli.py"
echo "*** Daemontools: starting daemon"
cd ${pypo_path}
exec 2>&1
diff --git a/pypo/install/pypo-install.py b/pypo/install/pypo-install.py
index adeb85619..a5a38dfbc 100644
--- a/pypo/install/pypo-install.py
+++ b/pypo/install/pypo-install.py
@@ -61,8 +61,17 @@ try:
shutil.copy("../scripts/silence-playlist.lsp", BASE_PATH+"files/basic")
shutil.copy("../scripts/silence.mp3", BASE_PATH+"files/basic")
shutil.copy("../pypo-cli.py", BASE_PATH+"bin")
+ shutil.copy("../pypo-notify.py", BASE_PATH+"bin")
+ shutil.copy("../logging.cfg", BASE_PATH+"bin")
+ shutil.copy("../config.cfg", BASE_PATH+"bin")
shutil.copy("../pypo-log.sh", BASE_PATH+"bin")
-
+ print "Copying directory util"
+ shutil.copytree("../util", BASE_PATH+"bin/util")
+ print "Copying directory api_clients"
+ shutil.copytree("../api_clients", BASE_PATH+"bin/api_clients")
+ print "Copying directory scripts"
+ shutil.copytree("../scripts", BASE_PATH+"bin/scripts")
+
print "Setting permissions"
os.system("chmod -R 755 "+BASE_PATH)
os.system("chown -R pypo:pypo "+BASE_PATH)
@@ -95,8 +104,18 @@ try:
output = p.stdout.read()
if (output.find("unable to open supervise/ok: file does not exist") >= 0):
print "Install has completed, but daemontools is not running, please make sure you have it installed and then reboot."
+ sys.exit()
+ print output
+
+ p = Popen('svstat /etc/service/pypo-push', shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
+ output = p.stdout.read()
+ print output
+
+ p = Popen('svstat /etc/service/pypo-liquidsoap', shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
+ output = p.stdout.read()
+ print output
- #os.symlink(BASE_PATH+"bin/pypo-log.sh", "/usr/local/bin/")
+#os.symlink(BASE_PATH+"bin/pypo-log.sh", "/usr/local/bin/")
except Exception, e:
diff --git a/application/models/tests/pypoTester.php b/pypo/tests/pypoTester.php
similarity index 81%
rename from application/models/tests/pypoTester.php
rename to pypo/tests/pypoTester.php
index 4443b14c1..0fa1853e9 100644
--- a/application/models/tests/pypoTester.php
+++ b/pypo/tests/pypoTester.php
@@ -1,12 +1,23 @@
getMessage()." ".$CC_DBC->getUserInfo()."\n";
+ exit(1);
+}
+$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
+
$playlistName = "pypo_playlist_test";
$minutesFromNow = 1;
@@ -82,4 +93,4 @@ $scheduleGroup = new ScheduleGroup();
$scheduleGroup->add($playTime, null, $pl->getId());
echo " SUCCESS: Playlist scheduled at $playTime\n\n";
-?>
\ No newline at end of file
+?>
diff --git a/tests/application/controllers/ApiControllerTest.php b/tests/application/controllers/ApiControllerTest.php
new file mode 100644
index 000000000..aaf96967e
--- /dev/null
+++ b/tests/application/controllers/ApiControllerTest.php
@@ -0,0 +1,20 @@
+