diff --git a/python_apps/show-recorder/recorder.cfg b/python_apps/show-recorder/recorder.cfg index c010a8645..d817a32b2 100644 --- a/python_apps/show-recorder/recorder.cfg +++ b/python_apps/show-recorder/recorder.cfg @@ -24,6 +24,7 @@ record_bitrate = 256 record_samplerate = 44100 record_channels = 2 record_sample_size = 16 +record_timeout = 3600 #can be either ogg|mp3, mp3 recording requires installation of the package "lame" record_file_type = 'ogg' diff --git a/python_apps/show-recorder/recorder.py b/python_apps/show-recorder/recorder.py index 7ac18b046..3ec1caf39 100644 --- a/python_apps/show-recorder/recorder.py +++ b/python_apps/show-recorder/recorder.py @@ -179,8 +179,7 @@ class CommandListener(): self.sr = None self.current_schedule = {} self.shows_to_record = {} - self.time_till_next_show = 3600 - self.real_timeout = True + self.time_till_next_show = config["record_timeout"] self.logger.info("RecorderFetch: init complete") self.server_timezone = ''; @@ -214,7 +213,7 @@ class CommandListener(): self.parse_shows(temp) self.server_timezone = m['server_timezone'] elif(command == 'cancel_recording'): - if self.sr.is_recording(): + if self.sr is not None and self.sr.is_recording(): self.sr.cancel_recording() def parse_shows(self, shows): @@ -241,14 +240,12 @@ class CommandListener(): next_show = getDateTimeObj(start_time) delta = next_show - tnow - self.real_timeout = False out = delta.seconds self.logger.debug("Next show %s", next_show) self.logger.debug("Now %s", tnow) else: - self.real_timeout = True - out = 3600 + out = config["record_timeout"] return out def start_record(self): @@ -276,8 +273,6 @@ class CommandListener(): #remove show from shows to record. del self.shows_to_record[start_time] self.time_till_next_show = self.get_time_till_next_show() - # set real_timtout to false no matter what - self.real_timeout = False except Exception,e : import traceback top = traceback.format_exc() @@ -316,14 +311,21 @@ class CommandListener(): self.logger.info("Loop #%s", loops) try: # block until 5 seconds before the next show start - self.connection.drain_events(timeout=self.time_till_next_show) + self.connection.drain_events(timeout=int(self.time_till_next_show)) except socket.timeout, s: self.logger.info(s) + + # start_record set time_till_next_show to config["record_timeout"] so we should check before + # if timeout amount was 1 hr.. + update_schedule = False + if int(self.time_till_next_show) == int(config["record_timeout"]) : + update_schedule = True + # start recording self.start_record() # if real timeout happended get show schedule from airtime - if self.real_timeout : + if update_schedule : temp = self.api_client.get_shows_to_record() if temp is not None: shows = temp['shows'] @@ -332,7 +334,10 @@ class CommandListener(): self.logger.info("Real Timeout: the schedule has updated") except Exception, e: - self.logger.info(e) + import traceback + top = traceback.format_exc() + self.logger.error('Exception: %s', e) + self.logger.error("traceback: %s", top) time.sleep(3) loops += 1