diff --git a/airtime_mvc/application/configs/constants.php b/airtime_mvc/application/configs/constants.php index df5ef7741..ffc94d660 100644 --- a/airtime_mvc/application/configs/constants.php +++ b/airtime_mvc/application/configs/constants.php @@ -13,12 +13,11 @@ define('MDATA_KEY_SOURCE', 'album_title'); define('MDATA_KEY_DURATION', 'length'); define('MDATA_KEY_MIME', 'mime'); define('MDATA_KEY_FTYPE', 'ftype'); -define('MDATA_KEY_URL', 'url'); +define('MDATA_KEY_URL', 'info_url'); define('MDATA_KEY_GENRE', 'genre'); define('MDATA_KEY_MOOD', 'mood'); define('MDATA_KEY_LABEL', 'label'); define('MDATA_KEY_COMPOSER', 'composer'); -define('MDATA_KEY_FORMAT', 'format'); define('MDATA_KEY_DESCRIPTION', 'description'); define('MDATA_KEY_SAMPLERATE', 'sample_rate'); define('MDATA_KEY_BITRATE', 'bit_rate'); diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index cc45408bf..6c35f491c 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -164,8 +164,7 @@ class LibraryController extends Zend_Controller_Action $formdata = $form->getValues(); $file->setDbColMetadata($formdata); - $data = $formdata; - $data['filepath'] = $file->getFilePath(); + $data = $file->getMetadata(); RabbitMq::SendFileMetaData($data); diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 6cb22b723..aa7dbef92 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -190,6 +190,27 @@ class StoredFile { return $md; } + /** + * Get metadata as array, indexed by the constant names. + * + * @return array + */ + public function getMetadata() + { + $c = get_defined_constants(true); + $md = array(); + + foreach ($c['user'] as $constant => $value) { + if (preg_match('/^MDATA_KEY/', $constant)) { + if (isset($this->_dbMD[$value])) { + $md[$constant] = $this->getDbColMetadataValue($value); + } + } + } + + return $md; + } + /** * Delete and insert media file * diff --git a/python_apps/media-monitor/MediaMonitor.py b/python_apps/media-monitor/MediaMonitor.py index a909e2874..0773ac456 100644 --- a/python_apps/media-monitor/MediaMonitor.py +++ b/python_apps/media-monitor/MediaMonitor.py @@ -85,21 +85,31 @@ class AirtimeNotifier(Notifier): consumer.register_callback(self.handle_message) consumer.consume() + self.logger = logging.getLogger('root') + def handle_message(self, body, message): # ACK the message to take it off the queue message.ack() - logger = logging.getLogger('root') - logger.info("Received md from RabbitMQ: " + body) + self.logger.info("Received md from RabbitMQ: " + body) - m = json.loads(message.body) - airtime_file = mutagen.File(m['filepath'], easy=True) - del m['filepath'] - for key in m.keys() : - if m[key] != "" : - airtime_file[self.airtime2mutagen[key]] = m[key] + try: + m = json.loads(message.body) + airtime_file = mutagen.File(m['MDATA_KEY_FILEPATH'], easy=True) - airtime_file.save() + for key in m.keys() : + if key in self.airtime2mutagen: + value = m[key] + if ((value is not None) and (len(str(value)) > 0)): + airtime_file[self.airtime2mutagen[key]] = str(value) + self.logger.info('setting %s = %s ', key, str(value)) + + + airtime_file.save() + except Exception, e: + self.logger.error('Trying to save md') + self.logger.error('Exception: %s', e.value) + self.logger.error('Filepath %s', m['MDATA_KEY_FILEPATH']) class MediaMonitor(ProcessEvent):