CC-1665: Scheduled stream rebroadcasting and recording
-use mime type so that webstreams can play with invalid filenames
This commit is contained in:
parent
fe3f4ea678
commit
35e3b3bc02
|
@ -51,14 +51,18 @@ class AudiopreviewController extends Zend_Controller_Action
|
|||
|
||||
if ($type == "audioclip") {
|
||||
$uri = "/api/get-media/file/".$audioFileID;
|
||||
$media = Application_Model_StoredFile::Recall($audioFileID);
|
||||
$mime = $media->getPropelOrm()->getDbMime();
|
||||
} else if ($type == "stream") {
|
||||
$webstream = CcWebstreamQuery::create()->findPk($audioFileID);
|
||||
$uri = $webstream->getDbUrl();
|
||||
$mime = $webstream->getDbMime();
|
||||
} else {
|
||||
throw new Exception("Unknown type for audio preview!");
|
||||
}
|
||||
|
||||
$this->view->uri = $uri;
|
||||
$this->view->mime = $mime;
|
||||
$this->view->audioFileID = $audioFileID;
|
||||
$this->view->audioFileArtist = $audioFileArtist;
|
||||
$this->view->audioFileTitle = $audioFileTitle;
|
||||
|
|
|
@ -76,7 +76,7 @@ class LibraryController extends Zend_Controller_Action
|
|||
$obj = new Application_Model_Playlist($id);
|
||||
} else {
|
||||
$obj = new Application_Model_Block($id);
|
||||
if (!$obj->isStatic()){
|
||||
if (!$obj->isStatic()) {
|
||||
unset($menu["play"]);
|
||||
}
|
||||
if (($isAdminOrPM || $obj->getCreatorId() == $user->getId()) && $screen == "playlist") {
|
||||
|
@ -96,7 +96,8 @@ class LibraryController extends Zend_Controller_Action
|
|||
}
|
||||
} else if ($type == "stream") {
|
||||
|
||||
$obj = new Application_Model_Webstream($id);
|
||||
$webstream = CcWebstreamQuery::create()->findPK($id);
|
||||
$obj = new Application_Model_Webstream($webstream);
|
||||
if (isset($this->obj_sess->id) && $screen == "playlist") {
|
||||
if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
|
||||
if ($this->obj_sess->type === "playlist") {
|
||||
|
@ -330,7 +331,9 @@ class LibraryController extends Zend_Controller_Action
|
|||
}
|
||||
$this->view->block = $block;
|
||||
} else if ($type == "stream") {
|
||||
$file = new Application_Model_Webstream($id);
|
||||
|
||||
$webstream = CcWebstreamQuery::create()->findPK($id);
|
||||
$file = new Application_Model_Webstream($webstream);
|
||||
|
||||
$md = $file->getMetadata();
|
||||
|
||||
|
|
|
@ -15,19 +15,19 @@ class WebstreamController extends Zend_Controller_Action
|
|||
|
||||
public function newAction()
|
||||
{
|
||||
$this->view->ws = new Application_Model_Webstream();
|
||||
|
||||
$webstream = new CcWebstream();
|
||||
|
||||
//we're not saving this primary key in the DB so it's OK
|
||||
$webstream->setDbId(-1);
|
||||
$webstream->setDbName("Untitled Webstream");
|
||||
$webstream->setDbDescription("");
|
||||
$webstream->setDbUrl("http://");
|
||||
$webstream->setDbLength("00:00:00");
|
||||
$webstream->setDbName("Untitled Webstream");
|
||||
|
||||
$this->view->ws = new Application_Model_Webstream($webstream);
|
||||
$this->view->html = $this->view->render('webstream/webstream.phtml');
|
||||
/*
|
||||
$pl_sess = $this->pl_sess;
|
||||
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
||||
|
||||
$pl = new Application_Model_Playlist();
|
||||
$pl->setName("Untitled Playlist");
|
||||
$pl->setPLMetaData('dc:creator', $userInfo->id);
|
||||
|
||||
$this->changePlaylist($pl->getId());
|
||||
$this->createFullResponse($pl);
|
||||
*/
|
||||
}
|
||||
|
||||
public function editAction()
|
||||
|
@ -39,7 +39,8 @@ class WebstreamController extends Zend_Controller_Action
|
|||
throw new Exception("Missing parameter 'id'");
|
||||
}
|
||||
|
||||
$this->view->ws = new Application_Model_Webstream($id);
|
||||
$webstream = CcWebstreamQuery::create()->findPK($id);
|
||||
$this->view->ws = new Application_Model_Webstream($webstream);
|
||||
$this->view->html = $this->view->render('webstream/webstream.phtml');
|
||||
}
|
||||
|
||||
|
@ -52,8 +53,15 @@ class WebstreamController extends Zend_Controller_Action
|
|||
$hasPermission = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER, UTYPE_HOST));
|
||||
$id = $request->getParam("id");
|
||||
|
||||
if ($id != -1) {
|
||||
$webstream = CcWebstreamQuery::create()->findPK($id);
|
||||
$parameters = array();
|
||||
$parameters['id'] = trim($request->getParam("id"));
|
||||
$parameters['length'] = trim($request->getParam("length"));
|
||||
$parameters['name'] = trim($request->getParam("name"));
|
||||
$parameters['description'] = trim($request->getParam("description"));
|
||||
$parameters['url'] = trim($request->getParam("url"));
|
||||
|
||||
if ($parameters['id'] != -1) {
|
||||
$webstream = CcWebstreamQuery::create()->findPK($parameters['id']);
|
||||
//we are updating a playlist. Ensure that if the user is a host/dj, that he has the correct permission.
|
||||
$user = Application_Model_User::getCurrentUser();
|
||||
if ($webstream->getDbCreatorId() != $user->getId()) {
|
||||
|
@ -67,15 +75,16 @@ class WebstreamController extends Zend_Controller_Action
|
|||
return;
|
||||
}
|
||||
|
||||
$analysis = Application_Model_Webstream::analyzeFormData($request);
|
||||
$analysis = Application_Model_Webstream::analyzeFormData($parameters);
|
||||
try {
|
||||
if (Application_Model_Webstream::isValid($analysis)) {
|
||||
Application_Model_Webstream::save($request, $id);
|
||||
Application_Model_Webstream::save($parameters);
|
||||
$this->view->statusMessage = "<div class='success'>Webstream saved.</div>";
|
||||
} else {
|
||||
throw new Exception();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Logging::log($e);
|
||||
$this->view->statusMessage = "<div class='errors'>Invalid form values.</div>";
|
||||
$this->view->analysis = $analysis;
|
||||
}
|
||||
|
|
|
@ -4,22 +4,9 @@ class Application_Model_Webstream{
|
|||
|
||||
private $id;
|
||||
|
||||
public function __construct($id=-1)
|
||||
public function __construct($webstream)
|
||||
{
|
||||
if ($id == -1) {
|
||||
$this->webstream = new CcWebstream();
|
||||
|
||||
//We're not saving this object in the database, so -1 ID is OK.
|
||||
$this->webstream->setDbId(-1);
|
||||
$this->webstream->setDbName("Untitled Webstream");
|
||||
$this->webstream->setDbDescription("");
|
||||
$this->webstream->setDbUrl("http://");
|
||||
$this->webstream->setDbLength("00:00:00");
|
||||
$this->webstream->setDbName("Untitled Webstream");
|
||||
} else {
|
||||
$this->id = $id;
|
||||
$this->webstream = CcWebstreamQuery::create()->findPK($this->id);
|
||||
}
|
||||
$this->webstream = $webstream;
|
||||
}
|
||||
|
||||
public function getOrm()
|
||||
|
@ -103,16 +90,15 @@ class Application_Model_Webstream{
|
|||
|
||||
$leftOvers = array_diff($p_ids, $ownedStreams);
|
||||
return $leftOvers;
|
||||
|
||||
}
|
||||
|
||||
public static function analyzeFormData($request)
|
||||
public static function analyzeFormData($parameters)
|
||||
{
|
||||
$valid = array("length" => array(true, ''),
|
||||
"url" => array(true, ''),
|
||||
"name" => array(true, ''));
|
||||
|
||||
$length = trim($request->getParam("length"));
|
||||
$length = $parameters["length"];
|
||||
$result = preg_match("/^([0-9]{1,2})h ([0-5][0-9])m$/", $length, $matches);
|
||||
if (!$result == 1 || !count($matches) == 3) {
|
||||
$valid['length'][0] = false;
|
||||
|
@ -120,7 +106,7 @@ class Application_Model_Webstream{
|
|||
}
|
||||
|
||||
|
||||
$url = trim($request->getParam("url"));
|
||||
$url = $parameters["url"];
|
||||
//simple validator that checks to make sure that the url starts with http(s),
|
||||
//and that the domain is at least 1 letter long followed by a period.
|
||||
$result = preg_match("/^(http|https):\/\/.+\./", $url, $matches);
|
||||
|
@ -131,13 +117,13 @@ class Application_Model_Webstream{
|
|||
}
|
||||
|
||||
|
||||
$name = trim($request->getParam("name"));
|
||||
$name = $parameters["name"];
|
||||
if (strlen($name) == 0) {
|
||||
$valid['name'][0] = false;
|
||||
$valid['name'][1] = 'Webstream name cannot be empty';
|
||||
}
|
||||
|
||||
$id = trim($request->getParam("id"));
|
||||
$id = $parameters["id"];
|
||||
|
||||
if (!is_null($id)) {
|
||||
// user has performed a create stream action instead of edit
|
||||
|
@ -148,8 +134,6 @@ class Application_Model_Webstream{
|
|||
Logging::log("EDIT");
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $valid;
|
||||
}
|
||||
|
||||
|
@ -191,11 +175,11 @@ class Application_Model_Webstream{
|
|||
return $mime;
|
||||
}
|
||||
|
||||
public static function save($request, $id)
|
||||
public static function save($parameters)
|
||||
{
|
||||
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
||||
|
||||
$length = trim($request->getParam("length"));
|
||||
$length = $parameters["length"];
|
||||
$result = preg_match("/^([0-9]{1,2})h ([0-5][0-9])m$/", $length, $matches);
|
||||
|
||||
if ($result == 1 && count($matches) == 3) {
|
||||
|
@ -209,22 +193,17 @@ class Application_Model_Webstream{
|
|||
throw new Exception("Invalid date format: $length");
|
||||
}
|
||||
|
||||
|
||||
//$ws = new Application_Model_Webstream($id);
|
||||
//$webstream = $ws->getOrm();
|
||||
|
||||
$webstream = new CcWebstream();
|
||||
$webstream->setDbName($request->getParam("name"));
|
||||
$webstream->setDbDescription($request->getParam("description"));
|
||||
$webstream->setDbUrl($request->getParam("url"));
|
||||
$webstream->setDbName($parameters["name"]);
|
||||
$webstream->setDbDescription($parameters["description"]);
|
||||
$webstream->setDbUrl($parameters["url"]);
|
||||
|
||||
$webstream->setDbLength($dblength);
|
||||
$webstream->setDbCreatorId($userInfo->id);
|
||||
$webstream->setDbUtime(new DateTime("now", new DateTimeZone('UTC')));
|
||||
$webstream->setDbMtime(new DateTime("now", new DateTimeZone('UTC')));
|
||||
$webstream->save();
|
||||
|
||||
$ws = new Application_Model_Webstream($webstream->getDbId());
|
||||
$ws = new Application_Model_Webstream($webstream);
|
||||
|
||||
$mime = $ws->discoverStreamMime();
|
||||
if ($mime !== false) {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<span class='blockIndex'><?php echo "$this->blockIndex" ?></span>
|
||||
<?php elseif (isset($this->uri)): ?>
|
||||
<span class='audioUri'><?php echo "$this->uri" ?></span>
|
||||
<span class='audioMime'><?php echo "$this->mime" ?></span>
|
||||
<span class='audioFileTitle'><?php echo "$this->audioFileTitle" ?></span>
|
||||
<span class='audioFileArtist'><?php echo "$this->audioFileArtist" ?></span>
|
||||
<?php elseif (isset($this->showID)): ?>
|
||||
|
|
|
@ -36,6 +36,7 @@ $(document).ready(function(){
|
|||
$.jPlayer.timeFormat.showHour = true;
|
||||
|
||||
var audioUri = $('.audioUri').text();
|
||||
var audioMime = $('.audioMime').text();
|
||||
//var audioFileID = $('.audioFileID').text();
|
||||
var playlistID = $('.playlistID').text();
|
||||
var playlistIndex = $('.playlistIndex').text();
|
||||
|
@ -49,7 +50,7 @@ $(document).ready(function(){
|
|||
if (playlistID != "" && playlistID !== ""){
|
||||
playAllPlaylist(playlistID, playlistIndex);
|
||||
}else if (audioUri != "") {
|
||||
playOne(audioUri);
|
||||
playOne(audioUri, audioMime);
|
||||
}else if (showID != "") {
|
||||
playAllShow(showID, showIndex);
|
||||
}else if(blockId != "" && blockIndex != ""){
|
||||
|
@ -188,20 +189,21 @@ function play(p_playlistIndex){
|
|||
* Playing one audio track occurs from the library. This function will create the media, setup
|
||||
* jplayer and play the track.
|
||||
*/
|
||||
function playOne(uri) {
|
||||
function playOne(uri, mime) {
|
||||
var playlist = new Array();
|
||||
var fileExtension = uri.split('.').pop();
|
||||
if (fileExtension.toLowerCase() === 'mp3') {
|
||||
|
||||
if (mime.search(/mp3/i) > 0 || mime.search(/mpeg/i) > 0) {
|
||||
media = {title: $('.audioFileTitle').text() !== 'null' ?$('.audioFileTitle').text():"",
|
||||
artist: $('.audioFileArtist').text() !== 'null' ?$('.audioFileArtist').text():"",
|
||||
mp3:uri
|
||||
};
|
||||
} else if (fileExtension.toLowerCase() === 'ogg' ) {
|
||||
} else if (mime.search(/og(g|a)/i) > 0 || mime.search(/vorbis/i) > 0) {
|
||||
media = {title: $('.audioFileTitle').text() != 'null' ?$('.audioFileTitle').text():"",
|
||||
artist: $('.audioFileArtist').text() != 'null' ?$('.audioFileArtist').text():"",
|
||||
oga:uri
|
||||
};
|
||||
}
|
||||
|
||||
_playlist_jplayer.option("autoPlay", true);
|
||||
playlist[0] = media;
|
||||
//_playlist_jplayer.setPlaylist(playlist); --if I use this the player will call _init on the setPlaylist and on the ready
|
||||
|
|
Loading…
Reference in New Issue