cc-2419: media monitor import on startup

-added multiple dir support
This commit is contained in:
martin 2011-07-04 15:08:02 -04:00
parent ae156c85b4
commit d260c66abc
5 changed files with 68 additions and 21 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -108,6 +108,9 @@ class ApiClientInterface:
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
def test(self):
pass
@ -422,6 +425,23 @@ class AirTimeApiClient(ApiClientInterface):
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
################################################################################

View File

@ -22,7 +22,9 @@ 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)
@ -30,6 +32,10 @@ class AirtimeMediaMonitorBootstrap():
def list_db_files(self):
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
#twice. This is become some of the tests for new files return result sets that are not
@ -86,8 +92,6 @@ class AirtimeMediaMonitorBootstrap():
#"touch" file timestamp
open("/var/tmp/airtime/media_monitor_boot","w")
#return
for file_path in deleted_files_set:
self.pe.handle_removed_file(file_path)

View File

@ -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 #
############################################