Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
Naomi Aro 2012-03-19 10:18:52 +01:00
commit b5f92dfa93
23 changed files with 527 additions and 315 deletions

View file

@ -62,6 +62,8 @@ class Config {
$CC_CONFIG['baseUrl'] = $values['general']['base_url'];
$CC_CONFIG['basePort'] = $values['general']['base_port'];
$CC_CONFIG['cache_ahead_hours'] = $values['general']['cache_ahead_hours'];
// Database config
$CC_CONFIG['dsn']['username'] = $values['database']['dbuser'];
$CC_CONFIG['dsn']['password'] = $values['database']['dbpass'];

View file

@ -150,8 +150,11 @@ class ApiController extends Zend_Controller_Action
//user clicks play button for track and downloads it.
header('Content-Disposition: inline; filename="'.$file_base_name.'"');
}
$this->smartReadFile($filepath, 'audio/'.$ext);
if ($ext === 'mp3'){
$this->smartReadFile($filepath, 'audio/mpeg');
} else {
$this->smartReadFile($filepath, 'audio/'.$ext);
}
exit;
}else{
header ("HTTP/1.1 404 Not Found");

View file

@ -232,6 +232,9 @@ class PreferenceController extends Zend_Controller_Action
$this->view->statusMsg = "<div class='success'>Stream Setting Updated.</div>";
}
}
$this->view->confirm_pypo_restart_text = "Updating settings will temporarily interrupt any currently playing shows. Click \'OK\' to continue.";
$this->view->num_stream = $num_of_stream;
$this->view->enable_stream_conf = Application_Model_Preference::GetEnableStreamConf();
$this->view->form = $form;

View file

@ -778,15 +778,13 @@ class ScheduleController extends Zend_Controller_Action
try {
$showInstance = new Application_Model_ShowInstance($showInstanceId);
}
catch(Exception $e){
} 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();
}
}
@ -806,8 +804,8 @@ class ScheduleController extends Zend_Controller_Action
}
$showInstance->clearShow();
$showInstance->delete();
// send 'cancel-current-show' command to pypo
Application_Model_RabbitMq::SendMessageToPypo("cancel_current_show", array());
Application_Model_RabbitMq::PushSchedule();
}
}

View file

