diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index dce293b0d..3441668da 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -63,7 +63,7 @@ class ApiController extends Zend_Controller_Action $this->_helper->viewRenderer->setNoRender(true); $api_key = $this->_getParam('api_key'); - $download = $this->_getParam('download'); + $downlaod = $this->_getParam('download'); if(!in_array($api_key, $CC_CONFIG["apiKey"])) { @@ -100,15 +100,15 @@ class ApiController extends Zend_Controller_Action // !! binary mode !! $fp = fopen($filepath, 'rb'); - + //We can have multiple levels of output buffering. Need to //keep looping until all have been disabled!!! //http://www.php.net/manual/en/function.ob-end-flush.php while (@ob_end_flush()); - + fpassthru($fp); fclose($fp); - + return; } } @@ -357,8 +357,9 @@ class ApiController extends Zend_Controller_Action } $md = $this->_getParam('md'); - - $file = StoredFile::Recall(null, $md['gunid']); + $filepath = $md['filepath']; + $filepath = str_replace("\\", "", $filepath); + $file = StoredFile::Recall(null, null, null, $filepath); if (PEAR::isError($file) || is_null($file)) { $this->view->response = "File not in Airtime's Database"; return; diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index ba152f49e..cdc17423e 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -703,7 +703,7 @@ class StoredFile { * @return StoredFile|Playlist|NULL * Return NULL if the object doesnt exist in the DB. */ - public static function Recall($p_id=null, $p_gunid=null, $p_md5sum=null) + public static function Recall($p_id=null, $p_gunid=null, $p_md5sum=null, $p_filepath=null) { global $CC_DBC; global $CC_CONFIG; @@ -713,6 +713,8 @@ class StoredFile { $cond = "gunid='$p_gunid'"; } elseif (!is_null($p_md5sum)) { $cond = "md5='$p_md5sum'"; + } elseif (!is_null($p_filepath)) { + $cond = "filepath='$p_filepath'"; } else { return null; } diff --git a/python_apps/media-monitor/MediaMonitor.py b/python_apps/media-monitor/MediaMonitor.py index afb249f73..5b34455e7 100644 --- a/python_apps/media-monitor/MediaMonitor.py +++ b/python_apps/media-monitor/MediaMonitor.py @@ -71,7 +71,7 @@ class AirtimeNotifier(Notifier): "isrc_number": "isrc",\ "copyright": "copyright",\ } - + schedule_exchange = Exchange("airtime-media-monitor", "direct", durable=True, auto_delete=True) schedule_queue = Queue("media-monitor", exchange=schedule_exchange, key="filesystem") self.connection = BrokerConnection(config["rabbitmq_host"], config["rabbitmq_user"], config["rabbitmq_password"], "/") @@ -87,7 +87,7 @@ class AirtimeNotifier(Notifier): logger = logging.getLogger('root') logger.info("Received md from RabbitMQ: " + body) - m = json.loads(message.body) + m = json.loads(message.body) airtime_file = mutagen.File(m['filepath'], easy=True) del m['filepath'] for key in m.keys() : @@ -124,21 +124,19 @@ class MediaMonitor(ProcessEvent): "copyright": "copyright",\ } + self.supported_file_formats = ['mp3', 'ogg'] self.logger = logging.getLogger('root') - self.temp_files = {} def update_airtime(self, event): self.logger.info("Updating Change to Airtime") - try: + try: f = open(event.pathname, 'rb') m = hashlib.md5() m.update(f.read()) - md5 = m.hexdigest() - gunid = event.name.split('.')[0] - md = {'gunid':gunid, 'md5':md5} + md = {'filepath':event.pathname, 'md5':md5} file_info = mutagen.File(event.pathname, easy=True) attrs = self.mutagen2airtime @@ -153,12 +151,28 @@ class MediaMonitor(ProcessEvent): except Exception, e: self.logger.info("%s", e) + def is_temp_file(self, filename): + info = filename.split(".") + + if(info[-2] in self.supported_file_formats): + return True + else : + return False + + def is_audio_file(self, filename): + info = filename.split(".") + + if(info[-1] in self.supported_file_formats): + return True + else : + return False + + def process_IN_CREATE(self, event): if not event.dir : - filename_info = event.name.split(".") #file created is a tmp file which will be modified and then moved back to the original filename. - if len(filename_info) > 2 : + if self.is_temp_file(event.name) : self.temp_files[event.pathname] = None #This is a newly imported file. else : @@ -166,18 +180,13 @@ class MediaMonitor(ProcessEvent): self.logger.info("%s: %s", event.maskname, event.pathname) - #event.path : /srv/airtime/stor/bd2 - #event.name : bd2aa73b58d9c8abcced989621846e99.mp3 - #event.pathname : /srv/airtime/stor/bd2/bd2aa73b58d9c8abcced989621846e99.mp3 def process_IN_MODIFY(self, event): if not event.dir : - filename_info = event.name.split(".") - #file modified is not a tmp file. - if len(filename_info) == 2 : - self.update_airtime(event) + if self.is_audio_file(event.name) : + self.update_airtime(event) - self.logger.info("%s: path: %s name: %s", event.maskname, event.path, event.name) + self.logger.info("%s: %s", event.maskname, event.pathname) def process_IN_MOVED_FROM(self, event): if event.pathname in self.temp_files : @@ -190,7 +199,7 @@ class MediaMonitor(ProcessEvent): if event.cookie in self.temp_files : del self.temp_files[event.cookie] self.update_airtime(event) - + self.logger.info("%s: %s", event.maskname, event.pathname) def process_default(self, event):