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 = StoredFile::Recall($file_id);
     $url = $file->getFileURL() . '/api_key/' . $CC_CONFIG["apiKey"][0] . '/download/true';
     $menu[] = array('action' => array('type' => 'gourl', 'url' => $url), 'title' => 'Download');
     //returns format jjmenu is looking for.
     die(json_encode($menu));
 }
Exemple #2
0
 /**
  *  Add audio clip to the playlist
  *
  * @param string $p_id
  * 		local ID of added file
  * @param string $p_position
  *    optional, Which position in the playlist to insert the audio clip
  * @param string $p_fadeIn
  * 		optional, in time format hh:mm:ss.ssssss - total duration
  * @param string $p_fadeOut
  * 		optional, in time format hh:mm:ss.ssssss - total duration
  * @param string $p_clipLength
  * 		optional length in in time format hh:mm:ss.ssssss -
  *      for webstream (or for overrule length of audioclip)
  * @return true|PEAR_Error
  * 		TRUE on success
  */
 public function addAudioClip($p_mediaId, $p_position = NULL, $p_fadeIn = NULL, $p_fadeOut = NULL, $p_clipLength = NULL, $p_cuein = NULL, $p_cueout = NULL)
 {
     //get audio clip.
     $media = StoredFile::Recall($p_mediaId);
     if (is_null($media) || PEAR::isError($media)) {
         return $media;
     }
     $metadata = $media->getMetadata();
     $length = $metadata['MDATA_KEY_DURATION'];
     if (!is_null($p_clipLength)) {
         $length = $p_clipLength;
     }
     // 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;
     $con = Propel::getConnection(CcPlaylistPeer::DATABASE_NAME);
     $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;
 }
Exemple #3
0
 /**
  * Export the schedule in json formatted for pypo (the liquidsoap scheduler)
  *
  * @param string $p_fromDateTime
  *      In the format "YYYY-MM-DD-HH-mm-SS"
  * @param string $p_toDateTime
  *      In the format "YYYY-MM-DD-HH-mm-SS"
  */
 public static function GetScheduledPlaylists($p_fromDateTime = null, $p_toDateTime = null)
 {
     global $CC_CONFIG, $CC_DBC;
     if (is_null($p_fromDateTime)) {
         $t1 = new DateTime();
         $range_start = $t1->format("Y-m-d H:i:s");
     } else {
         $range_start = Schedule::PypoTimeToAirtimeTime($p_fromDateTime);
     }
     if (is_null($p_fromDateTime)) {
         $t2 = new DateTime();
         $t2->add(new DateInterval("PT24H"));
         $range_end = $t2->format("Y-m-d H:i:s");
     } else {
         $range_end = Schedule::PypoTimeToAirtimeTime($p_toDateTime);
     }
     // Scheduler wants everything in a playlist
     $data = Schedule::GetItems($range_start, $range_end, true);
     $playlists = array();
     if (is_array($data)) {
         foreach ($data as $dx) {
             $start = $dx['start'];
             //chop off subseconds
             $start = substr($start, 0, 19);
             //Start time is the array key, needs to be in the format "YYYY-MM-DD-HH-mm-ss"
             $pkey = Schedule::AirtimeTimeToPypoTime($start);
             $timestamp = strtotime($start);
             $playlists[$pkey]['source'] = "PLAYLIST";
             $playlists[$pkey]['x_ident'] = $dx['group_id'];
             //$playlists[$pkey]['subtype'] = '1'; // Just needs to be between 1 and 4 inclusive
             $playlists[$pkey]['timestamp'] = $timestamp;
             $playlists[$pkey]['duration'] = $dx['clip_length'];
             $playlists[$pkey]['played'] = '0';
             $playlists[$pkey]['schedule_id'] = $dx['group_id'];
             $playlists[$pkey]['show_name'] = $dx['show_name'];
             $playlists[$pkey]['show_start'] = Schedule::AirtimeTimeToPypoTime($dx['show_start']);
             $playlists[$pkey]['show_end'] = Schedule::AirtimeTimeToPypoTime($dx['show_end']);
             $playlists[$pkey]['user_id'] = 0;
             $playlists[$pkey]['id'] = $dx['group_id'];
             $playlists[$pkey]['start'] = Schedule::AirtimeTimeToPypoTime($dx["start"]);
             $playlists[$pkey]['end'] = Schedule::AirtimeTimeToPypoTime($dx["end"]);
         }
     }
     foreach ($playlists as &$playlist) {
         $scheduleGroup = new ScheduleGroup($playlist["schedule_id"]);
         $items = $scheduleGroup->getItems();
         $medias = array();
         foreach ($items as $item) {
             $storedFile = StoredFile::Recall($item["file_id"]);
             $uri = $storedFile->getFileUrl();
             $starts = Schedule::AirtimeTimeToPypoTime($item["starts"]);
             $medias[$starts] = array('row_id' => $item["id"], 'id' => $storedFile->getGunid(), 'uri' => $uri, 'fade_in' => Schedule::WallTimeToMillisecs($item["fade_in"]), 'fade_out' => Schedule::WallTimeToMillisecs($item["fade_out"]), 'fade_cross' => 0, 'cue_in' => DateHelper::CalculateLengthInSeconds($item["cue_in"]), 'cue_out' => DateHelper::CalculateLengthInSeconds($item["cue_out"]), 'export_source' => 'scheduler', 'start' => $starts, 'end' => Schedule::AirtimeTimeToPypoTime($item["ends"]));
         }
         $playlist['medias'] = $medias;
     }
     $result = array();
     $result['status'] = array('range' => array('start' => $range_start, 'end' => $range_end), 'version' => AIRTIME_REST_VERSION);
     $result['playlists'] = $playlists;
     $result['check'] = 1;
     $result['stream_metadata'] = array();
     $result['stream_metadata']['format'] = Application_Model_Preference::GetStreamLabelFormat();
     $result['stream_metadata']['station_name'] = Application_Model_Preference::GetStationName();
     $result['server_timezone'] = date('O');
     return $result;
 }
