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:
parent
1eea96eefc
commit
ea1b254ebd
|
@ -331,8 +331,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;
|
||||
|
|
|
@ -701,7 +701,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;
|
||||
|
@ -711,6 +711,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;
|
||||
}
|
||||
|
|
|
@ -123,8 +123,8 @@ class MediaMonitor(ProcessEvent):
|
|||
"copyright": "copyright",\
|
||||
}
|
||||
|
||||
self.supported_file_formats = ['mp3', 'ogg']
|
||||
self.logger = logging.getLogger('root')
|
||||
|
||||
self.temp_files = {}
|
||||
|
||||
def update_airtime(self, event):
|
||||
|
@ -133,11 +133,9 @@ class MediaMonitor(ProcessEvent):
|
|||
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
|
||||
|
@ -152,12 +150,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 :
|
||||
|
@ -165,18 +179,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 :
|
||||
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 :
|
||||
|
|
Loading…
Reference in New Issue