CC-1799 Put Airtime Storage into a Human Readable File Naming Convention

searching database by filename to retrieve file.
Checking if is supported audio file/temp audio file.
This commit is contained in:
Naomi 2011-05-13 18:03:34 -04:00 committed by Naomi Aro
parent efc8d0664c
commit 6dfad55b89
3 changed files with 37 additions and 25 deletions

View File

@ -63,7 +63,7 @@ class ApiController extends Zend_Controller_Action
$this->_helper->viewRenderer->setNoRender(true); $this->_helper->viewRenderer->setNoRender(true);
$api_key = $this->_getParam('api_key'); $api_key = $this->_getParam('api_key');
$download = $this->_getParam('download'); $downlaod = $this->_getParam('download');
if(!in_array($api_key, $CC_CONFIG["apiKey"])) if(!in_array($api_key, $CC_CONFIG["apiKey"]))
{ {
@ -357,8 +357,9 @@ class ApiController extends Zend_Controller_Action
} }
$md = $this->_getParam('md'); $md = $this->_getParam('md');
$filepath = $md['filepath'];
$file = StoredFile::Recall(null, $md['gunid']); $filepath = str_replace("\\", "", $filepath);
$file = StoredFile::Recall(null, null, null, $filepath);
if (PEAR::isError($file) || is_null($file)) { if (PEAR::isError($file) || is_null($file)) {
$this->view->response = "File not in Airtime's Database"; $this->view->response = "File not in Airtime's Database";
return; return;

View File

@ -703,7 +703,7 @@ class StoredFile {
* @return StoredFile|Playlist|NULL * @return StoredFile|Playlist|NULL
* Return NULL if the object doesnt exist in the DB. * 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_DBC;
global $CC_CONFIG; global $CC_CONFIG;
@ -713,6 +713,8 @@ class StoredFile {
$cond = "gunid='$p_gunid'"; $cond = "gunid='$p_gunid'";
} elseif (!is_null($p_md5sum)) { } elseif (!is_null($p_md5sum)) {
$cond = "md5='$p_md5sum'"; $cond = "md5='$p_md5sum'";
} elseif (!is_null($p_filepath)) {
$cond = "filepath='$p_filepath'";
} else { } else {
return null; return null;
} }

View File

@ -124,8 +124,8 @@ class MediaMonitor(ProcessEvent):
"copyright": "copyright",\ "copyright": "copyright",\
} }
self.supported_file_formats = ['mp3', 'ogg']
self.logger = logging.getLogger('root') self.logger = logging.getLogger('root')
self.temp_files = {} self.temp_files = {}
def update_airtime(self, event): def update_airtime(self, event):
@ -134,11 +134,9 @@ class MediaMonitor(ProcessEvent):
f = open(event.pathname, 'rb') f = open(event.pathname, 'rb')
m = hashlib.md5() m = hashlib.md5()
m.update(f.read()) m.update(f.read())
md5 = m.hexdigest() 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) file_info = mutagen.File(event.pathname, easy=True)
attrs = self.mutagen2airtime attrs = self.mutagen2airtime
@ -153,12 +151,28 @@ class MediaMonitor(ProcessEvent):
except Exception, e: except Exception, e:
self.logger.info("%s", 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): def process_IN_CREATE(self, event):
if not event.dir : 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. #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 self.temp_files[event.pathname] = None
#This is a newly imported file. #This is a newly imported file.
else : else :
@ -166,18 +180,13 @@ class MediaMonitor(ProcessEvent):
self.logger.info("%s: %s", event.maskname, event.pathname) 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): def process_IN_MODIFY(self, event):
if not event.dir : if not event.dir :
filename_info = event.name.split(".")
#file modified is not a tmp file. if self.is_audio_file(event.name) :
if len(filename_info) == 2 :
self.update_airtime(event) 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): def process_IN_MOVED_FROM(self, event):
if event.pathname in self.temp_files : if event.pathname in self.temp_files :