Exemple #4
0
 /**
  * Fetch the StoredFile by looking up its filepath.
  *
  * @param string $p_filepath path of file stored in Airtime.
  * @return StoredFile|NULL
  */
 public static function RecallByFilepath($p_filepath)
 {
     return StoredFile::Recall(null, null, null, $p_filepath);
 }
Exemple #5
0
 public function getRecordedFile()
 {
     $file_id = $this->_showInstance->getDbRecordedFile();
     if (isset($file_id)) {
         $file = StoredFile::Recall($file_id);
         if (PEAR::isError($file)) {
             return null;
         }
         if (file_exists($file->getFilePath())) {
             return $file;
         }
     }
     return null;
 }
 public function uploadRecordedAction()
 {
     global $CC_CONFIG;
     $api_key = $this->_getParam('api_key');
     if (!in_array($api_key, $CC_CONFIG["apiKey"])) {
         header('HTTP/1.0 401 Unauthorized');
         print 'You are not allowed to access this resource.';
         exit;
     }
     //this file id is the recording for this show instance.
     $show_instance_id = $this->_getParam('showinstanceid');
     $file_id = $this->_getParam('fileid');
     $this->view->fileid = $file_id;
     $this->view->showinstanceid = $show_instance_id;
     $showCanceled = false;
     $file = StoredFile::Recall($file_id);
     //$show_instance  = $this->_getParam('show_instance');
     $show_name = null;
     try {
         $show_inst = new ShowInstance($show_instance_id);
         $show_inst->setRecordedFile($file_id);
         $show_name = $show_inst->getName();
         $show_genre = $show_inst->getGenre();
         $show_start_time = $show_inst->getShowStart();
     } catch (Exception $e) {
         //we've reached here probably because the show was
         //cancelled, and therefore the show instance does not
         //exist anymore (ShowInstance constructor threw this error).
         //We've done all we can do (upload the file and put it in
         //the library), now lets just return.
         $showCanceled = true;
     }
     if (isset($show_name)) {
         $tmpTitle = "{$show_name}-{$show_start_time}";
         $tmpTitle = str_replace(" ", "-", $tmpTitle);
     } else {
         $tmpTitle = $file->getName();
     }
     $file->setMetadataValue('MDATA_KEY_TITLE', $tmpTitle);
     $file->setMetadataValue('MDATA_KEY_CREATOR', "Airtime Show Recorder");
     $file->setMetadataValue('MDATA_KEY_TRACKNUMBER', null);
     if (!$showCanceled && Application_Model_Preference::GetDoSoundCloudUpload()) {
         for ($i = 0; $i < $CC_CONFIG['soundcloud-connection-retries']; $i++) {
             $show = new Show($show_inst->getShowId());
             $description = $show->getDescription();
             $hosts = $show->getHosts();
             $tags = array_merge($hosts, array($show_name));
             try {
                 $soundcloud = new ATSoundcloud();
                 $soundcloud_id = $soundcloud->uploadTrack($file->getFilePath(), $tmpTitle, $description, $tags, $show_start_time, $show_genre);
                 $show_inst->setSoundCloudFileId($soundcloud_id);
                 break;
             } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
                 $code = $e->getHttpCode();
                 if (!in_array($code, array(0, 100))) {
                     break;
                 }
             }
             sleep($CC_CONFIG['soundcloud-connection-wait']);
         }
     }
     $this->view->id = $file_id;
 }
 public function getFileMetaDataAction()
 {
     $id = $this->_getParam('id');
     $type = $this->_getParam('type');
     if ($type == "au") {
         $file = StoredFile::Recall($id);
         $this->view->type = $type;
         $this->view->md = $file->getMetadata();
     } else {
         if ($type == "pl") {
             $file = Playlist::Recall($id);
             $this->view->type = $type;
             $this->view->md = $file->getAllPLMetaData();
             $this->view->contents = $file->getContents();
         }
     }
 }