From b8ea08c065b08cd4b6c3bfed064bc948135b4f0e Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Mon, 13 Aug 2012 12:59:26 -0400 Subject: [PATCH 1/3] CC-1665: Scheduled stream rebroadcasting and recording -analyze stream mime type and report error as needed. --- .../controllers/WebstreamController.php | 7 +- airtime_mvc/application/models/Webstream.php | 67 ++++++++++--------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/airtime_mvc/application/controllers/WebstreamController.php b/airtime_mvc/application/controllers/WebstreamController.php index c7ed7d048..c04dc64f3 100644 --- a/airtime_mvc/application/controllers/WebstreamController.php +++ b/airtime_mvc/application/controllers/WebstreamController.php @@ -75,16 +75,15 @@ class WebstreamController extends Zend_Controller_Action return; } - $analysis = Application_Model_Webstream::analyzeFormData($parameters); + list($analysis, $mime) = Application_Model_Webstream::analyzeFormData($parameters); try { if (Application_Model_Webstream::isValid($analysis)) { - Application_Model_Webstream::save($parameters); + Application_Model_Webstream::save($parameters, $mime); $this->view->statusMessage = "
Webstream saved.
"; } else { - throw new Exception(); + throw new Exception("isValid returned false"); } } 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 cdbd14af0..51866ebeb 100644 --- a/airtime_mvc/application/models/Webstream.php +++ b/airtime_mvc/application/models/Webstream.php @@ -63,7 +63,6 @@ class Application_Model_Webstream{ "login"=> $username, "url" => $this->webstream->getDbUrl(), ); - } public static function deleteStreams($p_ids, $p_userId) @@ -113,9 +112,16 @@ class Application_Model_Webstream{ if ($result == 0) { $valid['url'][0] = false; - $valid['url'][1] = 'URL should be of form "http://www.domain.com/mount"'; - } + $valid['url'][1] = 'URL should be of form "http://domain"'; + } else { + try { + $mime = Application_Model_Webstream::discoverStreamMime($url); + } catch (Exception $e) { + $valid['url'][0] = false; + $valid['url'][1] = $e->getMessage(); + } + } $name = $parameters["name"]; if (strlen($name) == 0) { @@ -134,7 +140,7 @@ class Application_Model_Webstream{ Logging::log("EDIT"); } - return $valid; + return array($valid, $mime); } public static function isValid($analysis) @@ -148,34 +154,34 @@ class Application_Model_Webstream{ return true; } - /* - * This function is a callback used by curl to let us work - * with the contents returned from an http request. We don't - * actually want to work with the contents however (we just want - * the response headers), so immediately return a -1 in this function - * which tells curl not to download the response body at all. - */ - private function writefn($ch, $chunk) - { - return -1; - } - - private function discoverStreamMime() + private static function discoverStreamMime($url) { - Logging::log($this->webstream->getDbUrl()); - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $this->webstream->getDbUrl()); - curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); - curl_setopt($ch, CURLOPT_WRITEFUNCTION, array($this, 'writefn')); - $result = curl_exec($ch); - $mime = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); - curl_close($ch); + $headers = get_headers($url); + $mime = null; + foreach ($headers as $h) { + if (preg_match("/^content-type:/i", $h)) { + list(, $value) = explode(":", $h, 2); + $mime = trim($value); + } + if (preg_match("/^content-length:/i", $h)) { + //if content-length appears, this is not a web stream!!!! + //Aborting the save process. + throw new Exception("Invalid webstream - This appears to be a file download."); + } + } + + if (is_null($mime)) { + throw new Exception("No MIME type found for webstream."); + } else { + if (!preg_match("/(mpeg|ogg)/", $mime)) { + throw new Exception("Unrecognized stream type: $mime"); + } + } - Logging::log($mime); return $mime; } - public static function save($parameters) + public static function save($parameters, $mime) { $userInfo = Zend_Auth::getInstance()->getStorage()->read(); @@ -205,12 +211,7 @@ class Application_Model_Webstream{ $ws = new Application_Model_Webstream($webstream); - $mime = $ws->discoverStreamMime(); - if ($mime !== false) { - $webstream->setDbMime($mime); - } else { - throw new Exception("Couldn't get MIME type!"); - } + $webstream->setDbMime($mime); $webstream->save(); } } From 51e242ec7f253b6615c431ccd216c91639d920fe Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Mon, 13 Aug 2012 14:58:11 -0400 Subject: [PATCH 2/3] CC-1665: Scheduled stream rebroadcasting and recording -remove edit menu from show builder --- airtime_mvc/application/controllers/LibraryController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index 2bfa074f7..67c6dc9a5 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -106,9 +106,11 @@ class LibraryController extends Zend_Controller_Action } } if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) { - $menu["del"] = array("name"=> "Delete", "icon" => "delete", "url" => "/library/delete"); + if ($screen == "playlist") { $menu["edit"] = array("name"=> "Edit", "icon" => "edit", "url" => "/library/edit-file-md/id/{$id}"); } + $menu["del"] = array("name"=> "Delete", "icon" => "delete", "url" => "/library/delete"); + } } //SOUNDCLOUD MENU OPTIONS From 7a5d9a0f91970ea410075cecf9bdca0e51913d0f Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Mon, 13 Aug 2012 15:26:32 -0400 Subject: [PATCH 3/3] CC-1665: Scheduled stream rebroadcasting and recording -don't require 2 digits for minutes or hours --- .../controllers/WebstreamController.php | 4 +- airtime_mvc/application/models/Webstream.php | 37 ++++++++++--------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/airtime_mvc/application/controllers/WebstreamController.php b/airtime_mvc/application/controllers/WebstreamController.php index c04dc64f3..127e23ee2 100644 --- a/airtime_mvc/application/controllers/WebstreamController.php +++ b/airtime_mvc/application/controllers/WebstreamController.php @@ -75,10 +75,10 @@ class WebstreamController extends Zend_Controller_Action return; } - list($analysis, $mime) = Application_Model_Webstream::analyzeFormData($parameters); + list($analysis, $mime, $di) = Application_Model_Webstream::analyzeFormData($parameters); try { if (Application_Model_Webstream::isValid($analysis)) { - Application_Model_Webstream::save($parameters, $mime); + Application_Model_Webstream::save($parameters, $mime, $di); $this->view->statusMessage = "
Webstream saved.
"; } else { throw new Exception("isValid returned false"); diff --git a/airtime_mvc/application/models/Webstream.php b/airtime_mvc/application/models/Webstream.php index 51866ebeb..702d2c68d 100644 --- a/airtime_mvc/application/models/Webstream.php +++ b/airtime_mvc/application/models/Webstream.php @@ -96,9 +96,22 @@ class Application_Model_Webstream{ "url" => array(true, ''), "name" => array(true, '')); + $di = null; $length = $parameters["length"]; - $result = preg_match("/^([0-9]{1,2})h ([0-5][0-9])m$/", $length, $matches); - if (!$result == 1 || !count($matches) == 3) { + $result = preg_match("/^([0-9]{1,2})h ([0-5]?[0-9])m$/", $length, $matches); + if ($result == 1 && count($matches) == 3) { + $hours = $matches[1]; + $minutes = $matches[2]; + $di = new DateInterval("PT{$hours}H{$minutes}M"); + + $totalMinutes = $di->h * 60 + $di->i; + + if ($totalMinutes == 0) { + $valid['length'][0] = false; + $valid['length'][1] = 'Length needs to be greater than 0 minutes'; + } + + } else { $valid['length'][0] = false; $valid['length'][1] = 'Length should be of form "00h 00m"'; } @@ -110,6 +123,7 @@ class Application_Model_Webstream{ //and that the domain is at least 1 letter long $result = preg_match("/^(http|https):\/\/.+/", $url, $matches); + $mime = null; if ($result == 0) { $valid['url'][0] = false; $valid['url'][1] = 'URL should be of form "http://domain"'; @@ -140,7 +154,7 @@ class Application_Model_Webstream{ Logging::log("EDIT"); } - return array($valid, $mime); + return array($valid, $mime, $di); } public static function isValid($analysis) @@ -181,29 +195,16 @@ class Application_Model_Webstream{ return $mime; } - public static function save($parameters, $mime) + public static function save($parameters, $mime, $di) { $userInfo = Zend_Auth::getInstance()->getStorage()->read(); - $length = $parameters["length"]; - $result = preg_match("/^([0-9]{1,2})h ([0-5][0-9])m$/", $length, $matches); - - if ($result == 1 && count($matches) == 3) { - $hours = $matches[1]; - $minutes = $matches[2]; - $di = new DateInterval("PT{$hours}H{$minutes}M"); - $dblength = $di->format("%H:%I"); - } else { - //This should never happen because we should have already validated - //in the controller - throw new Exception("Invalid date format: $length"); - } - $webstream = new CcWebstream(); $webstream->setDbName($parameters["name"]); $webstream->setDbDescription($parameters["description"]); $webstream->setDbUrl($parameters["url"]); + $dblength = $di->format("%H:%I"); $webstream->setDbLength($dblength); $webstream->setDbCreatorId($userInfo->id); $webstream->setDbUtime(new DateTime("now", new DateTimeZone('UTC')));