From 164c06a5e566dc74c70c528b9be61f27d0d64f3d Mon Sep 17 00:00:00 2001 From: Naomi Aro Date: Tue, 28 Jun 2011 14:34:16 +0200 Subject: [PATCH] CC-2441 : media-monitor exception on import, cancels all importing checking if file md fails. --- .../airtimefilemonitor/airtimemetadata.py | 14 +++++++--- .../airtimefilemonitor/airtimenotifier.py | 6 ++++- .../airtimefilemonitor/airtimeprocessevent.py | 26 +++++++++++-------- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimemetadata.py b/python_apps/media-monitor/airtimefilemonitor/airtimemetadata.py index 6a0b1cdcb..7a3079c4a 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimemetadata.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimemetadata.py @@ -104,11 +104,17 @@ class AirtimeMetadata: self.logger.info("getting info from filepath %s", filepath) - md = {} - md5 = self.get_md5(filepath) - md['MDATA_KEY_MD5'] = md5 + try: + md = {} + md5 = self.get_md5(filepath) + md['MDATA_KEY_MD5'] = md5 + + file_info = mutagen.File(filepath, easy=True) + + except Exception, e: + self.logger.error("failed getting metadata from %s", filepath) + return None - file_info = mutagen.File(filepath, easy=True) self.logger.info(file_info) diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py b/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py index 2932d4727..b93b6f909 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimenotifier.py @@ -123,6 +123,8 @@ class AirtimeNotifier(Notifier): if (os.path.exists(filepath) and (mode == self.config.MODE_CREATE)): if file_md is None: mutagen = self.md_manager.get_md_from_file(filepath) + if mutagen is None: + return md.update(mutagen) if d['is_recorded_show']: @@ -132,6 +134,8 @@ class AirtimeNotifier(Notifier): elif (os.path.exists(filepath) and (mode == self.config.MODE_MODIFY)): mutagen = self.md_manager.get_md_from_file(filepath) + if mutagen is None: + return md.update(mutagen) self.api_client.update_media_metadata(md, mode) @@ -163,5 +167,5 @@ class AirtimeNotifier(Notifier): if mm.is_audio_file(full_filepath): self.logger.info("importing %s", full_filepath) event = {'filepath': full_filepath, 'mode': self.config.MODE_CREATE, 'is_recorded_show': False} - mm.file_events.put(event) + mm.multi_queue.put(event) diff --git a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py index 7f7df9079..6b18a77dd 100644 --- a/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py +++ b/python_apps/media-monitor/airtimefilemonitor/airtimeprocessevent.py @@ -138,7 +138,7 @@ class AirtimeProcessEvent(ProcessEvent): return filepath - def create_file_path(self, imported_filepath): + def create_file_path(self, imported_filepath, orig_md): storage_directory = self.config.storage_directory @@ -149,7 +149,6 @@ class AirtimeProcessEvent(ProcessEvent): file_ext = os.path.splitext(imported_filepath)[1] file_ext = file_ext.encode('utf-8') - orig_md = self.md_manager.get_md_from_file(imported_filepath) path_md = ['MDATA_KEY_TITLE', 'MDATA_KEY_CREATOR', 'MDATA_KEY_SOURCE', 'MDATA_KEY_TRACKNUMBER', 'MDATA_KEY_BITRATE'] md = {} @@ -191,7 +190,7 @@ class AirtimeProcessEvent(ProcessEvent): except Exception, e: self.logger.error('Exception: %s', e) - return filepath, orig_md, is_recorded_show + return filepath, is_recorded_show def process_IN_CREATE(self, event): @@ -206,10 +205,13 @@ class AirtimeProcessEvent(ProcessEvent): elif self.is_audio_file(event.pathname): if self.is_parent_directory(event.pathname, storage_directory): self.set_needed_file_permissions(event.pathname, event.dir) - filepath, file_md, is_recorded_show = self.create_file_path(event.pathname) - self.move_file(event.pathname, filepath) - self.renamed_files[event.pathname] = filepath - self.file_events.append({'mode': self.config.MODE_CREATE, 'filepath': filepath, 'data': file_md, 'is_recorded_show': is_recorded_show}) + file_md = self.md_manager.get_md_from_file(event.pathname) + + if file_md is not None: + filepath, is_recorded_show = self.create_file_path(event.pathname, file_md) + self.move_file(event.pathname, filepath) + self.renamed_files[event.pathname] = filepath + self.file_events.append({'mode': self.config.MODE_CREATE, 'filepath': filepath, 'data': file_md, 'is_recorded_show': is_recorded_show}) else: self.file_events.append({'mode': self.config.MODE_CREATE, 'filepath': event.pathname, 'is_recorded_show': False}) @@ -256,10 +258,12 @@ class AirtimeProcessEvent(ProcessEvent): # show dragged from unwatched folder into a watched folder. storage_directory = self.config.storage_directory if self.is_parent_directory(event.pathname, storage_directory): - filepath, file_md, is_recorded_show = self.create_file_path(event.pathname) - self.move_file(event.pathname, filepath) - self.renamed_files[event.pathname] = filepath - self.file_events.append({'mode': self.config.MODE_CREATE, 'filepath': filepath, 'data': file_md, 'is_recorded_show': False}) + file_md = self.md_manager.get_md_from_file(event.pathname) + if file_md is not None: + filepath, is_recorded_show = self.create_file_path(event.pathname) + self.move_file(event.pathname, filepath) + self.renamed_files[event.pathname] = filepath + self.file_events.append({'mode': self.config.MODE_CREATE, 'filepath': filepath, 'data': file_md, 'is_recorded_show': False}) else: self.file_events.append({'mode': self.config.MODE_CREATE, 'filepath': event.pathname, 'is_recorded_show': False})