function setup()
 {
     global $CC_CONFIG;
     $con = Propel::getConnection();
     // Clear the files table
     $sql = "DELETE FROM " . $CC_CONFIG["filesTable"];
     $con->exec($sql);
     // Add a file
     $values = array("filepath" => dirname(__FILE__) . "/test10001.mp3");
     $this->storedFile = Application_Model_StoredFile::Insert($values, false);
     // Add a file
     $values = array("filepath" => dirname(__FILE__) . "/test10002.mp3");
     $this->storedFile2 = Application_Model_StoredFile::Insert($values, false);
     // Clear the schedule table
     $sql = "DELETE FROM " . $CC_CONFIG["scheduleTable"];
     $con->exec($sql);
     // Create a playlist
     $playlist = new Application_Model_Playlist();
     $playlist->create("Scheduler Unit Test");
     $result = $playlist->addAudioClip($this->storedFile->getId());
     $result = $playlist->addAudioClip($this->storedFile2->getId());
     $result = $playlist->addAudioClip($this->storedFile2->getId());
     // Schedule it
     $i = new Application_Model_ScheduleGroup();
     $this->groupIdCreated = $i->add('2010-11-11 01:30:23', null, $playlist->getId());
 }
 public function copyfileAction()
 {
     $upload_dir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
     $filename = $this->_getParam('name');
     $tempname = $this->_getParam('tempname');
     $result = Application_Model_StoredFile::copyFileToStor($upload_dir, $filename, $tempname);
     if (!is_null($result)) {
         die('{"jsonrpc" : "2.0", "error" : ' . json_encode($result) . '}');
     }
     die('{"jsonrpc" : "2.0"}');
 }
 public function copyfileAction()
 {
     $upload_dir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
     $filename = $this->_getParam('name');
     $tempname = $this->_getParam('tempname');
     $result = Application_Model_StoredFile::copyFileToStor($upload_dir, $filename, $tempname);
     if (!is_null($result)) {
         $this->_helper->json->sendJson(array("jsonrpc" => "2.0", "error" => $result));
     }
     $this->_helper->json->sendJson(array("jsonrpc" => "2.0"));
 }
 function setup()
 {
     global $CC_CONFIG;
     // Clear the files table
     //$sql = "DELETE FROM ".$CC_CONFIG["filesTable"];
     // Add a file
     $values = array("filepath" => dirname(__FILE__) . "/test10001.mp3");
     $this->storedFile = Application_Model_StoredFile::Insert($values, false);
     // Add a file
     $values = array("filepath" => dirname(__FILE__) . "/test10002.mp3");
     $this->storedFile2 = Application_Model_StoredFile::Insert($values, false);
     // Clear the schedule table
     //$sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"];
 }
 function testDeleteAndPutFile()
 {
     $STORAGE_SERVER_PATH = dirname(__FILE__) . "/../../";
     $filePath = dirname(__FILE__) . "/ex1.mp3";
     // Delete any old data from previous tests
     $md5 = md5_file($filePath);
     $duplicate = Application_Model_StoredFile::RecallByMd5($md5);
     if ($duplicate) {
         $duplicate->delete();
     }
     // Test inserting a file by linking
     $values = array("filepath" => $filePath, "dc:description" => "Unit test " . time());
     $storedFile = Application_Model_StoredFile::Insert($values, false);
     //var_dump($storedFile);
     $id = $storedFile->getId();
     if (!is_numeric($id)) {
         $this->fail("StoredFile not created correctly. id = " . $id);
         return;
     }
     // Test loading metadata
     $f = new Application_Model_StoredFile();
     $f->__setGunid($storedFile->getGunid());
     $f->loadMetadata();
     if (!is_array($md = $f->getMetadata())) {
         $this->fail("Unable to load metadata.");
         return;
     }
     //var_dump($md);
     // Check if the length field has been set.
     $f2 = Application_Model_StoredFile::RecallByGunid($storedFile->getGunid());
     $m2 = $f2->getMetadata();
     if (!isset($m2["length"]) || $m2["length"] == "00:00:00.000000") {
         $this->fail("Length not reporting correctly in metadata.");
         return;
     }
 }
 /**
  * Simply sets up the view to play the required audio track.
  *  Gets the parameters from the request and sets them to the view.
  */
 public function audioPreviewAction()
 {
     $CC_CONFIG = Config::getConfig();
     $audioFileID = $this->_getParam('audioFileID');
     $audioFileArtist = $this->_getParam('audioFileArtist');
     $audioFileTitle = $this->_getParam('audioFileTitle');
     $type = $this->_getParam('type');
     $baseUrl = Application_Common_OsPath::getBaseDir();
     $this->view->headScript()->appendFile($baseUrl . 'js/airtime/audiopreview/preview_jplayer.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $this->view->headScript()->appendFile($baseUrl . 'js/jplayer/jplayer.playlist.min.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $this->view->headLink()->appendStylesheet($baseUrl . 'js/jplayer/skin/jplayer.airtime.audio.preview.css?' . $CC_CONFIG['airtime_version']);
     $this->_helper->layout->setLayout('audioPlayer');
     $logo = Application_Model_Preference::GetStationLogo();
     if ($logo) {
         $this->view->logo = "data:image/png;base64,{$logo}";
     } else {
         $this->view->logo = $baseUrl . "css/images/airtime_logo_jp.png";
     }
     if ($type == "audioclip") {
         $uri = $baseUrl . "api/get-media/file/" . $audioFileID;
         $media = Application_Model_StoredFile::RecallById($audioFileID);
         $mime = $media->getPropelOrm()->getDbMime();
     } elseif ($type == "stream") {
         $webstream = CcWebstreamQuery::create()->findPk($audioFileID);
         $uri = $webstream->getDbUrl();
         $mime = $webstream->getDbMime();
     } else {
         throw new Exception("Unknown type for audio preview!.Type={$type}");
     }
     $this->view->uri = $uri;
     $this->view->mime = $mime;
     $this->view->audioFileID = $audioFileID;
     // We need to decode artist and title because it gets
     // encoded twice in js
     $this->view->audioFileArtist = htmlspecialchars(urldecode($audioFileArtist));
     $this->view->audioFileTitle = htmlspecialchars(urldecode($audioFileTitle));
     $this->view->type = $type;
     $this->_helper->viewRenderer->setRender('audio-preview');
 }
 /**
  * Simply sets up the view to play the required audio track.
  *  Gets the parameters from the request and sets them to the view.
  */
 public function audioPreviewAction()
 {
     global $CC_CONFIG;
     $audioFileID = $this->_getParam('audioFileID');
     $audioFileArtist = $this->_getParam('audioFileArtist');
     $audioFileTitle = $this->_getParam('audioFileTitle');
     $type = $this->_getParam('type');
     $request = $this->getRequest();
     $baseUrl = $request->getBaseUrl();
     $this->view->headScript()->appendFile($baseUrl . '/js/airtime/audiopreview/preview_jplayer.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $this->view->headScript()->appendFile($baseUrl . '/js/jplayer/jplayer.playlist.min.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $this->view->headLink()->appendStylesheet($baseUrl . '/js/jplayer/skin/jplayer.airtime.audio.preview.css?' . $CC_CONFIG['airtime_version']);
     $this->_helper->layout->setLayout('audioPlayer');
     $logo = Application_Model_Preference::GetStationLogo();
     if ($logo) {
         $this->view->logo = "data:image/png;base64,{$logo}";
     } else {
         $this->view->logo = "{$baseUrl}/css/images/airtime_logo_jp.png";
     }
     if ($type == "audioclip") {
         $uri = "/api/get-media/file/" . $audioFileID;
         $media = Application_Model_StoredFile::Recall($audioFileID);
         $mime = $media->getPropelOrm()->getDbMime();
     } elseif ($type == "stream") {
         $webstream = CcWebstreamQuery::create()->findPk($audioFileID);
         $uri = $webstream->getDbUrl();
         $mime = $webstream->getDbMime();
     } else {
         throw new Exception("Unknown type for audio preview!.Type={$type}");
     }
     $this->view->uri = $uri;
     $this->view->mime = $mime;
     $this->view->audioFileID = $audioFileID;
     $this->view->audioFileArtist = $audioFileArtist;
     $this->view->audioFileTitle = $audioFileTitle;
     $this->view->type = $type;
     $this->_helper->viewRenderer->setRender('audio-preview');
 }
Exemple #8
0
 public function updateReplayGainValueAction()
 {
     // disable layout
     $this->view->layout()->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $request = $this->getRequest();
     $data = json_decode($request->getParam('data'));
     foreach ($data as $pair) {
         list($id, $gain) = $pair;
         // TODO : move this code into model -- RG
         $file = Application_Model_StoredFile::Recall($p_id = $id)->getPropelOrm();
         $file->setDbReplayGain($gain);
         $file->save();
     }
 }
Exemple #9
0
 private static function createScheduledEvents(&$data, $range_start, $range_end)
 {
     $utcTimeZone = new DateTimeZone("UTC");
     $items = self::getItems($range_start, $range_end);
     foreach ($items as $item) {
         $showEndDateTime = new DateTime($item["show_end"], $utcTimeZone);
         $trackStartDateTime = new DateTime($item["start"], $utcTimeZone);
         $trackEndDateTime = new DateTime($item["end"], $utcTimeZone);
         if ($trackStartDateTime->getTimestamp() > $showEndDateTime->getTimestamp()) {
             //do not send any tracks that start past their show's end time
             continue;
         }
         if ($trackEndDateTime->getTimestamp() > $showEndDateTime->getTimestamp()) {
             $di = $trackStartDateTime->diff($showEndDateTime);
             $item["cue_out"] = $di->format("%H:%i:%s") . ".000";
             $item["end"] = $showEndDateTime->format("Y-m-d H:i:s");
         }
         if (!is_null($item['file_id'])) {
             //row is from "file"
             $media_id = $item['file_id'];
             $storedFile = Application_Model_StoredFile::Recall($media_id);
             $uri = $storedFile->getFilePath();
             self::createFileScheduleEvent($data, $item, $media_id, $uri);
         } elseif (!is_null($item['stream_id'])) {
             //row is type "webstream"
             $media_id = $item['stream_id'];
             $uri = $item['url'];
             self::createStreamScheduleEvent($data, $item, $media_id, $uri);
         } else {
             throw new Exception("Unknown schedule type: " . print_r($item, true));
         }
     }
 }
Exemple #10
0
 public function getUploadToSoundcloudStatusAction()
 {
     $id = $this->_getParam('id');
     $type = $this->_getParam('type');
     if ($type == "show") {
         $show_instance = new Application_Model_ShowInstance($id);
         $this->view->sc_id = $show_instance->getSoundCloudFileId();
         $file = $show_instance->getRecordedFile();
         $this->view->error_code = $file->getSoundCloudErrorCode();
         $this->view->error_msg = $file->getSoundCloudErrorMsg();
     } elseif ($type == "file") {
         $file = Application_Model_StoredFile::Recall($id);
         $this->view->sc_id = $file->getSoundCloudId();
         $this->view->error_code = $file->getSoundCloudErrorCode();
         $this->view->error_msg = $file->getSoundCloudErrorMsg();
     } else {
         Logging::warn("Trying to upload unknown type: {$type} with id: {$id}");
     }
 }
Exemple #11
0
 public function contentContextMenuAction()
 {
     global $CC_CONFIG;
     $id = $this->_getParam('id');
     $params = '/format/json/id/#id#/';
     $paramsPop = str_replace('#id#', $id, $params);
     // added for downlaod
     $id = $this->_getParam('id');
     $file_id = $this->_getParam('id', null);
     $file = Application_Model_StoredFile::Recall($file_id);
     $baseUrl = $this->getRequest()->getBaseUrl();
     $url = $file->getRelativeFileUrl($baseUrl) . '/download/true';
     $menu[] = array('action' => array('type' => 'gourl', 'url' => $url), 'title' => 'Download');
     //returns format jjmenu is looking for.
     die(json_encode($menu));
 }
$CC_CONFIG['dsn']['username'] = $values['database']['dbuser'];
$CC_CONFIG['dsn']['password'] = $values['database']['dbpass'];
$CC_CONFIG['dsn']['hostspec'] = $values['database']['host'];
$CC_CONFIG['dsn']['phptype'] = 'pgsql';
$CC_CONFIG['dsn']['database'] = $values['database']['dbname'];
$CC_CONFIG['soundcloud-connection-retries'] = $values['soundcloud']['connection_retries'];
$CC_CONFIG['soundcloud-connection-wait'] = $values['soundcloud']['time_between_retries'];
require_once $CC_CONFIG['phpDir'] . '/application/configs/constants.php';
require_once $CC_CONFIG['phpDir'] . '/application/configs/conf.php';
$CC_CONFIG['phpDir'] = $values['general']['airtime_dir'];
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(get_include_path(), realpath($CC_CONFIG['phpDir'] . '/library'))));
require_once $CC_CONFIG['phpDir'] . '/application/models/StoredFile.php';
require_once $CC_CONFIG['phpDir'] . '/application/models/Preference.php';
require_once $CC_CONFIG['phpDir'] . '/application/models/MusicDir.php';
require_once $CC_CONFIG['phpDir'] . '/application/common/OsPath.php';
set_include_path($CC_CONFIG['phpDir'] . '/library' . PATH_SEPARATOR . get_include_path());
require_once $CC_CONFIG['phpDir'] . '/application/models/Soundcloud.php';
set_include_path($CC_CONFIG['phpDir'] . "/application/models" . PATH_SEPARATOR . get_include_path());
require_once $CC_CONFIG['phpDir'] . "/library/propel/runtime/lib/Propel.php";
Propel::init($CC_CONFIG['phpDir'] . "/application/configs/airtime-conf.php");
require_once 'propel/runtime/lib/Propel.php';
Propel::init($CC_CONFIG['phpDir'] . "/application/configs/airtime-conf-production.php");
if (count($argv) != 2) {
    exit;
}
$id = $argv[1];
$file = Application_Model_StoredFile::Recall($id);
// set id with -2 which is indicator for processing
$file->setSoundCloudFileId(SOUNDCLOUD_PROGRESS);
$file->uploadToSoundCloud();
 public function updateFutureIsScheduled($scheduleId, $status)
 {
     $sched = CcScheduleQuery::create()->findPk($scheduleId);
     $redraw = false;
     if (isset($sched)) {
         $fileId = $sched->getDbFileId();
         if (isset($fileId)) {
             $redraw = Application_Model_StoredFile::setIsScheduled($fileId, $status);
         }
     }
     return $redraw;
 }
 /**
  * Delete all files from playlist
  * @param int $p_playlistId
  */
 public function deleteAllFilesFromPlaylist()
 {
     // get only the files from the playlist
     // we are about to clear out
     $itemsToDelete = CcPlaylistcontentsQuery::create()->filterByDbPlaylistId($this->id)->filterByDbFileId(null, Criteria::NOT_EQUAL)->find();
     CcPlaylistcontentsQuery::create()->findByDbPlaylistId($this->id)->delete();
     // update is_playlist flag in cc_files
     Application_Model_StoredFile::setIsPlaylist($itemsToDelete, 'playlist', false);
     $this->pl->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
     $this->pl->save($this->con);
     $this->con->commit();
 }
 public function deleteShow($instanceId, $singleInstance = false)
 {
     $service_user = new Application_Service_UserService();
     $currentUser = $service_user->getCurrentUser();
     $con = Propel::getConnection();
     $con->beginTransaction();
     try {
         if (!$currentUser->isAdminOrPM()) {
             throw new Exception("Permission denied");
         }
         $ccShowInstance = CcShowInstancesQuery::create()->findPk($instanceId);
         if (!$ccShowInstance) {
             throw new Exception("Could not find show instance");
         }
         $showId = $ccShowInstance->getDbShowId();
         if ($singleInstance) {
             $ccShowInstances = CcShowInstancesQuery::create()->filterByDbShowId($showId)->filterByDbStarts($ccShowInstance->getDbStarts(), Criteria::GREATER_EQUAL)->filterByDbEnds($ccShowInstance->getDbEnds(), Criteria::LESS_EQUAL)->find();
         } else {
             $ccShowInstances = CcShowInstancesQuery::create()->filterByDbShowId($showId)->filterByDbStarts($ccShowInstance->getDbStarts(), Criteria::GREATER_EQUAL)->find();
         }
         if (gmdate("Y-m-d H:i:s") <= $ccShowInstance->getDbEnds()) {
             $this->deleteShowInstances($ccShowInstances, $ccShowInstance->getDbShowId());
         }
         Application_Model_StoredFile::updatePastFilesIsScheduled();
         Application_Model_RabbitMq::PushSchedule();
         $con->commit();
         return $showId;
     } catch (Exception $e) {
         $con->rollback();
         Logging::info("Delete show instance failed");
         Logging::info($e->getMessage());
         return false;
     }
 }
