diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index a6f0825b7..43f9831bd 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -263,6 +263,14 @@ class ApiController extends Zend_Controller_Action $end_timestamp = $now->add(new DateInterval("PT2H")); $end_timestamp = $end_timestamp->format("Y-m-d H:i:s"); $this->view->shows = Show::getShows($today_timestamp, $end_timestamp, $excludeInstance=NULL, $onlyRecord=TRUE); + + + $this->view->is_recording = false; + + $rows = Show_DAL::GetCurrentShow($today_timestamp); + if (count($rows) > 0){ + $this->view->is_recording = ($rows[0]['record'] == 1); + } } public function uploadRecordedAction() diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index ca1428904..35a7a28bf 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -238,7 +238,7 @@ class ScheduleController extends Zend_Controller_Action if (strtotime($show->getShowStart()) <= strtotime($today_timestamp) && strtotime($today_timestamp) < strtotime($show->getShowEnd()) && - $user->isAdmin() && !$show->isRecorded()) { + $user->isAdmin()) { $menu[] = array('action' => array('type' => 'fn', 'callback' => "window['confirmCancelShow']($id)"), 'title' => 'Cancel Current Show'); diff --git a/python_apps/show-recorder/recorder.py b/python_apps/show-recorder/recorder.py index a574899ef..51871d7f5 100644 --- a/python_apps/show-recorder/recorder.py +++ b/python_apps/show-recorder/recorder.py @@ -14,12 +14,12 @@ from poster.encode import multipart_encode from poster.streaminghttp import register_openers import urllib2 -from subprocess import call +from subprocess import Popen from threading import Thread -# For RabbitMQ -from kombu.connection import BrokerConnection -from kombu.messaging import Exchange, Queue, Consumer, Producer +# For RabbitMQ - to be implemented in the future +#from kombu.connection import BrokerConnection +#from kombu.messaging import Exchange, Queue, Consumer, Producer from api_clients import api_client @@ -56,9 +56,9 @@ class ShowRecorder(Thread): self.filetype = filetype self.show_instance = show_instance self.logger = logging.getLogger('root') + self.p = None def record_show(self): - length = str(self.filelength)+".0" filename = self.show_name+" "+self.start_time filename = filename.replace(" ", "-") @@ -70,12 +70,27 @@ class ShowRecorder(Thread): self.logger.info("starting record") self.logger.info("command " + command) - - #Run command with arguments. Wait for command to complete, then return the returncode attribute. - code = call(args) + + self.p = Popen(args) + + #blocks at the following lines until the child process + #quits + code = self.p.wait() + self.p = None + self.logger.info("finishing record, return code %s", code) - return code, filepath + + def cancel_recording(self): + #send signal interrupt (2) + self.logger.info("Show manually cancelled!") + if (self.p is not None): + self.p.terminate() + self.p = None + + #if self.p is defined, then the child process ecasound is recording + def is_recording(self): + return (self.p is not None) def upload_file(self, filepath): @@ -105,6 +120,7 @@ class Record(): self.api_client = api_client.api_client_factory(config) self.shows_to_record = {} self.logger = logging.getLogger('root') + self.sr = None def process_shows(self, shows): @@ -117,7 +133,6 @@ class Record(): self.shows_to_record[show[u'starts']] = [time_delta, show[u'instance_id'], show[u'name']] - def check_record(self): tnow = datetime.datetime.now() @@ -140,8 +155,8 @@ class Record(): show_instance = self.shows_to_record[start_time][1] show_name = self.shows_to_record[start_time][2] - show = ShowRecorder(show_instance, show_length.seconds, show_name, start_time, filetype="mp3") - show.start() + self.sr = ShowRecorder(show_instance, show_length.seconds, show_name, start_time, filetype="mp3") + self.sr.start() #remove show from shows to record. del self.shows_to_record[start_time] @@ -150,6 +165,12 @@ class Record(): def get_shows(self): shows = self.api_client.get_shows_to_record() + + if self.sr is not None: + if not shows['is_recording'] and self.sr.is_recording(): + self.sr.cancel_recording() + + if shows is not None: shows = shows[u'shows'] else: