From 1e8c8f81572a28974f04a09f7fe1fa9805890a27 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Mon, 9 Jul 2012 11:21:12 -0400 Subject: [PATCH] add a few try catch blocks --- .../airtimefilemonitor/airtimemetadata.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimemetadata.py b/python_apps/media-monitor/airtimefilemonitor/airtimemetadata.py index e7b6ad01d..cea950cba 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimemetadata.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimemetadata.py @@ -221,9 +221,20 @@ class AirtimeMetadata: md['MDATA_KEY_COPYRIGHT'] = self.truncate_to_length(md['MDATA_KEY_COPYRIGHT'], 512) #end of db truncation checks. - md['MDATA_KEY_BITRATE'] = getattr(file_info.info, "bitrate", None) - md['MDATA_KEY_SAMPLERATE'] = getattr(file_info.info, "sample_rate", None) - self.logger.info( "Bitrate: %s , Samplerate: %s", md['MDATA_KEY_BITRATE'], md['MDATA_KEY_SAMPLERATE'] ) + try: + md['MDATA_KEY_BITRATE'] = getattr(file_info.info, "bitrate", "0") + except Exception as e: + self.logger.warn("Could not get Bitrate") + md['MDATA_KEY_BITRATE'] = "0" + + try: + md['MDATA_KEY_SAMPLERATE'] = getattr(file_info.info, "sample_rate", "0") + except Exception as e: + self.logger.warn("Could not get Samplerate") + md['MDATA_KEY_SAMPLERATE'] = "0" + + self.logger.info("Bitrate: %s , Samplerate: %s", md['MDATA_KEY_BITRATE'], md['MDATA_KEY_SAMPLERATE']) + try: md['MDATA_KEY_DURATION'] = self.format_length(file_info.info.length) except Exception as e: self.logger.warn("File: '%s' raises: %s", filepath, str(e))