function createTestShow($showNumber, $showTime, $duration = "1:00") { $data = array(); $strTime = $showTime->format("Y-m-d H:i"); echo "Adding show: {$strTime}\n"; $data['add_show_name'] = 'automated show ' . $showNumber; $data['add_show_start_date'] = $showTime->format("Y-m-d"); $data['add_show_start_time'] = $showTime->format("H:i"); $data['add_show_duration'] = $duration; $data['add_show_no_end'] = 0; $data['add_show_repeats'] = 0; $data['add_show_description'] = 'automated show'; $data['add_show_url'] = 'http://www.OfirGal.com'; $data['add_show_color'] = ""; $data['add_show_genre'] = "Ofir"; $data['add_show_background_color'] = ""; $data['add_show_record'] = 0; $data['add_show_hosts'] = ""; $showId = Application_Model_Show::create($data); //echo "show created, ID: $showId\n"; // populating the show with a playlist $instances = Application_Model_Show::getShows($showTime, $showTime); $instance = array_pop($instances); $show = new Application_Model_ShowInstance($instance["instance_id"]); //echo "Adding playlist to show instance ".$show->getShowInstanceId()."\n"; $show->scheduleShow(array(1)); //echo "done\n"; //$show->scheduleShow(array($playlist->getId())); }
public static function GetNextItem($p_timeNow) { //get previous show and previous item in the schedule table. //Compare the two and if the last show was recorded and started //after the last item in the schedule table, then return the show's //name. Else return the last item from the schedule. $showInstance = Application_Model_ShowInstance::GetNextShowInstance($p_timeNow); $row = Application_Model_Schedule::GetNextScheduleItem($p_timeNow); if (is_null($showInstance)) { if (count($row) == 0) { return null; } else { return array("name" => $row[0]["artist_name"] . " - " . $row[0]["track_title"], "starts" => $row[0]["starts"], "ends" => $row[0]["ends"]); } } else { if (count($row) == 0) { if ($showInstance->isRecorded()) { //last item is a show instance return array("name" => $showInstance->getName(), "starts" => $showInstance->getShowInstanceStart(), "ends" => $showInstance->getShowInstanceEnd()); } else { return null; } } else { //return the one that starts sooner. if ($row[0]["starts"] <= $showInstance->getShowInstanceStart()) { return array("name" => $row[0]["artist_name"] . " - " . $row[0]["track_title"], "starts" => $row[0]["starts"], "ends" => $row[0]["ends"]); } else { return array("name" => $showInstance->getName(), "starts" => $showInstance->getShowInstanceStart(), "ends" => $showInstance->getShowInstanceEnd()); } } } }
public function setRecordedFile($file_id) { $showInstance = CcShowInstancesQuery::create()->findPK($this->_instanceId); $showInstance->setDbRecordedFile($file_id)->save(); $rebroadcasts = CcShowInstancesQuery::create()->filterByDbOriginalShow($this->_instanceId)->find(); foreach ($rebroadcasts as $rebroadcast) { try { $rebroad = new Application_Model_ShowInstance($rebroadcast->getDbId()); $rebroad->addFileToShow($file_id, false); } catch (Exception $e) { Logging::info($e->getMessage()); } } }
public function cancelShowAction() { $user = Application_Model_User::getCurrentUser(); if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) { $showInstanceId = $this->_getParam('id'); try { $showInstance = new Application_Model_ShowInstance($showInstanceId); } catch (Exception $e) { $this->view->show_error = true; return false; } $show = new Application_Model_Show($showInstance->getShowId()); $show->cancelShow($showInstance->getShowInstanceStart()); $this->view->show_id = $showInstance->getShowId(); } }
public function uploadRecordedActionParam($show_instance_id, $file_id) { $showCanceled = false; $file = Application_Model_StoredFile::RecallById($file_id); //$show_instance = $this->_getParam('show_instance'); try { $show_inst = new Application_Model_ShowInstance($show_instance_id); $show_inst->setRecordedFile($file_id); } 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; } // TODO : the following is inefficient because it calls save on both // fields $file->setMetadataValue('MDATA_KEY_CREATOR', "Airtime Show Recorder"); $file->setMetadataValue('MDATA_KEY_TRACKNUMBER', $show_instance_id); if (!$showCanceled && Application_Model_Preference::GetAutoUploadRecordedShowToSoundcloud()) { $id = $file->getId(); Application_Model_Soundcloud::uploadSoundcloud($id); } }
/** *Function will load and return the contents of the requested show. */ public function getShowAction() { $baseUrl = Application_Common_OsPath::getBaseDir(); // disable the view and the layout $this->view->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $showID = $this->_getParam('showID'); if (!isset($showID)) { return; } $showInstance = new Application_Model_ShowInstance($showID); $result = array(); $position = 0; foreach ($showInstance->getShowListContent() as $track) { $elementMap = array('element_title' => isset($track['track_title']) ? $track['track_title'] : "", 'element_artist' => isset($track['creator']) ? $track['creator'] : "", 'element_position' => $position, 'element_id' => ++$position, 'mime' => isset($track['mime']) ? $track['mime'] : ""); $elementMap['type'] = $track['type']; if ($track['type'] == 0) { $mime = $track['mime']; if (strtolower($mime) === 'audio/mp3') { $elementMap['element_mp3'] = $track['item_id']; } elseif (strtolower($mime) === 'audio/ogg') { $elementMap['element_oga'] = $track['item_id']; } elseif (strtolower($mime) === 'audio/mp4') { $elementMap['element_m4a'] = $track['item_id']; } elseif (strtolower($mime) === 'audio/wav') { $elementMap['element_wav'] = $track['item_id']; } elseif (strtolower($mime) === 'audio/x-flac') { $elementMap['element_flac'] = $track['item_id']; } else { throw new Exception("Unknown file type: {$mime}"); } $elementMap['uri'] = $baseUrl . "api/get-media/file/" . $track['item_id']; } else { $elementMap['uri'] = $track['filepath']; } $result[] = $elementMap; } $this->_helper->json($result); }
/** * * @param DateTime $start * -in UTC time * @param DateTime $end * -in UTC time * @param boolean $editable */ public static function &getFullCalendarEvents($p_start, $p_end, $p_editable = false) { $events = array(); $interval = $p_start->diff($p_end); $days = $interval->format('%a'); $shows = Application_Model_Show::getShows($p_start, $p_end); $content_count = Application_Model_ShowInstance::getContentCount($p_start, $p_end); $isFull = Application_Model_ShowInstance::getIsFull($p_start, $p_end); $displayTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone()); $utcTimezone = new DateTimeZone("UTC"); $now = new DateTime("now", $utcTimezone); foreach ($shows as &$show) { $options = array(); //only bother calculating percent for week or day view. if (intval($days) <= 7) { $options["percent"] = Application_Model_Show::getPercentScheduled($show["starts"], $show["ends"], $show["time_filled"]); } if (isset($show["parent_starts"])) { $parentStartsDT = new DateTime($show["parent_starts"], $utcTimezone); } $startsDT = DateTime::createFromFormat("Y-m-d G:i:s", $show["starts"], $utcTimezone); $endsDT = DateTime::createFromFormat("Y-m-d G:i:s", $show["ends"], $utcTimezone); if ($p_editable) { if ($show["record"] && $now > $startsDT) { $options["editable"] = false; } elseif ($show["rebroadcast"] && $now > $parentStartsDT) { $options["editable"] = false; } elseif ($now < $endsDT) { $options["editable"] = true; } } $startsDT->setTimezone($displayTimezone); $endsDT->setTimezone($displayTimezone); $options["show_empty"] = array_key_exists($show['instance_id'], $content_count) ? 0 : 1; if (array_key_exists($show['instance_id'], $isFull)) { $options["show_partial_filled"] = !$isFull[$show['instance_id']]; } else { $options["show_partial_filled"] = true; } $event = array(); $event["id"] = intval($show["instance_id"]); $event["title"] = $show["name"]; $event["start"] = $startsDT->format("Y-m-d H:i:s"); $event["end"] = $endsDT->format("Y-m-d H:i:s"); $event["allDay"] = false; $event["showId"] = intval($show["show_id"]); $event["linked"] = intval($show["linked"]); $event["record"] = intval($show["record"]); $event["rebroadcast"] = intval($show["rebroadcast"]); $event["soundcloud_id"] = is_null($show["soundcloud_id"]) ? -1 : $show["soundcloud_id"]; //for putting the now playing icon on the show. if ($now > $startsDT && $now < $endsDT) { $event["nowPlaying"] = true; } else { $event["nowPlaying"] = false; } //event colouring if ($show["color"] != "") { $event["textColor"] = "#" . $show["color"]; } if ($show["background_color"] != "") { $event["color"] = "#" . $show["background_color"]; } foreach ($options as $key => $value) { $event[$key] = $value; } $events[] = $event; } return $events; }
public function showContentDialogAction() { $showInstanceId = $this->_getParam('id'); try { $show = new Application_Model_ShowInstance($showInstanceId); } catch (Exception $e) { $this->view->show_error = true; return false; } $originalShowId = $show->isRebroadcast(); if (!is_null($originalShowId)) { try { $originalShow = new Application_Model_ShowInstance($originalShowId); } catch (Exception $e) { $this->view->show_error = true; return false; } $originalShowName = $originalShow->getName(); $originalShowStart = $originalShow->getShowInstanceStart(); //convert from UTC to user's timezone for display. $displayTimeZone = new DateTimeZone(Application_Model_Preference::GetTimezone()); $originalDateTime = new DateTime($originalShowStart, new DateTimeZone("UTC")); $originalDateTime->setTimezone($displayTimeZone); $this->view->additionalShowInfo = sprintf(_("Rebroadcast of show %s from %s at %s"), $originalShowName, $originalDateTime->format("l, F jS"), $originalDateTime->format("G:i")); } $this->view->showLength = $show->getShowLength(); $this->view->timeFilled = $show->getTimeScheduled(); $this->view->percentFilled = $show->getPercentScheduled(); $this->view->showContent = $show->getShowListContent(); $this->view->dialog = $this->view->render('schedule/show-content-dialog.phtml'); $this->view->showTitle = htmlspecialchars($show->getName()); unset($this->view->showContent); }
private static function createInputHarborKickTimes(&$data, $range_start, $range_end) { $utcTimeZone = new DateTimeZone("UTC"); $kick_times = Application_Model_ShowInstance::GetEndTimeOfNextShowWithLiveDJ($range_start, $range_end); foreach ($kick_times as $kick_time_info) { $kick_time = $kick_time_info['ends']; $temp = explode('.', Application_Model_Preference::GetDefaultTransitionFade()); // we round down transition time since PHP cannot handle millisecond. We need to // handle this better in the future $transition_time = intval($temp[0]); $switchOffDataTime = new DateTime($kick_time, $utcTimeZone); $switch_off_time = $switchOffDataTime->sub(new DateInterval('PT' . $transition_time . 'S')); $switch_off_time = $switch_off_time->format("Y-m-d H:i:s"); $kick_start = self::AirtimeTimeToPypoTime($kick_time); $data["media"][$kick_start]['start'] = $kick_start; $data["media"][$kick_start]['end'] = $kick_start; $data["media"][$kick_start]['event_type'] = "kick_out"; $data["media"][$kick_start]['type'] = "event"; $data["media"][$kick_start]['independent_event'] = true; if ($kick_time !== $switch_off_time) { $switch_start = self::AirtimeTimeToPypoTime($switch_off_time); $data["media"][$switch_start]['start'] = $switch_start; $data["media"][$switch_start]['end'] = $switch_start; $data["media"][$switch_start]['event_type'] = "switch_off"; $data["media"][$switch_start]['independent_event'] = true; } } }
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; } }
/** * * @param DateTime $start * -in UTC time * @param DateTime $end * -in UTC time * @param boolean $editable */ public static function &getFullCalendarEvents($p_start, $p_end, $p_editable = false) { $events = array(); $interval = $p_start->diff($p_end); $days = $interval->format('%a'); $shows = Application_Model_Show::getShows($p_start, $p_end); $nowEpoch = time(); $content_count = Application_Model_ShowInstance::getContentCount($p_start, $p_end); $timezone = date_default_timezone_get(); foreach ($shows as $show) { $options = array(); //only bother calculating percent for week or day view. if (intval($days) <= 7) { $options["percent"] = Application_Model_Show::getPercentScheduled($show["starts"], $show["ends"], $show["time_filled"]); } $utc = new DateTimeZone("UTC"); if (isset($show["parent_starts"])) { $parentStartsDT = new DateTime($show["parent_starts"], $utc); $parentStartsEpoch = intval($parentStartsDT->format("U")); } $startsDT = DateTime::createFromFormat("Y-m-d G:i:s", $show["starts"], $utc); $endsDT = DateTime::createFromFormat("Y-m-d G:i:s", $show["ends"], $utc); $startsEpochStr = $startsDT->format("U"); $endsEpochStr = $endsDT->format("U"); $startsEpoch = intval($startsEpochStr); $endsEpoch = intval($endsEpochStr); $startsDT->setTimezone(new DateTimeZone($timezone)); $endsDT->setTimezone(new DateTimeZone($timezone)); if ($p_editable) { if ($show["record"] && $nowEpoch > $startsEpoch) { $options["editable"] = false; } elseif ($show["rebroadcast"] && $nowEpoch > $parentStartsEpoch) { $options["editable"] = false; } elseif ($nowEpoch < $endsEpoch) { $options["editable"] = true; } } $showInstance = new Application_Model_ShowInstance($show["instance_id"]); $options["show_empty"] = array_key_exists($show['instance_id'], $content_count) ? 0 : 1; $events[] =& self::makeFullCalendarEvent($show, $options, $startsDT, $endsDT, $startsEpochStr, $endsEpochStr); } return $events; }
/** * There are 2 cases where this function can be called. * 1. When watched dir was removed * 2. When some dir was watched, but it was unmounted * * In case of 1, $userAddedWatchedDir should be true * In case of 2, $userAddedWatchedDir should be false * * When $userAddedWatchedDir is true, it will set "Watched" flag to false * otherwise, it will set "Exists" flag to true */ public function remove($userAddedWatchedDir = true) { $music_dir_id = $this->getId(); $sql = <<<SQL SELECT DISTINCT s.instance_id FROM cc_music_dirs AS md LEFT JOIN cc_files AS f ON f.directory = md.id RIGHT JOIN cc_schedule AS s ON s.file_id = f.id WHERE md.id = :musicDirId; SQL; $show_instances = Application_Common_Database::prepareAndExecute($sql, array(':musicDirId' => $music_dir_id), 'all'); // get all the files on this dir $sql = <<<SQL UPDATE cc_files SET file_exists = 'f' WHERE id IN (SELECT f.id FROM cc_music_dirs AS md LEFT JOIN cc_files AS f ON f.directory = md.id WHERE md.id = :musicDirId); SQL; $affected = Application_Common_Database::prepareAndExecute($sql, array(':musicDirId' => $music_dir_id), 'all'); // set RemovedFlag to true if ($userAddedWatchedDir) { self::setWatchedFlag(false); } else { self::setExistsFlag(false); } //$res = $this->_dir->delete(); foreach ($show_instances as $show_instance_row) { $temp_show = new Application_Model_ShowInstance($show_instance_row["instance_id"]); $temp_show->updateScheduledTime(); } Application_Model_RabbitMq::PushSchedule(); }
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}"); } }