// Delete any old playlists
$pl2 = Playlist::findPlaylistByName($playlistName);
foreach ($pl2 as $playlist) {
    //var_dump($playlist);
    $playlist->delete();
}
echo "done.\n";
// Create a new playlist
echo "Creating new playlist '{$playlistName}'...";
$pl = new Playlist();
$pl->create($playlistName);
$mediaFile = Application_Model_StoredFile::findByOriginalName("Peter_Rudenko_-_Opening.mp3");
if (is_null($mediaFile)) {
    echo "Adding test audio clip to the database.\n";
    $v = array("filepath" => __DIR__ . "/../../../audio_samples/vorbis.com/Hydrate-Kenny_Beltrey.ogg");
    $mediaFile = Application_Model_StoredFile::Insert($v);
}
$pl->addAudioClip($mediaFile->getId());
echo "done.\n";
//$pl2 = Playlist::findPlaylistByName("pypo_playlist_test");
//var_dump($pl2);
// Get current time
// In the format YYYY-MM-DD HH:MM:SS.nnnnnn
$startTime = date("Y-m-d H:i:s");
$endTime = date("Y-m-d H:i:s", time() + 60 * 60);
echo "Removing everything from the scheduler between {$startTime} and {$endTime}...";
// Check for succces
$scheduleClear = Schedule::isScheduleEmptyInRange($startTime, "01:00:00");
if (!$scheduleClear) {
    echo "\nERROR: Schedule could not be cleared.\n\n";
    var_dump(Schedule::getItems($startTime, $endTime));
 public function populateTemplateItem($values, $id = null, $instance_id = null)
 {
     $this->con->beginTransaction();
     try {
         $template = $this->getConfiguredItemTemplate();
         $prefix = Application_Form_EditHistoryItem::ID_PREFIX;
         if (isset($id)) {
             $historyRecord = CcPlayoutHistoryQuery::create()->findPk($id, $this->con);
         } else {
             $historyRecord = new CcPlayoutHistory();
         }
         if (isset($instance_id)) {
             $historyRecord->setDbInstanceId($instance_id);
         }
         $timezoneUTC = new DateTimeZone("UTC");
         $timezoneLocal = new DateTimeZone($this->timezone);
         $dateTime = new DateTime($values[$prefix . "starts"], $timezoneLocal);
         $dateTime->setTimezone($timezoneUTC);
         $historyRecord->setDbStarts($dateTime->format("Y-m-d H:i:s"));
         $dateTime = new DateTime($values[$prefix . "ends"], $timezoneLocal);
         $dateTime->setTimezone($timezoneUTC);
         $historyRecord->setDbEnds($dateTime->format("Y-m-d H:i:s"));
         $templateValues = $values[$prefix . "template"];
         $file = $historyRecord->getCcFiles();
         $md = array();
         $metadata = array();
         $fields = $template["fields"];
         $required = $this->mandatoryItemFields();
         $phpCasts = $this->getPhpCasts();
         for ($i = 0, $len = count($fields); $i < $len; $i++) {
             $field = $fields[$i];
             $key = $field["name"];
             //required is delt with before this loop.
             if (in_array($key, $required)) {
                 continue;
             }
             $isFileMd = $field["isFileMd"];
             $entry = $phpCasts[$field["type"]]($templateValues[$prefix . $key]);
             if ($isFileMd && isset($file)) {
                 Logging::info("adding metadata associated to a file for {$key} = {$entry}");
                 $md[$key] = $entry;
             } else {
                 Logging::info("adding metadata for {$key} = {$entry}");
                 $metadata[$key] = $entry;
             }
         }
         if (count($md) > 0) {
             $f = Application_Model_StoredFile::createWithFile($file, $this->con);
             $f->setDbColMetadata($md);
         }
         //Use this array to update existing values.
         $mds = $historyRecord->getCcPlayoutHistoryMetaDatas();
         foreach ($mds as $md) {
             $prevmd[$md->getDbKey()] = $md;
         }
         foreach ($metadata as $key => $val) {
             if (isset($prevmd[$key])) {
                 $meta = $prevmd[$key];
                 $meta->setDbValue($val);
             } else {
                 $meta = new CcPlayoutHistoryMetaData();
                 $meta->setDbKey($key);
                 $meta->setDbValue($val);
                 $historyRecord->addCcPlayoutHistoryMetaData($meta);
             }
         }
         $historyRecord->save($this->con);
         $this->con->commit();
     } catch (Exception $e) {
         $this->con->rollback();
         throw $e;
     }
 }
 private function makeHeaderRow($p_item)
 {
     $row = $this->defaultRowArray;
     //$this->isAllowed($p_item, $row);
     $this->getRowTimestamp($p_item, $row);
     $this->getItemColor($p_item, $row);
     $showStartDT = new DateTime($p_item["si_starts"], new DateTimeZone("UTC"));
     $showStartDT->setTimezone(new DateTimeZone($this->timezone));
     $startsEpoch = floatval($showStartDT->format("U.u"));
     $showEndDT = new DateTime($p_item["si_ends"], new DateTimeZone("UTC"));
     $showEndDT->setTimezone(new DateTimeZone($this->timezone));
     $endsEpoch = floatval($showEndDT->format("U.u"));
     //is a rebroadcast show
     if (intval($p_item["si_rebroadcast"]) === 1) {
         $row["rebroadcast"] = true;
         $parentInstance = CcShowInstancesQuery::create()->findPk($p_item["parent_show"]);
         $name = $parentInstance->getCcShow()->getDbName();
         $dt = $parentInstance->getDbStarts(null);
         $dt->setTimezone(new DateTimeZone($this->timezone));
         $time = $dt->format("Y-m-d H:i");
         $row["rebroadcast_title"] = sprintf(_("Rebroadcast of %s from %s"), $name, $time);
     } elseif (intval($p_item["si_record"]) === 1) {
         $row["record"] = true;
         // at the time of creating on show, the recorded file is not in the DB yet.
         // therefore, 'si_file_id' is null. So we need to check it.
         if (Application_Model_Preference::GetUploadToSoundcloudOption() && isset($p_item['si_file_id'])) {
             $file = Application_Model_StoredFile::RecallById($p_item['si_file_id']);
             if (isset($file)) {
                 $sid = $file->getSoundCloudId();
                 $row['soundcloud_id'] = $sid;
             }
         }
     }
     if ($startsEpoch < $this->epoch_now && $endsEpoch > $this->epoch_now) {
         $row["currentShow"] = true;
         $this->currentShow = true;
     } else {
         $this->currentShow = false;
     }
     $this->isAllowed($p_item, $row);
     $row["header"] = true;
     $row["starts"] = $showStartDT->format("Y-m-d H:i");
     $row["startDate"] = $showStartDT->format("Y-m-d");
     $row["startTime"] = $showStartDT->format("H:i");
     $row["refresh"] = floatval($showStartDT->format("U.u")) - $this->epoch_now;
     $row["ends"] = $showEndDT->format("Y-m-d H:i");
     $row["endDate"] = $showEndDT->format("Y-m-d");
     $row["endTime"] = $showEndDT->format("H:i");
     $row["duration"] = floatval($showEndDT->format("U.u")) - floatval($showStartDT->format("U.u"));
     $row["title"] = htmlspecialchars($p_item["show_name"]);
     $row["instance"] = intval($p_item["si_id"]);
     $row["image"] = '';
     $this->getScheduledStatus($startsEpoch, $endsEpoch, $row);
     $this->contentDT = $showStartDT;
     return $row;
 }
 public function updateCueValuesBySilanAction()
 {
     $request = $this->getRequest();
     $data = json_decode($request->getParam('data'), $assoc = true);
     foreach ($data as $pair) {
         list($id, $info) = $pair;
         // TODO : move this code into model -- RG
         $file = Application_Model_StoredFile::RecallById($p_id = $id)->getPropelOrm();
         //What we are doing here is setting a more accurate length that was
         //calculated with silan by actually scanning the entire file. This
         //process takes a really long time, and so we only do it in the background
         //after the file has already been imported -MK
         try {
             $length = $file->getDbLength();
             if (isset($info['length'])) {
                 $length = $info['length'];
                 //length decimal number in seconds. Need to convert it to format
                 //HH:mm:ss to get around silly PHP limitations.
                 $length = Application_Common_DateHelper::secondsToPlaylistTime($length);
                 $file->setDbLength($length);
             }
             $cuein = isset($info['cuein']) ? $info['cuein'] : 0;
             $cueout = isset($info['cueout']) ? $info['cueout'] : $length;
             $file->setDbCuein($cuein);
             $file->setDbCueout($cueout);
             $file->setDbSilanCheck(true);
             $file->save();
         } catch (Exception $e) {
             Logging::info("Failed to update silan values for " . $file->getDbTrackTitle());
             Logging::info("File length analyzed by Silan is: " . $length);
             //set silan_check to true so we don't attempt to re-anaylze again
             $file->setDbSilanCheck(true);
             $file->save();
         }
     }
     $this->_helper->json->sendJson(array());
 }
Exemple #20
0
 public static function Recall($p_id = null, $p_gunid = null, $p_md5sum = null, $p_filepath = null)
 {
     if (isset($p_id)) {
         $f = CcFilesQuery::create()->findPK(intval($p_id));
         return is_null($f) ? null : self::createWithFile($f);
     } elseif (isset($p_gunid)) {
         throw new Exception("You should never use gunid ({$gunid}) anymore");
     } elseif (isset($p_md5sum)) {
         throw new Exception("Searching by md5({$p_md5sum}) is disabled");
     } elseif (isset($p_filepath)) {
         return is_null($f) ? null : self::createWithFile(Application_Model_StoredFile::RecallByFilepath($p_filepath));
     } else {
         throw new Exception("No arguments passsed to Recall");
     }
 }
 public static function GetSystemInfo($returnArray = false, $p_testing = false)
 {
     exec('/usr/bin/airtime-check-system --no-color', $output);
     $output = preg_replace('/\\s+/', ' ', $output);
     $systemInfoArray = array();
     foreach ($output as $key => &$out) {
         $info = explode('=', $out);
         if (isset($info[1])) {
             $key = str_replace(' ', '_', trim($info[0]));
             $key = strtoupper($key);
             if ($key == 'WEB_SERVER' || $key == 'CPU' || $key == 'OS' || $key == 'TOTAL_RAM' || $key == 'FREE_RAM' || $key == 'AIRTIME_VERSION' || $key == 'KERNAL_VERSION' || $key == 'MACHINE_ARCHITECTURE' || $key == 'TOTAL_MEMORY_MBYTES' || $key == 'TOTAL_SWAP_MBYTES' || $key == 'PLAYOUT_ENGINE_CPU_PERC') {
                 if ($key == 'AIRTIME_VERSION') {
                     // remove hash tag on the version string
                     $version = explode('+', $info[1]);
                     $systemInfoArray[$key] = $version[0];
                 } else {
                     $systemInfoArray[$key] = $info[1];
                 }
             }
         }
     }
     $outputArray = array();
     $outputArray['LIVE_DURATION'] = Application_Model_LiveLog::GetLiveShowDuration($p_testing);
     $outputArray['SCHEDULED_DURATION'] = Application_Model_LiveLog::GetScheduledDuration($p_testing);
     $outputArray['SOUNDCLOUD_ENABLED'] = self::GetUploadToSoundcloudOption();
     if ($outputArray['SOUNDCLOUD_ENABLED']) {
         $outputArray['NUM_SOUNDCLOUD_TRACKS_UPLOADED'] = Application_Model_StoredFile::getSoundCloudUploads();
     } else {
         $outputArray['NUM_SOUNDCLOUD_TRACKS_UPLOADED'] = NULL;
     }
     $outputArray['STATION_NAME'] = self::GetStationName();
     $outputArray['PHONE'] = self::GetPhone();
     $outputArray['EMAIL'] = self::GetEmail();
     $outputArray['STATION_WEB_SITE'] = self::GetStationWebSite();
     $outputArray['STATION_COUNTRY'] = self::GetStationCountry();
     $outputArray['STATION_CITY'] = self::GetStationCity();
     $outputArray['STATION_DESCRIPTION'] = self::GetStationDescription();
     // get web server info
     if (isset($systemInfoArray["AIRTIME_VERSION_URL"])) {
         $url = $systemInfoArray["AIRTIME_VERSION_URL"];
         $index = strpos($url, '/api/');
         $url = substr($url, 0, $index);
         $headerInfo = get_headers(trim($url), 1);
         $outputArray['WEB_SERVER'] = $headerInfo['Server'][0];
     }
     $outputArray['NUM_OF_USERS'] = Application_Model_User::getUserCount();
     $outputArray['NUM_OF_SONGS'] = Application_Model_StoredFile::getFileCount();
     $outputArray['NUM_OF_PLAYLISTS'] = Application_Model_Playlist::getPlaylistCount();
     $outputArray['NUM_OF_SCHEDULED_PLAYLISTS'] = Application_Model_Schedule::getSchduledPlaylistCount();
     $outputArray['NUM_OF_PAST_SHOWS'] = Application_Model_ShowInstance::GetShowInstanceCount(gmdate("Y-m-d H:i:s"));
     $outputArray['UNIQUE_ID'] = self::GetUniqueId();
     $outputArray['SAAS'] = self::GetPlanLevel();
     if ($outputArray['SAAS'] != 'disabled') {
         $outputArray['TRIAL_END_DATE'] = self::GetTrialEndingDate();
     } else {
         $outputArray['TRIAL_END_DATE'] = NULL;
     }
     $outputArray['INSTALL_METHOD'] = self::GetInstallMethod();
     $outputArray['NUM_OF_STREAMS'] = self::GetNumOfStreams();
     $outputArray['STREAM_INFO'] = Application_Model_StreamSetting::getStreamInfoForDataCollection();
     $outputArray = array_merge($systemInfoArray, $outputArray);
     $outputString = "\n";
     foreach ($outputArray as $key => $out) {
         if ($key == 'TRIAL_END_DATE' && ($out != '' || $out != 'NULL')) {
             continue;
         }
         if ($key == "STREAM_INFO") {
             $outputString .= $key . " :\n";
             foreach ($out as $s_info) {
                 foreach ($s_info as $k => $v) {
                     $outputString .= "\t" . strtoupper($k) . " : " . $v . "\n";
                 }
             }
         } elseif ($key == "SOUNDCLOUD_ENABLED") {
             if ($out) {
                 $outputString .= $key . " : TRUE\n";
             } elseif (!$out) {
                 $outputString .= $key . " : FALSE\n";
             }
         } elseif ($key == "SAAS") {
             if (strcmp($out, 'disabled') != 0) {
                 $outputString .= $key . ' : ' . $out . "\n";
             }
         } else {
             $outputString .= $key . ' : ' . $out . "\n";
         }
     }
     if ($returnArray) {
         $outputArray['PROMOTE'] = self::GetPublicise();
         $outputArray['LOGOIMG'] = self::GetStationLogo();
         return $outputArray;
     } else {
         return $outputString;
     }
 }
 public static function searchLibraryFiles($datatables)
 {
     $baseUrl = Application_Common_OsPath::getBaseDir();
     $con = Propel::getConnection(CcFilesPeer::DATABASE_NAME);
     $displayColumns = self::getLibraryColumns();
     $plSelect = array();
     $blSelect = array();
     $fileSelect = array();
     $streamSelect = array();
     foreach ($displayColumns as $key) {
         if ($key === "id") {
             $plSelect[] = "PL.id AS " . $key;
             $blSelect[] = "BL.id AS " . $key;
             $fileSelect[] = "FILES.id AS {$key}";
             $streamSelect[] = "ws.id AS " . $key;
         } elseif ($key === "track_title") {
             $plSelect[] = "name AS " . $key;
             $blSelect[] = "name AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = "name AS " . $key;
         } elseif ($key === "ftype") {
             $plSelect[] = "'playlist'::varchar AS " . $key;
             $blSelect[] = "'block'::varchar AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = "'stream'::varchar AS " . $key;
         } elseif ($key === "artist_name") {
             $plSelect[] = "login AS " . $key;
             $blSelect[] = "login AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = "login AS " . $key;
         } elseif ($key === "owner_id") {
             $plSelect[] = "login AS " . $key;
             $blSelect[] = "login AS " . $key;
             $fileSelect[] = "sub.login AS {$key}";
             $streamSelect[] = "login AS " . $key;
         } elseif ($key === "replay_gain") {
             $plSelect[] = "NULL::NUMERIC AS " . $key;
             $blSelect[] = "NULL::NUMERIC AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = "NULL::NUMERIC AS " . $key;
         } elseif ($key === "lptime") {
             $plSelect[] = "NULL::TIMESTAMP AS " . $key;
             $blSelect[] = "NULL::TIMESTAMP AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = $key;
         } elseif ($key === "is_scheduled" || $key === "is_playlist") {
             $plSelect[] = "NULL::boolean AS " . $key;
             $blSelect[] = "NULL::boolean AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = "NULL::boolean AS " . $key;
         } elseif ($key === "cuein" || $key === "cueout") {
             $plSelect[] = "NULL::INTERVAL AS " . $key;
             $blSelect[] = "NULL::INTERVAL AS " . $key;
             $fileSelect[] = $key;
             $streamSelect[] = "NULL::INTERVAL AS " . $key;
         } else {
             if ($key === "length") {
                 $plSelect[] = $key;
                 $blSelect[] = $key;
                 $fileSelect[] = "(cueout - cuein)::INTERVAL AS length";
                 $streamSelect[] = $key;
             } else {
                 if (in_array($key, array("utime", "mtime"))) {
                     $plSelect[] = $key;
                     $blSelect[] = $key;
                     $fileSelect[] = $key;
                     $streamSelect[] = $key;
                 } elseif ($key === "year") {
                     $plSelect[] = "EXTRACT(YEAR FROM utime)::varchar AS " . $key;
                     $blSelect[] = "EXTRACT(YEAR FROM utime)::varchar AS " . $key;
                     $fileSelect[] = "year AS " . $key;
                     $streamSelect[] = "EXTRACT(YEAR FROM utime)::varchar AS " . $key;
                 } else {
                     if (in_array($key, array("track_number", "bit_rate", "sample_rate", "bpm"))) {
                         $plSelect[] = "NULL::int AS " . $key;
                         $blSelect[] = "NULL::int AS " . $key;
                         $fileSelect[] = $key;
                         $streamSelect[] = "NULL::int AS " . $key;
                     } elseif ($key === "filepath") {
                         $plSelect[] = "NULL::VARCHAR AS " . $key;
                         $blSelect[] = "NULL::VARCHAR AS " . $key;
                         $fileSelect[] = $key;
                         $streamSelect[] = "url AS " . $key;
                     } else {
                         if ($key == "mime") {
                             $plSelect[] = "NULL::VARCHAR AS " . $key;
                             $blSelect[] = "NULL::VARCHAR AS " . $key;
                             $fileSelect[] = $key;
                             $streamSelect[] = $key;
                         } else {
                             $plSelect[] = "NULL::text AS " . $key;
                             $blSelect[] = "NULL::text AS " . $key;
                             $fileSelect[] = $key;
                             $streamSelect[] = "NULL::text AS " . $key;
                         }
                     }
                 }
             }
         }
     }
     $plSelect = "SELECT " . join(",", $plSelect);
     $blSelect = "SELECT " . join(",", $blSelect);
     $fileSelect = "SELECT " . join(",", $fileSelect);
     $streamSelect = "SELECT " . join(",", $streamSelect);
     $type = intval($datatables["type"]);
     $plTable = "({$plSelect} FROM cc_playlist AS PL LEFT JOIN cc_subjs AS sub ON (sub.id = PL.creator_id))";
     $blTable = "({$blSelect} FROM cc_block AS BL LEFT JOIN cc_subjs AS sub ON (sub.id = BL.creator_id))";
     $fileTable = "({$fileSelect} FROM cc_files AS FILES LEFT JOIN cc_subjs AS sub ON (sub.id = FILES.owner_id) WHERE file_exists = 'TRUE' AND hidden='FALSE')";
     //$fileTable = "({$fileSelect} FROM cc_files AS FILES WHERE file_exists = 'TRUE')";
     $streamTable = "({$streamSelect} FROM cc_webstream AS ws LEFT JOIN cc_subjs AS sub ON (sub.id = ws.creator_id))";
     $unionTable = "({$plTable} UNION {$blTable} UNION {$fileTable} UNION {$streamTable}) AS RESULTS";
     //choose which table we need to select data from.
     // TODO : use constants instead of numbers -- RG
     switch ($type) {
         case 0:
             $fromTable = $unionTable;
             break;
         case 1:
             $fromTable = $fileTable . " AS File";
             //need an alias for the table if it's standalone.
             break;
         case 2:
             $fromTable = $plTable . " AS Playlist";
             //need an alias for the table if it's standalone.
             break;
         case 3:
             $fromTable = $blTable . " AS Block";
             //need an alias for the table if it's standalone.
             break;
         case 4:
             $fromTable = $streamTable . " AS StreamTable";
             //need an alias for the table if it's standalone.
             break;
         default:
             $fromTable = $unionTable;
     }
     // update is_scheduled to false for tracks that
     // have already played out
     self::updatePastFilesIsScheduled();
     $results = Application_Model_Datatables::findEntries($con, $displayColumns, $fromTable, $datatables);
     $displayTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
     $utcTimezone = new DateTimeZone("UTC");
     foreach ($results['aaData'] as &$row) {
         $row['id'] = intval($row['id']);
         //taken from Datatables.php, needs to be cleaned up there.
         if (isset($r['ftype'])) {
             if ($r['ftype'] == 'playlist') {
                 $pl = new Application_Model_Playlist($r['id']);
                 $r['length'] = $pl->getLength();
             } elseif ($r['ftype'] == "block") {
                 $bl = new Application_Model_Block($r['id']);
                 $r['bl_type'] = $bl->isStatic() ? 'static' : 'dynamic';
                 $r['length'] = $bl->getLength();
             }
         }
         if ($row['ftype'] === "audioclip") {
             $cuein_formatter = new LengthFormatter($row["cuein"]);
             $row["cuein"] = $cuein_formatter->format();
             $cueout_formatter = new LengthFormatter($row["cueout"]);
             $row["cueout"] = $cueout_formatter->format();
             $cuein = Application_Common_DateHelper::playlistTimeToSeconds($row["cuein"]);
             $cueout = Application_Common_DateHelper::playlistTimeToSeconds($row["cueout"]);
             $row_length = Application_Common_DateHelper::secondsToPlaylistTime($cueout - $cuein);
             $formatter = new SamplerateFormatter($row['sample_rate']);
             $row['sample_rate'] = $formatter->format();
             $formatter = new BitrateFormatter($row['bit_rate']);
             $row['bit_rate'] = $formatter->format();
             //soundcloud status
             $file = Application_Model_StoredFile::RecallById($row['id']);
             $row['soundcloud_id'] = $file->getSoundCloudId();
             // for audio preview
             $row['audioFile'] = $row['id'] . "." . pathinfo($row['filepath'], PATHINFO_EXTENSION);
         } else {
             $row['audioFile'] = $row['id'];
             $row_length = $row['length'];
         }
         $len_formatter = new LengthFormatter($row_length);
         $row['length'] = $len_formatter->format();
         //convert mtime and utime to localtime
         $row['mtime'] = new DateTime($row['mtime'], $utcTimezone);
         $row['mtime']->setTimeZone($displayTimezone);
         $row['mtime'] = $row['mtime']->format('Y-m-d H:i:s');
         $row['utime'] = new DateTime($row['utime'], $utcTimezone);
         $row['utime']->setTimeZone($displayTimezone);
         $row['utime'] = $row['utime']->format('Y-m-d H:i:s');
         //need to convert last played to localtime if it exists.
         if (isset($row['lptime'])) {
             $row['lptime'] = new DateTime($row['lptime'], $utcTimezone);
             $row['lptime']->setTimeZone($displayTimezone);
             $row['lptime'] = $row['lptime']->format('Y-m-d H:i:s');
         }
         // we need to initalize the checkbox and image row because we do not retrieve
         // any data from the db for these and datatables will complain
         $row['checkbox'] = "";
         $row['image'] = "";
         $type = substr($row['ftype'], 0, 2);
         $row['tr_id'] = "{$type}_{$row['id']}";
     }
     return $results;
 }
Exemple #23
0
 public function getRecordedFile()
 {
     $file_id = $this->_showInstance->getDbRecordedFile();
     if (isset($file_id)) {
         $file = Application_Model_StoredFile::Recall($file_id);
         if (isset($file) && file_exists($file->getFilePath())) {
             return $file;
         }
     }
     return null;
 }
Exemple #24
0
 public static function setCurrentLibraryTableSetting($settings)
 {
     $num_columns = count(Application_Model_StoredFile::getLibraryColumns());
     $new_columns_num = count($settings['abVisCols']);
     if ($num_columns != $new_columns_num) {
         throw new Exception("Trying to write a user column preference with incorrect number of columns!");
     }
     $data = serialize($settings);
     $v = self::setValue("library_datatable", $data, true);
 }