From 6e9db647c1ef4c1f4f183d8534010f12a1dfe298 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 30 Jul 2012 12:14:06 -0400 Subject: [PATCH] cc-4105: Fixed metadata handling. Added more error reporting to rmq requests --- .../application/controllers/ApiController.php | 3 +++ .../media-monitor2/media/monitor/airtime.py | 3 ++- .../media-monitor2/media/monitor/pure.py | 17 ++++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 128f65413..d478ceb3f 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -610,6 +610,9 @@ class ApiController extends Zend_Controller_Action } } + Logging::log("MM request>>>>>>>"); + Logging::log( $md ); + // update import timestamp Application_Model_Preference::SetImportTimestamp(); if ($mode == "create") { diff --git a/python_apps/media-monitor2/media/monitor/airtime.py b/python_apps/media-monitor2/media/monitor/airtime.py index ffd31fa00..d2d9a1d05 100644 --- a/python_apps/media-monitor2/media/monitor/airtime.py +++ b/python_apps/media-monitor2/media/monitor/airtime.py @@ -176,12 +176,13 @@ class AirtimeMessageReceiver(Loggable): # verify that. self.logger.info("Attempting to delete(maybe) '%s'" % msg['filepath']) if msg['delete']: - self.logger.info("Clippy confirmation was received, actually deleting file...") if os.path.exists(msg['filepath']): try: self.logger.info("Attempting to delete '%s'" % msg['filepath']) FileMediator.ignore(msg['filepath']) os.unlink(msg['filepath']) + if not os.path.exists(msg['filepath']): + self.logger.info("Successfully deleted: '%s'" % msg['filepath']) except Exception as e: self.logger.info("Failed to delete '%s'" % msg['filepath']) self.logger.info("Error: " % str(e)) diff --git a/python_apps/media-monitor2/media/monitor/pure.py b/python_apps/media-monitor2/media/monitor/pure.py index 3395a88bb..43a7cce8c 100644 --- a/python_apps/media-monitor2/media/monitor/pure.py +++ b/python_apps/media-monitor2/media/monitor/pure.py @@ -140,6 +140,19 @@ def default_to(dictionary, keys, default): if not (k in new_d): new_d[k] = default return new_d +def remove_whitespace(dictionary): + """Remove values that empty whitespace in the dictionary""" + nd = copy.deepcopy(dictionary) + bad_keys = [] + for k,v in nd.iteritems(): + stripped = v.strip() + # ghetto and maybe unnecessary + if stripped == '' or stripped == u'': + bad_keys.append(k) + for bad_key in bad_keys: del nd[bad_key] + return nd + + def normalized_metadata(md, original_path): """ consumes a dictionary of metadata and returns a new dictionary with the formatted meta data. We also consume original_path because we must set @@ -157,6 +170,7 @@ def normalized_metadata(md, original_path): 'MDATA_KEY_BITRATE' : lambda x: str(int(x) / 1000) + "kbps", # note: you don't actually need the lambda here. It's only used for clarity 'MDATA_KEY_FILEPATH' : lambda x: os.path.normpath(x), + 'MDATA_KEY_MIME' : lambda x: x.replace('-','/') } path_md = ['MDATA_KEY_TITLE', 'MDATA_KEY_CREATOR', 'MDATA_KEY_SOURCE', 'MDATA_KEY_TRACKNUMBER', 'MDATA_KEY_BITRATE'] @@ -168,6 +182,7 @@ def normalized_metadata(md, original_path): new_md = apply_rules_dict(new_md, format_rules) new_md = default_to(dictionary=new_md, keys=['MDATA_KEY_TITLE'], default=no_extension_basename(original_path)) new_md = default_to(dictionary=new_md, keys=path_md, default=unicode_unknown) + new_md = default_to(dictionary=new_md, keys=['MDATA_KEY_FTYPE'], default=u'audioclip') # In the case where the creator is 'Airtime Show Recorder' we would like to # format the MDATA_KEY_TITLE slightly differently # Note: I don't know why I'm doing a unicode string comparison here @@ -182,7 +197,7 @@ def normalized_metadata(md, original_path): # be set to the original path of the file for airtime recorded shows # (before it was "organized"). We will skip this procedure for now # because it's not clear why it was done - return new_md + return remove_whitespace(new_md) def organized_path(old_path, root_path, normal_md): """