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

This commit is contained in:
denise 2012-08-15 15:13:15 -04:00
commit ceba380127
13 changed files with 206 additions and 40 deletions

View File

@ -34,6 +34,7 @@ class ApiController extends Zend_Controller_Action
->addActionContext('get-bootstrap-info', 'json') ->addActionContext('get-bootstrap-info', 'json')
->addActionContext('get-files-without-replay-gain', 'json') ->addActionContext('get-files-without-replay-gain', 'json')
->addActionContext('reload-metadata-group', 'json') ->addActionContext('reload-metadata-group', 'json')
->addActionContext('notify-webstream-data', 'json')
->initContext(); ->initContext();
} }
@ -349,12 +350,15 @@ class ApiController extends Zend_Controller_Action
//set a 'last played' timestamp for media item //set a 'last played' timestamp for media item
//needed for smart playlists //needed for smart playlists
try{ try {
$file_id = Application_Model_Schedule::GetFileId($media_id); $file_id = Application_Model_Schedule::GetFileId($media_id);
$file = Application_Model_StoredFile::Recall($file_id); if (!is_null($file_id)) {
$now = new DateTime("now", new DateTimeZone("UTC")); //we are dealing with a file not a stream
$file->setLastPlayedTime($now); $file = Application_Model_StoredFile::Recall($file_id);
}catch(Exception $e){ $now = new DateTime("now", new DateTimeZone("UTC"));
$file->setLastPlayedTime($now);
}
} catch (Exception $e) {
Logging::log($e); Logging::log($e);
} }
@ -368,9 +372,11 @@ class ApiController extends Zend_Controller_Action
$end_timestamp = $now->add(new DateInterval("PT2H")); $end_timestamp = $now->add(new DateInterval("PT2H"));
$end_timestamp = $end_timestamp->format("Y-m-d H:i:s"); $end_timestamp = $end_timestamp->format("Y-m-d H:i:s");
$this->view->shows = Application_Model_Show::getShows(Application_Common_DateHelper::ConvertToUtcDateTime($today_timestamp, date_default_timezone_get()), $this->view->shows =
Application_Common_DateHelper::ConvertToUtcDateTime($end_timestamp, date_default_timezone_get()), Application_Model_Show::getShows(
$excludeInstance=NULL, $onlyRecord=TRUE); Application_Common_DateHelper::ConvertToUtcDateTime($today_timestamp, date_default_timezone_get()),
Application_Common_DateHelper::ConvertToUtcDateTime($end_timestamp, date_default_timezone_get()),
$excludeInstance = null, $onlyRecord = true);
$this->view->is_recording = false; $this->view->is_recording = false;
@ -394,11 +400,12 @@ class ApiController extends Zend_Controller_Action
$result = Application_Model_StoredFile::copyFileToStor($upload_dir, $fileName, $tempFileName); $result = Application_Model_StoredFile::copyFileToStor($upload_dir, $fileName, $tempFileName);
if (!is_null($result)) { if (!is_null($result)) {
die('{"jsonrpc" : "2.0", "error" : {"code": '.$result[code].', "message" : "'.$result[message].'"}}'); die('{"jsonrpc" : "2.0", "error" : {"code": '.$result['code'].', "message" : "'.$result['message'].'"}}');
} }
} }
public function uploadRecordedAction() { public function uploadRecordedAction()
{
$show_instance_id = $this->_getParam('showinstanceid'); $show_instance_id = $this->_getParam('showinstanceid');
$file_id = $this->_getParam('fileid'); $file_id = $this->_getParam('fileid');
$this->view->fileid = $file_id; $this->view->fileid = $file_id;
@ -422,7 +429,7 @@ class ApiController extends Zend_Controller_Action
$show_genre = $show_inst->getGenre(); $show_genre = $show_inst->getGenre();
$show_start_time = Application_Common_DateHelper::ConvertToLocalDateTimeString($show_inst->getShowInstanceStart()); $show_start_time = Application_Common_DateHelper::ConvertToLocalDateTimeString($show_inst->getShowInstanceStart());
} catch (Exception $e) { } catch (Exception $e) {
//we've reached here probably because the show was //we've reached here probably because the show was
//cancelled, and therefore the show instance does not //cancelled, and therefore the show instance does not
//exist anymore (ShowInstance constructor threw this error). //exist anymore (ShowInstance constructor threw this error).
@ -1015,4 +1022,34 @@ class ApiController extends Zend_Controller_Action
$file->save(); $file->save();
} }
} }
public function notifyWebstreamDataAction()
{
$request = $this->getRequest();
$data = $request->getParam("data");
$media_id = $request->getParam("media_id");
$schedule = CcScheduleQuery::create()->findPK($media_id);
$stream_id = $schedule->getDbStreamId();
if (!is_null($stream_id)) {
$webstream = CcWebstreamQuery::create()->findPK($stream_id);
if (strlen($data) <= 1024) {
$data_arr = json_decode($data);
if (isset($data_arr->title)) {
$webstream->setDbLiquidsoapData($data_arr->title);
} else {
$webstream->setDbLiquidsoapData('');
}
$webstream->save();
}
} else {
throw new Error("Unexpected error. media_id $media_id has a null stream value in cc_schedule!");
}
Logging::log(json_decode($data));
$this->view->response = $data;
$this->view->media_id = $media_id;
}
} }

