CC-1665: Scheduled stream rebroadcasting and recording
-analyze stream mime type and report error as needed.
This commit is contained in:
parent
3b5b82fe79
commit
b8ea08c065
|
@ -75,16 +75,15 @@ class WebstreamController extends Zend_Controller_Action
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$analysis = Application_Model_Webstream::analyzeFormData($parameters);
|
list($analysis, $mime) = Application_Model_Webstream::analyzeFormData($parameters);
|
||||||
try {
|
try {
|
||||||
if (Application_Model_Webstream::isValid($analysis)) {
|
if (Application_Model_Webstream::isValid($analysis)) {
|
||||||
Application_Model_Webstream::save($parameters);
|
Application_Model_Webstream::save($parameters, $mime);
|
||||||
$this->view->statusMessage = "<div class='success'>Webstream saved.</div>";
|
$this->view->statusMessage = "<div class='success'>Webstream saved.</div>";
|
||||||
} else {
|
} else {
|
||||||
throw new Exception();
|
throw new Exception("isValid returned false");
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Logging::log($e);
|
|
||||||
$this->view->statusMessage = "<div class='errors'>Invalid form values.</div>";
|
$this->view->statusMessage = "<div class='errors'>Invalid form values.</div>";
|
||||||
$this->view->analysis = $analysis;
|
$this->view->analysis = $analysis;
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,6 @@ class Application_Model_Webstream{
|
||||||
"login"=> $username,
|
"login"=> $username,
|
||||||
"url" => $this->webstream->getDbUrl(),
|
"url" => $this->webstream->getDbUrl(),
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function deleteStreams($p_ids, $p_userId)
|
public static function deleteStreams($p_ids, $p_userId)
|
||||||
|
@ -113,9 +112,16 @@ class Application_Model_Webstream{
|
||||||
|
|
||||||
if ($result == 0) {
|
if ($result == 0) {
|
||||||
$valid['url'][0] = false;
|
$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"];
|
$name = $parameters["name"];
|
||||||
if (strlen($name) == 0) {
|
if (strlen($name) == 0) {
|
||||||
|
@ -134,7 +140,7 @@ class Application_Model_Webstream{
|
||||||
Logging::log("EDIT");
|
Logging::log("EDIT");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $valid;
|
return array($valid, $mime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isValid($analysis)
|
public static function isValid($analysis)
|
||||||
|
@ -148,34 +154,34 @@ class Application_Model_Webstream{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
private static function discoverStreamMime($url)
|
||||||
* 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()
|
|
||||||
{
|
{
|
||||||
Logging::log($this->webstream->getDbUrl());
|
$headers = get_headers($url);
|
||||||
$ch = curl_init();
|
$mime = null;
|
||||||
curl_setopt($ch, CURLOPT_URL, $this->webstream->getDbUrl());
|
foreach ($headers as $h) {
|
||||||
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
|
if (preg_match("/^content-type:/i", $h)) {
|
||||||
curl_setopt($ch, CURLOPT_WRITEFUNCTION, array($this, 'writefn'));
|
list(, $value) = explode(":", $h, 2);
|
||||||
$result = curl_exec($ch);
|
$mime = trim($value);
|
||||||
$mime = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
|
}
|
||||||
curl_close($ch);
|
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;
|
return $mime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function save($parameters)
|
public static function save($parameters, $mime)
|
||||||
{
|
{
|
||||||
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
||||||
|
|
||||||
|
@ -205,12 +211,7 @@ class Application_Model_Webstream{
|
||||||
|
|
||||||
$ws = new Application_Model_Webstream($webstream);
|
$ws = new Application_Model_Webstream($webstream);
|
||||||
|
|
||||||
$mime = $ws->discoverStreamMime();
|
$webstream->setDbMime($mime);
|
||||||
if ($mime !== false) {
|
|
||||||
$webstream->setDbMime($mime);
|
|
||||||
} else {
|
|
||||||
throw new Exception("Couldn't get MIME type!");
|
|
||||||
}
|
|
||||||
$webstream->save();
|
$webstream->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue