Example #1
0
 public function getCueLength()
 {
     $cuein = $this->getDbCuein();
     $cueout = $this->getDbCueout();
     $cueinSec = Application_Common_DateHelper::calculateLengthInSeconds($cuein);
     $cueoutSec = Application_Common_DateHelper::calculateLengthInSeconds($cueout);
     $lengthSec = bcsub($cueoutSec, $cueinSec, 6);
     $length = Application_Common_DateHelper::secondsToPlaylistTime($lengthSec);
     return $length;
 }
Example #2
0
 private function retrieveMediaFiles($id, $type)
 {
     $files = array();
     if ($type === "audioclip") {
         $file = CcFilesQuery::create()->findPK($id, $this->con);
         if (is_null($file) || !$file->visible()) {
             throw new Exception(_("A selected File does not exist!"));
         } else {
             $data = $this->fileInfo;
             $data["id"] = $id;
             $cuein = Application_Common_DateHelper::playlistTimeToSeconds($file->getDbCuein());
             $cueout = Application_Common_DateHelper::playlistTimeToSeconds($file->getDbCueout());
             $row_length = Application_Common_DateHelper::secondsToPlaylistTime($cueout - $cuein);
             $data["cliplength"] = $row_length;
             $data["cuein"] = $file->getDbCuein();
             $data["cueout"] = $file->getDbCueout();
             //fade is in format SS.uuuuuu
             $data["fadein"] = Application_Model_Preference::GetDefaultFadeIn();
             $data["fadeout"] = Application_Model_Preference::GetDefaultFadeOut();
             $files[] = $data;
         }
     } elseif ($type === "playlist") {
         $pl = new Application_Model_Playlist($id);
         $contents = $pl->getContents();
         foreach ($contents as $plItem) {
             if ($plItem['type'] == 0) {
                 $data["id"] = $plItem['item_id'];
                 $data["cliplength"] = $plItem['length'];
                 $data["cuein"] = $plItem['cuein'];
                 $data["cueout"] = $plItem['cueout'];
                 $data["fadein"] = $plItem['fadein'];
                 $data["fadeout"] = $plItem['fadeout'];
                 $data["type"] = 0;
                 $files[] = $data;
             } elseif ($plItem['type'] == 1) {
                 $data["id"] = $plItem['item_id'];
                 $data["cliplength"] = $plItem['length'];
                 $data["cuein"] = $plItem['cuein'];
                 $data["cueout"] = $plItem['cueout'];
                 $data["fadein"] = "00.500000";
                 //$plItem['fadein'];
                 $data["fadeout"] = "00.500000";
                 //$plItem['fadeout'];
                 $data["type"] = 1;
                 $files[] = $data;
             } elseif ($plItem['type'] == 2) {
                 // if it's a block
                 $bl = new Application_Model_Block($plItem['item_id']);
                 if ($bl->isStatic()) {
                     foreach ($bl->getContents() as $track) {
                         $data["id"] = $track['item_id'];
                         $data["cliplength"] = $track['length'];
                         $data["cuein"] = $track['cuein'];
                         $data["cueout"] = $track['cueout'];
                         $data["fadein"] = $track['fadein'];
                         $data["fadeout"] = $track['fadeout'];
                         $data["type"] = 0;
                         $files[] = $data;
                     }
                 } else {
                     $defaultFadeIn = Application_Model_Preference::GetDefaultFadeIn();
                     $defaultFadeOut = Application_Model_Preference::GetDefaultFadeOut();
                     $dynamicFiles = $bl->getListOfFilesUnderLimit();
                     foreach ($dynamicFiles as $f) {
                         $fileId = $f['id'];
                         $file = CcFilesQuery::create()->findPk($fileId);
                         if (isset($file) && $file->visible()) {
                             $data["id"] = $file->getDbId();
                             $data["cuein"] = $file->getDbCuein();
                             $data["cueout"] = $file->getDbCueout();
                             $cuein = Application_Common_DateHelper::calculateLengthInSeconds($data["cuein"]);
                             $cueout = Application_Common_DateHelper::calculateLengthInSeconds($data["cueout"]);
                             $data["cliplength"] = Application_Common_DateHelper::secondsToPlaylistTime($cueout - $cuein);
                             //fade is in format SS.uuuuuu
                             $data["fadein"] = $defaultFadeIn;
                             $data["fadeout"] = $defaultFadeOut;
                             $data["type"] = 0;
                             $files[] = $data;
                         }
                     }
                 }
             }
         }
     } elseif ($type == "stream") {
         //need to return
         $stream = CcWebstreamQuery::create()->findPK($id, $this->con);
         if (is_null($stream)) {
             throw new Exception(_("A selected File does not exist!"));
         } else {
             $data = $this->fileInfo;
             $data["id"] = $id;
             $data["cliplength"] = $stream->getDbLength();
             $data["cueout"] = $stream->getDbLength();
             $data["type"] = 1;
             //fade is in format SS.uuuuuu
             $data["fadein"] = Application_Model_Preference::GetDefaultFadeIn();
             $data["fadeout"] = Application_Model_Preference::GetDefaultFadeOut();
             $files[] = $data;
         }
     } elseif ($type == "block") {
         $bl = new Application_Model_Block($id);
         if ($bl->isStatic()) {
             foreach ($bl->getContents() as $track) {
                 $data["id"] = $track['item_id'];
                 $data["cliplength"] = $track['length'];
                 $data["cuein"] = $track['cuein'];
                 $data["cueout"] = $track['cueout'];
                 $data["fadein"] = $track['fadein'];
                 $data["fadeout"] = $track['fadeout'];
                 $data["type"] = 0;
                 $files[] = $data;
             }
         } else {
             $defaultFadeIn = Application_Model_Preference::GetDefaultFadeIn();
             $defaultFadeOut = Application_Model_Preference::GetDefaultFadeOut();
             $dynamicFiles = $bl->getListOfFilesUnderLimit();
             foreach ($dynamicFiles as $f) {
                 $fileId = $f['id'];
                 $file = CcFilesQuery::create()->findPk($fileId);
                 if (isset($file) && $file->visible()) {
                     $data["id"] = $file->getDbId();
                     $data["cuein"] = $file->getDbCuein();
                     $data["cueout"] = $file->getDbCueout();
                     $cuein = Application_Common_DateHelper::calculateLengthInSeconds($data["cuein"]);
                     $cueout = Application_Common_DateHelper::calculateLengthInSeconds($data["cueout"]);
                     $data["cliplength"] = Application_Common_DateHelper::secondsToPlaylistTime($cueout - $cuein);
                     //fade is in format SS.uuuuuu
                     $data["fadein"] = $defaultFadeIn;
                     $data["fadeout"] = $defaultFadeOut;
                     $data["type"] = 0;
                     $files[] = $data;
                 }
             }
         }
     }
     return $files;
 }