View File

@ -80,12 +80,10 @@ class Application_Model_Schedule
%%tables%% WHERE "; %%tables%% WHERE ";
$fileColumns = "ft.artist_name, ft.track_title, "; $fileColumns = "ft.artist_name, ft.track_title, ";
//$fileJoin = "cc_files ft ON st.file_id = ft.id";
$fileJoin = "FROM cc_schedule st JOIN cc_files ft ON st.file_id = ft.id $fileJoin = "FROM cc_schedule st JOIN cc_files ft ON st.file_id = ft.id
LEFT JOIN cc_show_instances si ON st.instance_id = si.id"; LEFT JOIN cc_show_instances si ON st.instance_id = si.id";
$streamColumns = "sub.login as artist_name, ws.name as track_title, "; $streamColumns = "ws.name as artist_name, ws.liquidsoap_data as track_title, ";
//$streamJoin = "cc_webstream ws ON st.stream_id = ws.id";
$streamJoin = "FROM cc_schedule st JOIN cc_webstream ws ON st.stream_id = ws.id $streamJoin = "FROM cc_schedule st JOIN cc_webstream ws ON st.stream_id = ws.id
LEFT JOIN cc_show_instances si ON st.instance_id = si.id LEFT JOIN cc_show_instances si ON st.instance_id = si.id
LEFT JOIN cc_subjs as sub on sub.id = ws.creator_id"; LEFT JOIN cc_subjs as sub on sub.id = ws.creator_id";

View File

@ -47,6 +47,7 @@ class CcWebstreamTableMap extends TableMap {
$this->addColumn('MTIME', 'DbMtime', 'TIMESTAMP', true, 6, null); $this->addColumn('MTIME', 'DbMtime', 'TIMESTAMP', true, 6, null);
$this->addColumn('UTIME', 'DbUtime', 'TIMESTAMP', true, 6, null); $this->addColumn('UTIME', 'DbUtime', 'TIMESTAMP', true, 6, null);
$this->addColumn('MIME', 'DbMime', 'VARCHAR', false, 255, null); $this->addColumn('MIME', 'DbMime', 'VARCHAR', false, 255, null);
$this->addColumn('LIQUIDSOAP_DATA', 'DbLiquidsoapData', 'VARCHAR', false, 1024, null);
// validators // validators
} // initialize() } // initialize()

View File

