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
|
@ -64,7 +64,7 @@ class ApiController extends Zend_Controller_Action
|
||||||
|
|
||||||
$api_key = $this->_getParam('api_key');
|
$api_key = $this->_getParam('api_key');
|
||||||
$downlaod = $this->_getParam('download');
|
$downlaod = $this->_getParam('download');
|
||||||
|
|
||||||
if(!in_array($api_key, $CC_CONFIG["apiKey"]))
|
if(!in_array($api_key, $CC_CONFIG["apiKey"]))
|
||||||
{
|
{
|
||||||
header('HTTP/1.0 401 Unauthorized');
|
header('HTTP/1.0 401 Unauthorized');
|
||||||
|
@ -331,8 +331,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;
|
||||||
|
|
|
@ -701,7 +701,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;
|
||||||
|
@ -711,6 +711,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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ class AirtimeNotifier(Notifier):
|
||||||
"isrc_number": "isrc",\
|
"isrc_number": "isrc",\
|
||||||
"copyright": "copyright",\
|
"copyright": "copyright",\
|
||||||
}
|
}
|
||||||
|
|
||||||
schedule_exchange = Exchange("airtime-media-monitor", "direct", durable=True, auto_delete=True)
|
schedule_exchange = Exchange("airtime-media-monitor", "direct", durable=True, auto_delete=True)
|
||||||
schedule_queue = Queue("media-monitor", exchange=schedule_exchange, key="filesystem")
|
schedule_queue = Queue("media-monitor", exchange=schedule_exchange, key="filesystem")
|
||||||
self.connection = BrokerConnection(config["rabbitmq_host"], config["rabbitmq_user"], config["rabbitmq_password"], "/")
|
self.connection = BrokerConnection(config["rabbitmq_host"], config["rabbitmq_user"], config["rabbitmq_password"], "/")
|
||||||
|
@ -86,7 +86,7 @@ class AirtimeNotifier(Notifier):
|
||||||
logger = logging.getLogger('root')
|
logger = logging.getLogger('root')
|
||||||
logger.info("Received md from RabbitMQ: " + body)
|
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)
|
airtime_file = mutagen.File(m['filepath'], easy=True)
|
||||||
del m['filepath']
|
del m['filepath']
|
||||||
for key in m.keys() :
|
for key in m.keys() :
|
||||||
|
@ -123,21 +123,19 @@ 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):
|
||||||
self.logger.info("Updating Change to Airtime")
|
self.logger.info("Updating Change to Airtime")
|
||||||
try:
|
try:
|
||||||
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
|
||||||
|
@ -152,12 +150,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 :
|
||||||
|
@ -165,18 +179,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 :
|
||||||
|
@ -189,7 +198,7 @@ class MediaMonitor(ProcessEvent):
|
||||||
if event.cookie in self.temp_files :
|
if event.cookie in self.temp_files :
|
||||||
del self.temp_files[event.cookie]
|
del self.temp_files[event.cookie]
|
||||||
self.update_airtime(event)
|
self.update_airtime(event)
|
||||||
|
|
||||||
self.logger.info("%s: %s", event.maskname, event.pathname)
|
self.logger.info("%s: %s", event.maskname, event.pathname)
|
||||||
|
|
||||||
def process_default(self, event):
|
def process_default(self, event):
|
||||||
|
|
Loading…
Reference in New Issue