@ -64,14 +64,16 @@ class Application_Model_Schedule {
$utcTimeNow = $date->getUtcTimestamp();
$shows = Application_Model_Show::getPrevCurrentNext($utcTimeNow);
$previousShowID = count($shows['previousShow'])>0?$shows['previousShow'][0]['id']:null;
$currentShowID = count($shows['currentShow'])>0?$shows['currentShow'][0]['id']:null;
$results = Application_Model_Schedule::GetPrevCurrentNext($currentShowID, $utcTimeNow);
$nextShowID = count($shows['nextShow'])>0?$shows['nextShow'][0]['id']:null;
$results = Application_Model_Schedule::GetPrevCurrentNext($previousShowID, $currentShowID, $nextShowID, $utcTimeNow);
$range = array("env"=>APPLICATION_ENV,
"schedulerTime"=>$timeNow,
"previous"=>isset($results['previous'])?$results['previous']:(count($shows['previousShow'])>0?$shows['previousShow'][0]:null),
"current"=>isset($results['current'])?$results['current']:null,
"next"=> isset($results['next'])?$results['next']:(count($shows['nextShow'])>0?$shows['nextShow'][0]:null),
"previous"=>$results['previous'] !=null?$results['previous']:(count($shows['previousShow'])>0?$shows['previousShow'][0]:null),
"current"=>$results['current'] !=null?$results['current']:null,
"next"=> $results['next'] !=null?$results['next']:(count($shows['nextShow'])>0?$shows['nextShow'][0]:null),
"currentShow"=>$shows['currentShow'],
"nextShow"=>$shows['nextShow'],
"timezone"=> date("T"),
@ -88,19 +90,39 @@ class Application_Model_Schedule {
* show types are not found through this mechanism a call is made to the old way of querying
* the database to find the track info.
**/
public static function GetPrevCurrentNext($p_currentShowID, $p_timeNow)
public static function GetPrevCurrentNext($p_previousShowID, $p_currentShowID, $p_nextShowID, $p_timeNow)
{
if ($p_previousShowID == null && $p_currentShowID == null && $p_nextShowID == null)
return;
global $CC_CONFIG, $CC_DBC;
if (!isset($p_currentShowID)) {
return array();
}
$sql = "Select ft.artist_name, ft.track_title, st.starts as starts, st.ends as ends, st.media_item_played as media_item_played
$sql = 'Select ft.artist_name, ft.track_title, st.starts as starts, st.ends as ends, st.media_item_played as media_item_played
FROM cc_schedule st LEFT JOIN cc_files ft ON st.file_id = ft.id
WHERE st.instance_id = '$p_currentShowID' AND st.playout_status > 0
ORDER BY st.starts";
WHERE ';
if (isset($p_previousShowID)){
if (isset($p_nextShowID) || isset($p_currentShowID))
$sql .= '(';
$sql .= 'st.instance_id = '.$p_previousShowID;
}
if ($p_currentShowID != null){
if ($p_previousShowID != null)
$sql .= ' OR ';
else if($p_nextShowID != null)
$sql .= '(';
$sql .= 'st.instance_id = '.$p_currentShowID;
}
if ($p_nextShowID != null) {
if ($p_previousShowID != null || $p_currentShowID != null)
$sql .= ' OR ';
$sql .= 'st.instance_id = '.$p_nextShowID;
if($p_previousShowID != null || $p_currentShowID != null)
$sql .= ')';
} else if($p_previousShowID != null && $p_currentShowID != null)
$sql .= ')';
$sql .= ' AND st.playout_status > 0 ORDER BY st.starts';
//Logging::log($sql);
$rows = $CC_DBC->GetAll($sql);
$numberOfRows = count($rows);
@ -587,7 +609,17 @@ class Application_Model_Schedule {
}
if (is_null($p_fromDateTime)) {
$t2 = new DateTime("@".time());
$t2->add(new DateInterval("PT30M"));
$cache_ahead_hours = $CC_CONFIG["cache_ahead_hours"];
if (is_numeric($cache_ahead_hours)){
//make sure we are not dealing with a float
$cache_ahead_hours = intval($cache_ahead_hours);
} else {
$cache_ahead_hours = 1;
}
$t2->add(new DateInterval("PT".$cache_ahead_hours."H"));
$range_end = $t2->format("Y-m-d H:i:s");
} else {
$range_end = Application_Model_Schedule::PypoTimeToAirtimeTime($p_toDateTime);

View file

@ -199,9 +199,6 @@ class Application_Model_Show {
->filterByDbShowId($this->_showId)
->update(array('DbLastShow' => $timeinfo[0]));
//$sql = "DELETE FROM cc_show_instances
// WHERE starts >= '{$day_timestamp}' AND show_id = {$this->_showId}";
$sql = "UPDATE cc_show_instances
SET modified_instance = TRUE
WHERE starts >= '{$day_timestamp}' AND show_id = {$this->_showId}";
@ -1762,7 +1759,9 @@ class Application_Model_Show {
//Find the show that is within the current time.
if ((strtotime($rows[$i]['starts']) <= $timeNowAsMillis) && (strtotime($rows[$i]['ends']) >= $timeNowAsMillis)){
if ( $i - 1 >= 0){
$results['previousShow'][0] = array("name"=>$rows[$i-1]['name'],
$results['previousShow'][0] = array(
"id"=>$rows[$i-1]['id'],
"name"=>$rows[$i-1]['name'],
"start_timestamp"=>$rows[$i-1]['start_timestamp'],
"end_timestamp"=>$rows[$i-1]['end_timestamp'],
"starts"=>$rows[$i-1]['starts'],
@ -1772,7 +1771,9 @@ class Application_Model_Show {
$results['currentShow'][0] = $rows[$i];
if ( isset($rows[$i+1])){
$results['nextShow'][0] = array("name"=>$rows[$i+1]['name'],
$results['nextShow'][0] = array(
"id"=>$rows[$i+1]['id'],
"name"=>$rows[$i+1]['name'],
"start_timestamp"=>$rows[$i+1]['start_timestamp'],
"end_timestamp"=>$rows[$i+1]['end_timestamp'],
"starts"=>$rows[$i+1]['starts'],
@ -1787,7 +1788,9 @@ class Application_Model_Show {
}
//if we hit this we know we've gone to far and can stop looping.
if (strtotime($rows[$i]['starts']) > $timeNowAsMillis) {
$results['nextShow'][0] = array("name"=>$rows[$i]['name'],
$results['nextShow'][0] = array(
"id"=>$rows[$i]['id'],
"name"=>$rows[$i]['name'],
"start_timestamp"=>$rows[$i]['start_timestamp'],
"end_timestamp"=>$rows[$i]['end_timestamp'],
"starts"=>$rows[$i]['starts'],
@ -1798,7 +1801,9 @@ class Application_Model_Show {
//If we didn't find a a current show because the time didn't fit we may still have
//found a previous show so use it.
if (count($results['previousShow']) == 0 && isset($previousShowIndex)) {
$results['previousShow'][0] = array("name"=>$rows[$previousShowIndex]['name'],
$results['previousShow'][0] = array(
"id"=>$rows[$previousShowIndex]['id'],
"name"=>$rows[$previousShowIndex]['name'],
"start_timestamp"=>$rows[$previousShowIndex]['start_timestamp'],
"end_timestamp"=>$rows[$previousShowIndex]['end_timestamp'],
"starts"=>$rows[$previousShowIndex]['starts'],

View file

@ -1,7 +1,7 @@
<div class="ui-widget ui-widget-content block-shadow simple-formblock clearfix padded-strong stream-config">
<h2 <?php if($this->enable_stream_conf == "true"){?>style="float:left"<?php }?>>Stream Settings</h2>
<?php if($this->enable_stream_conf == "true"){?>
<form method="post" action="/Preference/stream-setting" enctype="application/x-www-form-urlencoded">
<form method="post" action="/Preference/stream-setting" enctype="application/x-www-form-urlencoded" onsubmit="return confirm('<?php echo $this->confirm_pypo_restart_text ?>');">
<div class="button-bar bottom" id="submit-element" style="float:right">
<input type="submit" class="ui-button ui-state-default right-floated" value="Save" id="Save" name="Save" />
</div>
@ -83,4 +83,4 @@
<?php }?>
</div>
</form>
</div>
</div>

View file

@ -18,6 +18,10 @@ airtime_dir = x
base_url = localhost
base_port = 80
#How many hours ahead of time should Airtime playout engine (PYPO)
#cache scheduled media files.
cache_ahead_hours = 1
[soundcloud]
connection_retries = 3
time_between_retries = 60

View file

@ -8,16 +8,22 @@ var _idToPostionLookUp;
*/
$(document).ready(function(){
if (useFlash())
mySupplied = "oga, mp3, m4v";
else
mySupplied = "oga, mp3";
_playlist_jplayer = new jPlayerPlaylist({
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
},[], //array of songs will be filled with below's json call
{
swfPath: "/js/jplayer",
//supplied: "mp3,oga",
supplied:mySupplied,
wmode: "window"
});
$.jPlayer.timeFormat.showHour = true;
var audioFileID = $('.audioFileID').text();
@ -35,6 +41,10 @@ $(document).ready(function(){
}
});
function useFlash() {
console.log(navigator.userAgent);
return navigator.userAgent.toLowerCase().match('firefox');
}
/**
* Sets up the jPlayerPlaylist to play.
* - Get the playlist info based on the playlistID give.
@ -122,7 +132,7 @@ function play(p_playlistIndex){
function playOne(p_audioFileID) {
var playlist = new Array();
var fileExtensioin = p_audioFileID.split('.').pop();
console.log(p_audioFileID);
if (fileExtensioin === 'mp3') {
media = {title: $('.audioFileTitle').text() !== 'null' ?$('.audioFileTitle').text():"",
artist: $('.audioFileArtist').text() !== 'null' ?$('.audioFileArtist').text():"",
@ -135,7 +145,7 @@ function playOne(p_audioFileID) {
};
}
_playlist_jplayer.option("autoPlay", true);
console.log(media);
playlist[0] = media;
//_playlist_jplayer.setPlaylist(playlist); --if I use this the player will call _init on the setPlaylist and on the ready
_playlist_jplayer._initPlaylist(playlist);