@ -79,6 +79,12 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent
*/ */
protected $mime; protected $mime;
/**
* The value for the liquidsoap_data field.
* @var string
*/
protected $liquidsoap_data;
/** /**
* @var array CcSchedule[] Collection to store aggregation of CcSchedule objects. * @var array CcSchedule[] Collection to store aggregation of CcSchedule objects.
*/ */
@ -255,6 +261,16 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent
return $this->mime; return $this->mime;
} }
/**
* Get the [liquidsoap_data] column value.
*
* @return string
*/
public function getDbLiquidsoapData()
{
return $this->liquidsoap_data;
}
/** /**
* Set the value of [id] column. * Set the value of [id] column.
* *
@ -493,6 +509,26 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent
return $this; return $this;
} // setDbMime() } // setDbMime()
/**
* Set the value of [liquidsoap_data] column.
*
* @param string $v new value
* @return CcWebstream The current object (for fluent API support)
*/
public function setDbLiquidsoapData($v)
{
if ($v !== null) {
$v = (string) $v;
}
if ($this->liquidsoap_data !== $v) {
$this->liquidsoap_data = $v;
$this->modifiedColumns[] = CcWebstreamPeer::LIQUIDSOAP_DATA;
}
return $this;
} // setDbLiquidsoapData()
/** /**
* Indicates whether the columns in this object are only set to default values. * Indicates whether the columns in this object are only set to default values.
* *
@ -538,6 +574,7 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent
$this->mtime = ($row[$startcol + 6] !== null) ? (string) $row[$startcol + 6] : null; $this->mtime = ($row[$startcol + 6] !== null) ? (string) $row[$startcol + 6] : null;
$this->utime = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null; $this->utime = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null;
$this->mime = ($row[$startcol + 8] !== null) ? (string) $row[$startcol + 8] : null; $this->mime = ($row[$startcol + 8] !== null) ? (string) $row[$startcol + 8] : null;
$this->liquidsoap_data = ($row[$startcol + 9] !== null) ? (string) $row[$startcol + 9] : null;
$this->resetModified(); $this->resetModified();
$this->setNew(false); $this->setNew(false);
@ -546,7 +583,7 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent
$this->ensureConsistency(); $this->ensureConsistency();
} }
return $startcol + 9; // 9 = CcWebstreamPeer::NUM_COLUMNS - CcWebstreamPeer::NUM_LAZY_LOAD_COLUMNS). return $startcol + 10; // 10 = CcWebstreamPeer::NUM_COLUMNS - CcWebstreamPeer::NUM_LAZY_LOAD_COLUMNS).
} catch (Exception $e) { } catch (Exception $e) {
throw new PropelException("Error populating CcWebstream object", $e); throw new PropelException("Error populating CcWebstream object", $e);
@ -890,6 +927,9 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent
case 8: case 8:
return $this->getDbMime(); return $this->getDbMime();
break; break;
case 9:
return $this->getDbLiquidsoapData();
break;
default: default:
return null; return null;
break; break;
@ -922,6 +962,7 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent
$keys[6] => $this->getDbMtime(), $keys[6] => $this->getDbMtime(),
$keys[7] => $this->getDbUtime(), $keys[7] => $this->getDbUtime(),
$keys[8] => $this->getDbMime(), $keys[8] => $this->getDbMime(),
$keys[9] => $this->getDbLiquidsoapData(),
); );
return $result; return $result;
} }
@ -980,6 +1021,9 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent
case 8: case 8:
$this->setDbMime($value); $this->setDbMime($value);
break; break;
case 9:
$this->setDbLiquidsoapData($value);
break;
} // switch() } // switch()
} }
@ -1013,6 +1057,7 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent
if (array_key_exists($keys[6], $arr)) $this->setDbMtime($arr[$keys[6]]); if (array_key_exists($keys[6], $arr)) $this->setDbMtime($arr[$keys[6]]);
if (array_key_exists($keys[7], $arr)) $this->setDbUtime($arr[$keys[7]]); if (array_key_exists($keys[7], $arr)) $this->setDbUtime($arr[$keys[7]]);
if (array_key_exists($keys[8], $arr)) $this->setDbMime($arr[$keys[8]]); if (array_key_exists($keys[8], $arr)) $this->setDbMime($arr[$keys[8]]);
if (array_key_exists($keys[9], $arr)) $this->setDbLiquidsoapData($arr[$keys[9]]);
} }
/** /**
@ -1033,6 +1078,7 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent
if ($this->isColumnModified(CcWebstreamPeer::MTIME)) $criteria->add(CcWebstreamPeer::MTIME, $this->mtime); if ($this->isColumnModified(CcWebstreamPeer::MTIME)) $criteria->add(CcWebstreamPeer::MTIME, $this->mtime);
if ($this->isColumnModified(CcWebstreamPeer::UTIME)) $criteria->add(CcWebstreamPeer::UTIME, $this->utime); if ($this->isColumnModified(CcWebstreamPeer::UTIME)) $criteria->add(CcWebstreamPeer::UTIME, $this->utime);
if ($this->isColumnModified(CcWebstreamPeer::MIME)) $criteria->add(CcWebstreamPeer::MIME, $this->mime); if ($this->isColumnModified(CcWebstreamPeer::MIME)) $criteria->add(CcWebstreamPeer::MIME, $this->mime);
if ($this->isColumnModified(CcWebstreamPeer::LIQUIDSOAP_DATA)) $criteria->add(CcWebstreamPeer::LIQUIDSOAP_DATA, $this->liquidsoap_data);
return $criteria; return $criteria;
} }
@ -1102,6 +1148,7 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent
$copyObj->setDbMtime($this->mtime); $copyObj->setDbMtime($this->mtime);
$copyObj->setDbUtime($this->utime); $copyObj->setDbUtime($this->utime);
$copyObj->setDbMime($this->mime); $copyObj->setDbMime($this->mime);
$copyObj->setDbLiquidsoapData($this->liquidsoap_data);
if ($deepCopy) { if ($deepCopy) {
// important: temporarily setNew(false) because this affects the behavior of // important: temporarily setNew(false) because this affects the behavior of
@ -1332,6 +1379,7 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent
$this->mtime = null; $this->mtime = null;
$this->utime = null; $this->utime = null;
$this->mime = null; $this->mime = null;
$this->liquidsoap_data = null;
$this->alreadyInSave = false; $this->alreadyInSave = false;
$this->alreadyInValidation = false; $this->alreadyInValidation = false;
$this->clearAllReferences(); $this->clearAllReferences();

View File

@ -26,7 +26,7 @@ abstract class BaseCcWebstreamPeer {
const TM_CLASS = 'CcWebstreamTableMap'; const TM_CLASS = 'CcWebstreamTableMap';
/** The total number of columns. */ /** The total number of columns. */
const NUM_COLUMNS = 9; const NUM_COLUMNS = 10;
/** The number of lazy-loaded columns. */ /** The number of lazy-loaded columns. */
const NUM_LAZY_LOAD_COLUMNS = 0; const NUM_LAZY_LOAD_COLUMNS = 0;
@ -58,6 +58,9 @@ abstract class BaseCcWebstreamPeer {
/** the column name for the MIME field */ /** the column name for the MIME field */
const MIME = 'cc_webstream.MIME'; const MIME = 'cc_webstream.MIME';
/** the column name for the LIQUIDSOAP_DATA field */
const LIQUIDSOAP_DATA = 'cc_webstream.LIQUIDSOAP_DATA';
/** /**
* An identiy map to hold any loaded instances of CcWebstream objects. * An identiy map to hold any loaded instances of CcWebstream objects.
* This must be public so that other peer classes can access this when hydrating from JOIN * This must be public so that other peer classes can access this when hydrating from JOIN
@ -74,12 +77,12 @@ abstract class BaseCcWebstreamPeer {
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/ */
private static $fieldNames = array ( private static $fieldNames = array (
BasePeer::TYPE_PHPNAME => array ('DbId', 'DbName', 'DbDescription', 'DbUrl', 'DbLength', 'DbCreatorId', 'DbMtime', 'DbUtime', 'DbMime', ), BasePeer::TYPE_PHPNAME => array ('DbId', 'DbName', 'DbDescription', 'DbUrl', 'DbLength', 'DbCreatorId', 'DbMtime', 'DbUtime', 'DbMime', 'DbLiquidsoapData', ),
BasePeer::TYPE_STUDLYPHPNAME => array ('dbId', 'dbName', 'dbDescription', 'dbUrl', 'dbLength', 'dbCreatorId', 'dbMtime', 'dbUtime', 'dbMime', ), BasePeer::TYPE_STUDLYPHPNAME => array ('dbId', 'dbName', 'dbDescription', 'dbUrl', 'dbLength', 'dbCreatorId', 'dbMtime', 'dbUtime', 'dbMime', 'dbLiquidsoapData', ),
BasePeer::TYPE_COLNAME => array (self::ID, self::NAME, self::DESCRIPTION, self::URL, self::LENGTH, self::CREATOR_ID, self::MTIME, self::UTIME, self::MIME, ), BasePeer::TYPE_COLNAME => array (self::ID, self::NAME, self::DESCRIPTION, self::URL, self::LENGTH, self::CREATOR_ID, self::MTIME, self::UTIME, self::MIME, self::LIQUIDSOAP_DATA, ),
BasePeer::TYPE_RAW_COLNAME => array ('ID', 'NAME', 'DESCRIPTION', 'URL', 'LENGTH', 'CREATOR_ID', 'MTIME', 'UTIME', 'MIME', ), BasePeer::TYPE_RAW_COLNAME => array ('ID', 'NAME', 'DESCRIPTION', 'URL', 'LENGTH', 'CREATOR_ID', 'MTIME', 'UTIME', 'MIME', 'LIQUIDSOAP_DATA', ),
BasePeer::TYPE_FIELDNAME => array ('id', 'name', 'description', 'url', 'length', 'creator_id', 'mtime', 'utime', 'mime', ), BasePeer::TYPE_FIELDNAME => array ('id', 'name', 'description', 'url', 'length', 'creator_id', 'mtime', 'utime', 'mime', 'liquidsoap_data', ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, ) BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, )
); );
/** /**
@ -89,12 +92,12 @@ abstract class BaseCcWebstreamPeer {
* e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0 * e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
*/ */
private static $fieldKeys = array ( private static $fieldKeys = array (
BasePeer::TYPE_PHPNAME => array ('DbId' => 0, 'DbName' => 1, 'DbDescription' => 2, 'DbUrl' => 3, 'DbLength' => 4, 'DbCreatorId' => 5, 'DbMtime' => 6, 'DbUtime' => 7, 'DbMime' => 8, ), BasePeer::TYPE_PHPNAME => array ('DbId' => 0, 'DbName' => 1, 'DbDescription' => 2, 'DbUrl' => 3, 'DbLength' => 4, 'DbCreatorId' => 5, 'DbMtime' => 6, 'DbUtime' => 7, 'DbMime' => 8, 'DbLiquidsoapData' => 9, ),
BasePeer::TYPE_STUDLYPHPNAME => array ('dbId' => 0, 'dbName' => 1, 'dbDescription' => 2, 'dbUrl' => 3, 'dbLength' => 4, 'dbCreatorId' => 5, 'dbMtime' => 6, 'dbUtime' => 7, 'dbMime' => 8, ), BasePeer::TYPE_STUDLYPHPNAME => array ('dbId' => 0, 'dbName' => 1, 'dbDescription' => 2, 'dbUrl' => 3, 'dbLength' => 4, 'dbCreatorId' => 5, 'dbMtime' => 6, 'dbUtime' => 7, 'dbMime' => 8, 'dbLiquidsoapData' => 9, ),
BasePeer::TYPE_COLNAME => array (self::ID => 0, self::NAME => 1, self::DESCRIPTION => 2, self::URL => 3, self::LENGTH => 4, self::CREATOR_ID => 5, self::MTIME => 6, self::UTIME => 7, self::MIME => 8, ), BasePeer::TYPE_COLNAME => array (self::ID => 0, self::NAME => 1, self::DESCRIPTION => 2, self::URL => 3, self::LENGTH => 4, self::CREATOR_ID => 5, self::MTIME => 6, self::UTIME => 7, self::MIME => 8, self::LIQUIDSOAP_DATA => 9, ),
BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'NAME' => 1, 'DESCRIPTION' => 2, 'URL' => 3, 'LENGTH' => 4, 'CREATOR_ID' => 5, 'MTIME' => 6, 'UTIME' => 7, 'MIME' => 8, ), BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'NAME' => 1, 'DESCRIPTION' => 2, 'URL' => 3, 'LENGTH' => 4, 'CREATOR_ID' => 5, 'MTIME' => 6, 'UTIME' => 7, 'MIME' => 8, 'LIQUIDSOAP_DATA' => 9, ),
BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'name' => 1, 'description' => 2, 'url' => 3, 'length' => 4, 'creator_id' => 5, 'mtime' => 6, 'utime' => 7, 'mime' => 8, ), BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'name' => 1, 'description' => 2, 'url' => 3, 'length' => 4, 'creator_id' => 5, 'mtime' => 6, 'utime' => 7, 'mime' => 8, 'liquidsoap_data' => 9, ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, ) BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, )
); );
/** /**
@ -175,6 +178,7 @@ abstract class BaseCcWebstreamPeer {
$criteria->addSelectColumn(CcWebstreamPeer::MTIME); $criteria->addSelectColumn(CcWebstreamPeer::MTIME);
$criteria->addSelectColumn(CcWebstreamPeer::UTIME); $criteria->addSelectColumn(CcWebstreamPeer::UTIME);
$criteria->addSelectColumn(CcWebstreamPeer::MIME); $criteria->addSelectColumn(CcWebstreamPeer::MIME);
$criteria->addSelectColumn(CcWebstreamPeer::LIQUIDSOAP_DATA);
} else { } else {
$criteria->addSelectColumn($alias . '.ID'); $criteria->addSelectColumn($alias . '.ID');
$criteria->addSelectColumn($alias . '.NAME'); $criteria->addSelectColumn($alias . '.NAME');
@ -185,6 +189,7 @@ abstract class BaseCcWebstreamPeer {
$criteria->addSelectColumn($alias . '.MTIME'); $criteria->addSelectColumn($alias . '.MTIME');
$criteria->addSelectColumn($alias . '.UTIME'); $criteria->addSelectColumn($alias . '.UTIME');
$criteria->addSelectColumn($alias . '.MIME'); $criteria->addSelectColumn($alias . '.MIME');
$criteria->addSelectColumn($alias . '.LIQUIDSOAP_DATA');
} }
} }

View File

@ -15,6 +15,7 @@
* @method CcWebstreamQuery orderByDbMtime($order = Criteria::ASC) Order by the mtime column * @method CcWebstreamQuery orderByDbMtime($order = Criteria::ASC) Order by the mtime column
* @method CcWebstreamQuery orderByDbUtime($order = Criteria::ASC) Order by the utime column * @method CcWebstreamQuery orderByDbUtime($order = Criteria::ASC) Order by the utime column
* @method CcWebstreamQuery orderByDbMime($order = Criteria::ASC) Order by the mime column * @method CcWebstreamQuery orderByDbMime($order = Criteria::ASC) Order by the mime column
* @method CcWebstreamQuery orderByDbLiquidsoapData($order = Criteria::ASC) Order by the liquidsoap_data column
* *
* @method CcWebstreamQuery groupByDbId() Group by the id column * @method CcWebstreamQuery groupByDbId() Group by the id column
* @method CcWebstreamQuery groupByDbName() Group by the name column * @method CcWebstreamQuery groupByDbName() Group by the name column
@ -25,6 +26,7 @@
* @method CcWebstreamQuery groupByDbMtime() Group by the mtime column * @method CcWebstreamQuery groupByDbMtime() Group by the mtime column
* @method CcWebstreamQuery groupByDbUtime() Group by the utime column * @method CcWebstreamQuery groupByDbUtime() Group by the utime column
* @method CcWebstreamQuery groupByDbMime() Group by the mime column * @method CcWebstreamQuery groupByDbMime() Group by the mime column
* @method CcWebstreamQuery groupByDbLiquidsoapData() Group by the liquidsoap_data column
* *
* @method CcWebstreamQuery leftJoin($relation) Adds a LEFT JOIN clause to the query * @method CcWebstreamQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
* @method CcWebstreamQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query * @method CcWebstreamQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
@ -46,6 +48,7 @@
* @method CcWebstream findOneByDbMtime(string $mtime) Return the first CcWebstream filtered by the mtime column * @method CcWebstream findOneByDbMtime(string $mtime) Return the first CcWebstream filtered by the mtime column
* @method CcWebstream findOneByDbUtime(string $utime) Return the first CcWebstream filtered by the utime column * @method CcWebstream findOneByDbUtime(string $utime) Return the first CcWebstream filtered by the utime column
* @method CcWebstream findOneByDbMime(string $mime) Return the first CcWebstream filtered by the mime column * @method CcWebstream findOneByDbMime(string $mime) Return the first CcWebstream filtered by the mime column
* @method CcWebstream findOneByDbLiquidsoapData(string $liquidsoap_data) Return the first CcWebstream filtered by the liquidsoap_data column
* *
* @method array findByDbId(int $id) Return CcWebstream objects filtered by the id column * @method array findByDbId(int $id) Return CcWebstream objects filtered by the id column
* @method array findByDbName(string $name) Return CcWebstream objects filtered by the name column * @method array findByDbName(string $name) Return CcWebstream objects filtered by the name column
@ -56,6 +59,7 @@
* @method array findByDbMtime(string $mtime) Return CcWebstream objects filtered by the mtime column * @method array findByDbMtime(string $mtime) Return CcWebstream objects filtered by the mtime column
* @method array findByDbUtime(string $utime) Return CcWebstream objects filtered by the utime column * @method array findByDbUtime(string $utime) Return CcWebstream objects filtered by the utime column
* @method array findByDbMime(string $mime) Return CcWebstream objects filtered by the mime column * @method array findByDbMime(string $mime) Return CcWebstream objects filtered by the mime column
* @method array findByDbLiquidsoapData(string $liquidsoap_data) Return CcWebstream objects filtered by the liquidsoap_data column
* *
* @package propel.generator.airtime.om * @package propel.generator.airtime.om
*/ */
@ -385,6 +389,28 @@ abstract class BaseCcWebstreamQuery extends ModelCriteria
return $this->addUsingAlias(CcWebstreamPeer::MIME, $dbMime, $comparison); return $this->addUsingAlias(CcWebstreamPeer::MIME, $dbMime, $comparison);
} }
/**
* Filter the query on the liquidsoap_data column
*
* @param string $dbLiquidsoapData The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return CcWebstreamQuery The current query, for fluid interface
*/
public function filterByDbLiquidsoapData($dbLiquidsoapData = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($dbLiquidsoapData)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $dbLiquidsoapData)) {
$dbLiquidsoapData = str_replace('*', '%', $dbLiquidsoapData);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(CcWebstreamPeer::LIQUIDSOAP_DATA, $dbLiquidsoapData, $comparison);
}
/** /**
* Filter the query by a related CcSchedule object * Filter the query by a related CcSchedule object
* *

View File

@ -423,5 +423,6 @@
<column name="mtime" phpName="DbMtime" type="TIMESTAMP" size="6" required="true" /> <column name="mtime" phpName="DbMtime" type="TIMESTAMP" size="6" required="true" />
<column name="utime" phpName="DbUtime" type="TIMESTAMP" size="6" required="true" /> <column name="utime" phpName="DbUtime" type="TIMESTAMP" size="6" required="true" />
<column name="mime" phpName="DbMime" type="VARCHAR" /> <column name="mime" phpName="DbMime" type="VARCHAR" />
<column name="liquidsoap_data" phpName="DbLiquidsoapData" type="VARCHAR" size="1024" required="false"/>
</table> </table>
</database> </database>

View File

@ -639,6 +639,7 @@ CREATE TABLE "cc_webstream"
"mtime" TIMESTAMP(6) NOT NULL, "mtime" TIMESTAMP(6) NOT NULL,
"utime" TIMESTAMP(6) NOT NULL, "utime" TIMESTAMP(6) NOT NULL,
"mime" VARCHAR(255), "mime" VARCHAR(255),
"liquidsoap_data" VARCHAR(1024),
PRIMARY KEY ("id") PRIMARY KEY ("id")
); );

View File

@ -115,3 +115,5 @@ get_bootstrap_info = 'get-bootstrap-info/format/json/api_key/%%api_key%%'
get_files_without_replay_gain = 'get-files-without-replay-gain/api_key/%%api_key%%/dir_id/%%dir_id%%' get_files_without_replay_gain = 'get-files-without-replay-gain/api_key/%%api_key%%/dir_id/%%dir_id%%'
update_replay_gain_value = 'update-replay-gain-value/api_key/%%api_key%%' update_replay_gain_value = 'update-replay-gain-value/api_key/%%api_key%%'
notify_webstream_data = 'notify-webstream-data/api_key/%%api_key%%/media_id/%%media_id%%/format/json'

View File

@ -81,9 +81,17 @@ class AirtimeApiClient():
successful_response = True successful_response = True
except IOError, e: except IOError, e:
logger.error('Error Authenticating with remote server: %s', e) logger.error('Error Authenticating with remote server: %s', e)
if isinstance(url, urllib2.Request):
logger.debug(url.get_full_url())
else:
logger.debug(url)
except Exception, e: except Exception, e:
logger.error('Couldn\'t connect to remote server. Is it running?') logger.error('Couldn\'t connect to remote server. Is it running?')
logger.error("%s" % e) logger.error("%s" % e)
if isinstance(url, urllib2.Request):
logger.debug(url.get_full_url())
else:
logger.debug(url)
if not successful_response: if not successful_response:
logger.error("Error connecting to server, waiting 5 seconds and trying again.") logger.error("Error connecting to server, waiting 5 seconds and trying again.")
@ -684,7 +692,25 @@ class AirtimeApiClient():
data = urllib.urlencode({'data': json.dumps(pairs)}) data = urllib.urlencode({'data': json.dumps(pairs)})
request = urllib2.Request(url, data) request = urllib2.Request(url, data)
self.get_response_from_server(request) self.logger.debug(self.get_response_from_server(request))
except Exception, e: except Exception, e:
self.logger.error("Exception: %s", e) self.logger.error("Exception: %s", e)
raise raise
def notify_webstream_data(self, data, media_id):
"""
Update the server with the latest metadata we've received from the
external webstream
"""
try:
url = "http://%(base_url)s:%(base_port)s/%(api_base)s/%(notify_webstream_data)s/" % (self.config)
url = url.replace("%%media_id%%", str(media_id))
url = url.replace("%%api_key%%", self.config["api_key"])
data = urllib.urlencode({'data': data})
self.logger.debug(url)
request = urllib2.Request(url, data)
self.logger.info(self.get_response_from_server(request))
except Exception, e:
self.logger.error("Exception: %s", e)

View File

@ -1,11 +1,15 @@
def notify(m) def notify(m)
log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --data='#{!pypo_data}' --media-id=#{m['schedule_table_id']} &") current_media_id := string_of(m['schedule_table_id'])
system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --data='#{!pypo_data}' --media-id=#{m['schedule_table_id']} &") command = "/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --data='#{!pypo_data}' --media-id=#{m['schedule_table_id']} &"
log(command)
system(command)
end end
def notify_stream(m) def notify_stream(m)
log("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --stream --uri=#{base64.encode(m['uri'])} --title=#{base64.encode(m['title'])} &") json_str = string.replace(pattern="\n",(fun (s) -> ""), json_of(m))
#system("/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --stream --uri=#{base64.encode(m['uri'])} --title=#{base64.encode(m['title'])} &") command = "/usr/lib/airtime/pypo/bin/liquidsoap_scripts/notify.sh --webstream='#{json_str}' --media-id=#{!current_media_id} &"
log(command)
system(command)
end end
# A function applied to each metadata chunk # A function applied to each metadata chunk

View File

@ -27,6 +27,7 @@ stream_metadata_type = ref 0
default_dj_fade = ref 0. default_dj_fade = ref 0.
station_name = ref '' station_name = ref ''
show_name = ref '' show_name = ref ''
current_media_id = ref ''
s1_connected = ref '' s1_connected = ref ''
s2_connected = ref '' s2_connected = ref ''

View File

@ -6,10 +6,10 @@ Python part of radio playout (pypo)
This function acts as a gateway between liquidsoap and the server API. This function acts as a gateway between liquidsoap and the server API.
Mainly used to tell the platform what pypo/liquidsoap does. Mainly used to tell the platform what pypo/liquidsoap does.
Main case: Main case:
- whenever LS starts playing a new track, its on_metadata callback calls - whenever LS starts playing a new track, its on_metadata callback calls
a function in ls (notify(m)) which then calls the python script here a function in ls (notify(m)) which then calls the python script here
with the currently starting filename as parameter with the currently starting filename as parameter
- this python script takes this parameter, tries to extract the actual - this python script takes this parameter, tries to extract the actual
media id from it, and then calls back to the API to tell about it about it. media id from it, and then calls back to the API to tell about it about it.
@ -33,14 +33,15 @@ usage = "%prog [options]" + " - notification gateway"
parser = OptionParser(usage=usage) parser = OptionParser(usage=usage)
# Options # Options
parser.add_option("-d", "--data", help="Pass JSON data from liquidsoap into this script.", metavar="data") parser.add_option("-d", "--data", help="Pass JSON data from Liquidsoap into this script.", metavar="data")
parser.add_option("-m", "--media-id", help="ID of the file that is currently playing.", metavar="media_id") parser.add_option("-m", "--media-id", help="ID of the file that is currently playing.", metavar="media_id")
parser.add_option("-e", "--error", action="store", dest="error", type="string", help="liquidsoap error msg.", metavar="error_msg") parser.add_option("-e", "--error", action="store", dest="error", type="string", help="Liquidsoap error msg.", metavar="error_msg")
parser.add_option("-s", "--stream-id", help="ID stream", metavar="stream_id") parser.add_option("-s", "--stream-id", help="ID stream", metavar="stream_id")
parser.add_option("-c", "--connect", help="liquidsoap connected", action="store_true", metavar="connect") parser.add_option("-c", "--connect", help="Liquidsoap connected", action="store_true", metavar="connect")
parser.add_option("-t", "--time", help="liquidsoap boot up time", action="store", dest="time", metavar="time", type="string") parser.add_option("-t", "--time", help="Liquidsoap boot up time", action="store", dest="time", metavar="time", type="string")
parser.add_option("-x", "--source-name", help="source connection name", metavar="source_name") parser.add_option("-x", "--source-name", help="source connection name", metavar="source_name")
parser.add_option("-y", "--source-status", help="source connection stauts", metavar="source_status") parser.add_option("-y", "--source-status", help="source connection status", metavar="source_status")
parser.add_option("-w", "--webstream", help="JSON metadata associated with webstream", metavar="json_data")
# parse options # parse options
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
@ -97,6 +98,15 @@ class Notify:
response = self.api_client.notify_source_status(source_name, status) response = self.api_client.notify_source_status(source_name, status)
logger.debug("Response: " + json.dumps(response)) logger.debug("Response: " + json.dumps(response))
def notify_webstream_data(self, data, media_id):
logger = logging.getLogger("notify")
logger.debug('#################################################')
logger.debug('# Calling server to update webstream data #')
logger.debug('#################################################')
response = self.api_client.notify_webstream_data(data, media_id)
pass
if __name__ == '__main__': if __name__ == '__main__':
print print
print '#########################################' print '#########################################'
@ -124,6 +134,12 @@ if __name__ == '__main__':
n.notify_source_status(options.source_name, options.source_status) n.notify_source_status(options.source_name, options.source_status)
except Exception, e: except Exception, e:
print e print e
elif options.webstream:
try:
n = Notify()
n.notify_webstream_data(options.webstream, options.media_id)
except Exception, e:
print e
else: else:
if not options.data: if not options.data:
print "NOTICE: 'data' command-line argument not given." print "NOTICE: 'data' command-line argument not given."