Example #3
0
 private function buildEntry($p_item, $pos)
 {
     $objType = $p_item[1];
     $objId = $p_item[0];
     if ($objType == 'audioclip') {
         $obj = CcFilesQuery::create()->findPK($objId, $this->con);
     } elseif ($objType == "stream") {
         $obj = CcWebstreamQuery::create()->findPK($objId, $this->con);
     } elseif ($objType == "block") {
         $obj = CcBlockQuery::create()->findPK($objId, $this->con);
     } else {
         throw new Exception("Unknown file type");
     }
     if (isset($obj)) {
         if ($obj instanceof CcFiles && $obj->visible() || $obj instanceof CcWebstream || $obj instanceof CcBlock) {
             $entry = $this->plItem;
             $entry["id"] = $obj->getDbId();
             $entry["pos"] = $pos;
             $entry["cliplength"] = $obj->getDbLength();
             if ($obj instanceof CcFiles && $obj) {
                 $entry["cuein"] = isset($p_item['cuein']) ? $p_item['cuein'] : $obj->getDbCuein();
                 $entry["cueout"] = isset($p_item['cueout']) ? $p_item['cueout'] : $obj->getDbCueout();
                 $cue_in = isset($p_item['cueInSec']) ? $p_item['cueInSec'] : Application_Common_DateHelper::calculateLengthInSeconds($entry['cuein']);
                 $cue_out = isset($p_item['cueOutSec']) ? $p_item['cueOutSec'] : Application_Common_DateHelper::calculateLengthInSeconds($entry['cueout']);
                 $entry["cliplength"] = isset($p_item['length']) ? $p_item['length'] : Application_Common_DateHelper::secondsToPlaylistTime($cue_out - $cue_in);
             } elseif ($obj instanceof CcWebstream && $obj) {
                 $entry["cuein"] = "00:00:00";
                 $entry["cueout"] = $entry["cliplength"];
             }
             $entry["ftype"] = $objType;
             $entry["fadein"] = isset($p_item['fadein']) ? $p_item['fadein'] : $entry["fadein"];
             $entry["fadeout"] = isset($p_item['fadeout']) ? $p_item['fadeout'] : $entry["fadeout"];
         }
         return $entry;
     } else {
         throw new Exception("trying to add a object that does not exist.");
     }
 }
