From eb4c23b0b6a117a473d4d278c01c7a2ce44dc39e Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Thu, 26 Jul 2012 14:41:09 -0400 Subject: [PATCH] CC-1665: Scheduled stream rebroadcasting and recording -Fix scheduled streams mixed with scheduled files --- .../controllers/PlaylistController.php | 4 +-- airtime_mvc/application/models/Playlist.php | 2 +- airtime_mvc/application/models/Schedule.php | 25 +++++++++++-------- airtime_mvc/application/models/Scheduler.php | 4 +-- .../application/models/ShowInstance.php | 2 +- airtime_mvc/application/models/Webstream.php | 4 +-- .../public/js/airtime/showbuilder/builder.js | 2 +- python_apps/pypo/pypofetch.py | 4 +-- python_apps/pypo/pypopush.py | 4 +++ 9 files changed, 29 insertions(+), 22 deletions(-) diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php index 30e62f5b8..9a334bcfc 100644 --- a/airtime_mvc/application/controllers/PlaylistController.php +++ b/airtime_mvc/application/controllers/PlaylistController.php @@ -293,8 +293,8 @@ class PlaylistController extends Zend_Controller_Action public function addItemsAction() { - $aItems = $this->_getParam('aItems', array()); - $aItems = (!is_array($aItems)) ? array($aItems) : $aItems; + $ids = $this->_getParam('aItems', array()); + $ids = (!is_array($ids)) ? array($ids) : $ids; $afterItem = $this->_getParam('afterItem', null); $addType = $this->_getParam('type', 'after'); $obj_type = $this->_getParam('obj_type'); diff --git a/airtime_mvc/application/models/Playlist.php b/airtime_mvc/application/models/Playlist.php index e8f894575..8223f5e2d 100644 --- a/airtime_mvc/application/models/Playlist.php +++ b/airtime_mvc/application/models/Playlist.php @@ -188,7 +188,7 @@ EOT; foreach ($rows as &$row) { Logging::log($row); - $clipSec = Application_Model_Playlist::playlistTimeToSeconds($row['length']); + $clipSec = Application_Common_DateHelper::playlistTimeToSeconds($row['length']); $offset += $clipSec; $offset_cliplength = Application_Common_DateHelper::secondsToPlaylistTime($offset); diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index bd4c37345..9c87526fa 100644 --- a/airtime_mvc/application/models/Schedule.php +++ b/airtime_mvc/application/models/Schedule.php @@ -495,7 +495,6 @@ class Application_Model_Schedule ." si.ends AS show_end," ." f.id AS file_id," ." f.replay_gain AS replay_gain," - ." f.filepath AS filepath," ." ws.id as stream_id," ." ws.url as url" ." FROM $CC_CONFIG[scheduleTable] AS st" @@ -630,17 +629,18 @@ class Application_Model_Schedule if (!is_null($item['file_id'])) { //row is from "file" $media_id = $item['file_id']; - $uri = $item['filepath']; + $storedFile = Application_Model_StoredFile::Recall($media_id); + $uri = $storedFile->getFilePath(); $type = "file"; + $independent_event = false; } else if (!is_null($item['stream_id'])) { //row is type "webstream" $media_id = $item['stream_id']; $uri = $item['url']; $type = "stream"; + $independent_event = true; } - - $start = Application_Model_Schedule::AirtimeTimeToPypoTime($item["start"]); $end = Application_Model_Schedule::AirtimeTimeToPypoTime($item["end"]); @@ -657,20 +657,23 @@ class Application_Model_Schedule 'end' => $end, 'show_name' => $showName, 'replay_gain' => is_null($item["replay_gain"]) ? "0": $item["replay_gain"], - 'independent_event' => false + 'independent_event' => $independent_event ); if ($type == "stream") { //since a stream never ends we have to insert an additional "kick stream" event. The "start" - //time of this event is the "end" time of the stream. - $data["media"][$end] = array( - 'start' => $end, - 'end' => $end, + //time of this event is the "end" time of the stream minus 1 second. + $dt = new DateTime($item["end"], new DateTimeZone('UTC')); + $dt->sub(new DateInterval("PT1S")); + $stream_end = Application_Model_Schedule::AirtimeTimeToPypoTime($dt->format("Y-m-d H:i:s")); + + $data["media"][$stream_end] = array( + 'start' => $stream_end, + 'end' => $stream_end, 'uri' => $uri, 'type' => 'stream_end', 'independent_event' => true - ); - + ); } } diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php index ffae8ab10..aeef324dd 100644 --- a/airtime_mvc/application/models/Scheduler.php +++ b/airtime_mvc/application/models/Scheduler.php @@ -227,7 +227,7 @@ class Application_Model_Scheduler private function findEndTime($p_startDT, $p_duration) { $startEpoch = $p_startDT->format("U.u"); - $durationSeconds = Application_Model_Playlist::playlistTimeToSeconds($p_duration); + $durationSeconds = Application_Common_DateHelper::playlistTimeToSeconds($p_duration); //add two float numbers to 6 subsecond precision //DateTime::createFromFormat("U.u") will have a problem if there is no decimal in the resulting number. @@ -608,7 +608,7 @@ class Application_Model_Scheduler $length = bcsub($nEpoch , $sEpoch , 6); $cliplength = Application_Common_DateHelper::secondsToPlaylistTime($length); - $cueinSec = Application_Model_Playlist::playlistTimeToSeconds($removedItem->getDbCueIn()); + $cueinSec = Application_Common_DateHelper::playlistTimeToSeconds($removedItem->getDbCueIn()); $cueOutSec = bcadd($cueinSec , $length, 6); $cueout = Application_Common_DateHelper::secondsToPlaylistTime($cueOutSec); diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index 9d60ac147..f0955313a 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -603,7 +603,7 @@ class Application_Model_ShowInstance { $time_filled = $this->getTimeScheduled(); - return Application_Model_Playlist::playlistTimeToSeconds($time_filled); + return Application_Common_DateHelper::playlistTimeToSeconds($time_filled); } public function getDurationSecs() diff --git a/airtime_mvc/application/models/Webstream.php b/airtime_mvc/application/models/Webstream.php index a32f275b1..a48e6c200 100644 --- a/airtime_mvc/application/models/Webstream.php +++ b/airtime_mvc/application/models/Webstream.php @@ -48,8 +48,8 @@ class Application_Model_Webstream{ $webstream->setDbLength($dblength); $webstream->setDbLogin($userInfo->id); - $webstream->setDbUtime(new DateTime()); - $webstream->setDbMtime(new DateTime()); + $webstream->setDbUtime(new DateTime($timezone = new DateTimeZone('UTC'))); + $webstream->setDbMtime(new DateTime($timezone = new DateTimeZone('UTC'))); $webstream->save(); } } diff --git a/airtime_mvc/public/js/airtime/showbuilder/builder.js b/airtime_mvc/public/js/airtime/showbuilder/builder.js index 0b45f0c65..8af595775 100644 --- a/airtime_mvc/public/js/airtime/showbuilder/builder.js +++ b/airtime_mvc/public/js/airtime/showbuilder/builder.js @@ -295,7 +295,7 @@ var AIRTIME = (function(AIRTIME){ }; mod.fnServerData = function fnBuilderServerData( sSource, aoData, fnCallback ) { - + aoData.push( { name: "timestamp", value: mod.getTimestamp()} ); aoData.push( { name: "instances", value: mod.getShowInstances()} ); aoData.push( { name: "format", value: "json"} ); diff --git a/python_apps/pypo/pypofetch.py b/python_apps/pypo/pypofetch.py index 7b6ba285f..ed8189dd2 100644 --- a/python_apps/pypo/pypofetch.py +++ b/python_apps/pypo/pypofetch.py @@ -432,7 +432,7 @@ class PypoFetch(Thread): """ if(media_item['type'] == 'file'): fileExt = os.path.splitext(media_item['uri'])[1] - dst = os.path.join(download_dir, media_item['id'] + fileExt) + dst = os.path.join(download_dir, unicode(media_item['id']) + fileExt) media_item['dst'] = dst media_item['file_ready'] = False media_filtered[key] = media_item @@ -462,7 +462,7 @@ class PypoFetch(Thread): media_item = media[mkey] if media_item['type'] == 'file': fileExt = os.path.splitext(media_item['uri'])[1] - scheduled_file_set.add(media_item["id"] + fileExt) + scheduled_file_set.add(unicode(media_item["id"]) + fileExt) expired_files = cached_file_set - scheduled_file_set diff --git a/python_apps/pypo/pypopush.py b/python_apps/pypo/pypopush.py index 3136ee355..628133f59 100644 --- a/python_apps/pypo/pypopush.py +++ b/python_apps/pypo/pypopush.py @@ -242,7 +242,11 @@ class PypoPush(Thread): for mkey in sorted_keys: media_item = media_schedule[mkey] if media_item['independent_event']: + if len(current_chain) > 0: + chains.append(current_chain) + chains.append([media_item]) + current_chain = [] elif len(current_chain) == 0: current_chain.append(media_item) elif media_item['start'] == current_chain[-1]['end']: