cc-2419: media monitor import on startup
-added multiple dir support
This commit is contained in:
parent
ae156c85b4
commit
d260c66abc
|
@ -15,6 +15,7 @@ class ApiController extends Zend_Controller_Action
|
|||
->addActionContext('media-item-status', 'json')
|
||||
->addActionContext('reload-metadata', 'json')
|
||||
->addActionContext('list-all-files', 'json')
|
||||
->addActionContext('list-all-watched-dirs', 'json')
|
||||
->initContext();
|
||||
}
|
||||
|
||||
|
@ -523,5 +524,31 @@ class ApiController extends Zend_Controller_Action
|
|||
|
||||
$this->view->files = StoredFile::listAllFiles();
|
||||
}
|
||||
|
||||
public function listAllWatchedDirsAction() {
|
||||
global $CC_CONFIG;
|
||||
|
||||
$request = $this->getRequest();
|
||||
$api_key = $request->getParam('api_key');
|
||||
if (!in_array($api_key, $CC_CONFIG["apiKey"]))
|
||||
{
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
print 'You are not allowed to access this resource.';
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
|
||||
$arrWatchedDirs = MusicDir::getWatchedDirs();
|
||||
$storDir = MusicDir::getStorDir();
|
||||
|
||||
$result[] = $storDir->getDirectory();
|
||||
|
||||
foreach ($arrWatchedDirs as $watchedDir){
|
||||
$result[] = $watchedDir->getDirectory();
|
||||
}
|
||||
|
||||
$this->view->dirs = $result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,9 +7,9 @@ class MusicDir {
|
|||
*/
|
||||
private $_dir;
|
||||
|
||||
public function __construct()
|
||||
public function __construct($dir)
|
||||
{
|
||||
|
||||
$this->_dir = $dir;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
|
@ -50,8 +50,7 @@ class MusicDir {
|
|||
$dir->setDirectory($p_path);
|
||||
$dir->save();
|
||||
|
||||
$mus_dir = new MusicDir();
|
||||
$mus_dir->_dir = $dir;
|
||||
$mus_dir = new MusicDir($dir);
|
||||
|
||||
return $mus_dir;
|
||||
}
|
||||
|
@ -65,8 +64,7 @@ class MusicDir {
|
|||
{
|
||||
$dir = CcMusicDirsQuery::create()->findPK($pk);
|
||||
|
||||
$mus_dir = new MusicDir();
|
||||
$mus_dir->_dir = $dir;
|
||||
$mus_dir = new MusicDir($dir);
|
||||
|
||||
return $mus_dir;
|
||||
}
|
||||
|
@ -77,9 +75,7 @@ class MusicDir {
|
|||
->filterByDirectory($p_path)
|
||||
->findOne();
|
||||
|
||||
$mus_dir = new MusicDir();
|
||||
$mus_dir->_dir = $dir;
|
||||
|
||||
$mus_dir = new MusicDir($dir);
|
||||
return $mus_dir;
|
||||
}
|
||||
|
||||
|
@ -92,9 +88,7 @@ class MusicDir {
|
|||
->find();
|
||||
|
||||
foreach($dirs as $dir) {
|
||||
$tmp = new MusicDir();
|
||||
$tmp->_dir = $dir;
|
||||
|
||||
$tmp = new MusicDir($dir);
|
||||
$result[] = $tmp;
|
||||
}
|
||||
|
||||
|
@ -107,7 +101,7 @@ class MusicDir {
|
|||
->filterByType("stor")
|
||||
->findOne();
|
||||
|
||||
$mus_dir = new MusicDir();
|
||||
$mus_dir = new MusicDir($dir);
|
||||
$mus_dir->_dir = $dir;
|
||||
|
||||
return $mus_dir;
|
||||
|
@ -127,8 +121,7 @@ class MusicDir {
|
|||
foreach($dirs as $dir) {
|
||||
$directory = $dir->getDirectory();
|
||||
if (substr($p_filepath, 0, strlen($directory)) === $directory) {
|
||||
$mus_dir = new MusicDir();
|
||||
$mus_dir->_dir = $dir;
|
||||
$mus_dir = new MusicDir($dir);
|
||||
return $mus_dir;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,6 +106,9 @@ class ApiClientInterface:
|
|||
pass
|
||||
|
||||
def list_all_db_files(self):
|
||||
pass
|
||||
|
||||
def list_all_watched_dirs(self):
|
||||
pass
|
||||
|
||||
# Put here whatever tests you want to run to make sure your API is working
|
||||
|
@ -421,7 +424,24 @@ class AirTimeApiClient(ApiClientInterface):
|
|||
logger.error("Exception: %s", e)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
def list_all_watched_dirs(self):
|
||||
logger = logging.getLogger()
|
||||
try:
|
||||
url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["list_all_watched_dirs"])
|
||||
|
||||
|
||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
||||
logger.debug(url)
|
||||
|
||||
req = urllib2.Request(url)
|
||||
response = urllib2.urlopen(req).read()
|
||||
response = json.loads(response)
|
||||
except Exception, e:
|
||||
response = None
|
||||
logger.error("Exception: %s", e)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
################################################################################
|
||||
|
|
|
@ -22,13 +22,19 @@ class AirtimeMediaMonitorBootstrap():
|
|||
went offline. We can do this by doing a hash of the directory metadata.
|
||||
"""
|
||||
def scan(self):
|
||||
directories = ['/srv/airtime/stor']
|
||||
directories = self.get_list_of_watched_dirs();
|
||||
|
||||
self.logger.info("watched directories found: %s", directories)
|
||||
|
||||
for dir in directories:
|
||||
self.check_for_diff(dir)
|
||||
|
||||
def list_db_files(self):
|
||||
return self.api_client.list_all_db_files()
|
||||
return self.api_client.list_all_db_files()
|
||||
|
||||
def get_list_of_watched_dirs(self):
|
||||
json = self.api_client.list_all_watched_dirs()
|
||||
return json["dirs"]
|
||||
|
||||
def check_for_diff(self, dir):
|
||||
#set to hold new and/or modified files. We use a set to make it ok if files are added
|
||||
|
@ -85,9 +91,7 @@ class AirtimeMediaMonitorBootstrap():
|
|||
self.logger.info("Modified files: \n%s\n\n"%modified_files_set)
|
||||
|
||||
#"touch" file timestamp
|
||||
open("/var/tmp/airtime/media_monitor_boot","w")
|
||||
#return
|
||||
|
||||
open("/var/tmp/airtime/media_monitor_boot","w")
|
||||
|
||||
for file_path in deleted_files_set:
|
||||
self.pe.handle_removed_file(file_path)
|
||||
|
|
|
@ -31,6 +31,9 @@ update_media_url = 'reload-metadata/format/json/api_key/%%api_key%%/mode/%%mode%
|
|||
# URL to tell Airtime we want a listing of all files it knows about
|
||||
list_all_db_files = 'list-all-files/format/json/api_key/%%api_key%%'
|
||||
|
||||
# URL to tell Airtime we want a listing of all dirs its watching (including the stor dir)
|
||||
list_all_watched_dirs = 'list-all-watched-dirs/format/json/api_key/%%api_key%%'
|
||||
|
||||
############################################
|
||||
# RabbitMQ settings #
|
||||
############################################
|
||||
|
|
Loading…
Reference in New Issue