Example #4
0
 public function getListOfFilesUnderLimit()
 {
     $info = $this->getListofFilesMeetCriteria();
     $files = $info['files'];
     $limit = $info['limit'];
     $insertList = array();
     $totalTime = 0;
     $totalItems = 0;
     // this moves the pointer to the first element in the collection
     $files->getFirst();
     $iterator = $files->getIterator();
     while ($iterator->valid() && $totalTime < $limit['time']) {
         $id = $iterator->current()->getDbId();
         $length = Application_Common_DateHelper::calculateLengthInSeconds($iterator->current()->getDbLength());
         $insertList[$id] = $length;
         $totalTime += $length;
         $totalItems++;
         if (!is_null($limit['items']) && $limit['items'] == count($insertList) || $totalItems > 500) {
             break;
         }
         $iterator->next();
     }
     return $insertList;
 }
Example #5
0
 public function getListOfFilesUnderLimit()
 {
     $info = $this->getListofFilesMeetCriteria();
     $files = $info['files'];
     $limit = $info['limit'];
     $repeat = $info['repeat_tracks'];
     $insertList = array();
     $totalTime = 0;
     $totalItems = 0;
     // this moves the pointer to the first element in the collection
     $files->getFirst();
     $iterator = $files->getIterator();
     $isBlockFull = false;
     while ($iterator->valid()) {
         $id = $iterator->current()->getDbId();
         $fileLength = $iterator->current()->getCueLength();
         $length = Application_Common_DateHelper::calculateLengthInSeconds($fileLength);
         $insertList[] = array('id' => $id, 'length' => $length);
         $totalTime += $length;
         $totalItems++;
         if (!is_null($limit['items']) && $limit['items'] == count($insertList) || $totalItems > 500 || $totalTime > $limit['time']) {
             $isBlockFull = true;
             break;
         }
         $iterator->next();
     }
     $sizeOfInsert = count($insertList);
     // if block is not full and repeat_track is check, fill up more
     while (!$isBlockFull && $repeat == 1 && $sizeOfInsert > 0) {
         Logging::debug("adding repeated tracks.");
         Logging::debug("total time = " . $totalTime);
         $randomEleKey = array_rand(array_slice($insertList, 0, $sizeOfInsert));
         $insertList[] = $insertList[$randomEleKey];
         $totalTime += $insertList[$randomEleKey]['length'];
         $totalItems++;
         if (!is_null($limit['items']) && $limit['items'] == count($insertList) || $totalItems > 500 || $totalTime > $limit['time']) {
             break;
         }
     }
     return $insertList;
 }
Example #6
0
 /**
  * Set multiple metadata values using defined metadata constants.
  *
  * @param array $p_md
  *  example: $p_md['MDATA_KEY_URL'] = 'http://www.fake.com'
  */
 public function setMetadata($p_md = null)
 {
     if (is_null($p_md)) {
         $this->setDbColMetadata();
     } else {
         $dbMd = array();
         if (isset($p_md["MDATA_KEY_YEAR"])) {
             // We need to make sure to clean this value before
             // inserting into database. If value is outside of range
             // [-2^31, 2^31-1] then postgresl will throw error when
             // trying to retrieve this value. We could make sure
             // number is within these bounds, but simplest is to do
             // substring to 4 digits (both values are garbage, but
             // at least our new garbage value won't cause errors).
             // If the value is 2012-01-01, then substring to first 4
             // digits is an OK result. CC-3771
             $year = $p_md["MDATA_KEY_YEAR"];
             if (strlen($year) > 4) {
                 $year = substr($year, 0, 4);
             }
             if (!is_numeric($year)) {
                 $year = 0;
             }
             $p_md["MDATA_KEY_YEAR"] = $year;
         }
         # Translate metadata attributes from media monitor (MDATA_KEY_*)
         # to their counterparts in constants.php (usually the column names)
         $track_length = $p_md['MDATA_KEY_DURATION'];
         $track_length_in_sec = Application_Common_DateHelper::calculateLengthInSeconds($track_length);
         foreach ($p_md as $mdConst => $mdValue) {
             if (defined($mdConst)) {
                 if ($mdConst == "MDATA_KEY_CUE_OUT") {
                     if ($mdValue == '0.0') {
                         $mdValue = $track_length_in_sec;
                     } else {
                         $this->_file->setDbSilanCheck(true)->save();
                     }
                 }
                 $dbMd[constant($mdConst)] = $mdValue;
             }
         }
         $this->setDbColMetadata($dbMd);
     }
 }