From 35e3b3bc02f599f0fa356c30d84b8a9ff760df65 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Fri, 10 Aug 2012 12:40:28 -0400 Subject: [PATCH] CC-1665: Scheduled stream rebroadcasting and recording -use mime type so that webstreams can play with invalid filenames --- .../controllers/AudiopreviewController.php | 4 ++ .../controllers/LibraryController.php | 9 ++-- .../controllers/WebstreamController.php | 43 ++++++++++------- airtime_mvc/application/models/Webstream.php | 47 +++++-------------- .../scripts/audiopreview/audio-preview.phtml | 1 + .../airtime/audiopreview/preview_jplayer.js | 12 +++-- 6 files changed, 57 insertions(+), 59 deletions(-) diff --git a/airtime_mvc/application/controllers/AudiopreviewController.php b/airtime_mvc/application/controllers/AudiopreviewController.php index d667363df..e32ba730a 100644 --- a/airtime_mvc/application/controllers/AudiopreviewController.php +++ b/airtime_mvc/application/controllers/AudiopreviewController.php @@ -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; diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index 067a33ac6..2748463f8 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -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(); diff --git a/airtime_mvc/application/controllers/WebstreamController.php b/airtime_mvc/application/controllers/WebstreamController.php index 3e82ad47e..c7ed7d048 100644 --- a/airtime_mvc/application/controllers/WebstreamController.php +++ b/airtime_mvc/application/controllers/WebstreamController.php @@ -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 = "
Webstream saved.
"; } else { throw new Exception(); } } catch (Exception $e) { + Logging::log($e); $this->view->statusMessage = "
Invalid form values.
"; $this->view->analysis = $analysis; } diff --git a/airtime_mvc/application/models/Webstream.php b/airtime_mvc/application/models/Webstream.php index a33575a68..627b81978 100644 --- a/airtime_mvc/application/models/Webstream.php +++ b/airtime_mvc/application/models/Webstream.php @@ -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) { diff --git a/airtime_mvc/application/views/scripts/audiopreview/audio-preview.phtml b/airtime_mvc/application/views/scripts/audiopreview/audio-preview.phtml index 447157a16..9cc956a4e 100644 --- a/airtime_mvc/application/views/scripts/audiopreview/audio-preview.phtml +++ b/airtime_mvc/application/views/scripts/audiopreview/audio-preview.phtml @@ -8,6 +8,7 @@ blockIndex" ?> uri)): ?> uri" ?> + mime" ?> audioFileTitle" ?> audioFileArtist" ?> showID)): ?> diff --git a/airtime_mvc/public/js/airtime/audiopreview/preview_jplayer.js b/airtime_mvc/public/js/airtime/audiopreview/preview_jplayer.js index a20f7421a..ad697a05f 100644 --- a/airtime_mvc/public/js/airtime/audiopreview/preview_jplayer.js +++ b/airtime_mvc/public/js/airtime/audiopreview/preview_jplayer.js @@ -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