cc-2419: media monitor import on startup
-fixed support for watched dirs
This commit is contained in:
parent
c67e711a05
commit
df1dec2078
7 changed files with 38 additions and 22 deletions
|
@ -521,8 +521,9 @@ class ApiController extends Zend_Controller_Action
|
||||||
print 'You are not allowed to access this resource.';
|
print 'You are not allowed to access this resource.';
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
$dir_id = $request->getParam('dir_id');
|
||||||
|
|
||||||
$this->view->files = StoredFile::listAllFiles();
|
$this->view->files = StoredFile::listAllFiles($dir_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listAllWatchedDirsAction() {
|
public function listAllWatchedDirsAction() {
|
||||||
|
@ -542,10 +543,10 @@ class ApiController extends Zend_Controller_Action
|
||||||
$arrWatchedDirs = MusicDir::getWatchedDirs();
|
$arrWatchedDirs = MusicDir::getWatchedDirs();
|
||||||
$storDir = MusicDir::getStorDir();
|
$storDir = MusicDir::getStorDir();
|
||||||
|
|
||||||
$result[] = $storDir->getDirectory();
|
$result[$storDir->getId()] = $storDir->getDirectory();
|
||||||
|
|
||||||
foreach ($arrWatchedDirs as $watchedDir){
|
foreach ($arrWatchedDirs as $watchedDir){
|
||||||
$result[] = $watchedDir->getDirectory();
|
$result[$watchedDir->getId()] = $watchedDir->getDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->view->dirs = $result;
|
$this->view->dirs = $result;
|
||||||
|
|
|
@ -819,14 +819,15 @@ class StoredFile {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function listAllFiles(){
|
public static function listAllFiles($dir_id){
|
||||||
global $CC_CONFIG, $CC_DBC;
|
global $CC_CONFIG, $CC_DBC;
|
||||||
|
|
||||||
$sql = "SELECT m.directory || '/' || f.filepath as fp"
|
$sql = "SELECT m.directory || '/' || f.filepath as fp"
|
||||||
." FROM CC_MUSIC_DIRS m"
|
." FROM CC_MUSIC_DIRS m"
|
||||||
." LEFT JOIN CC_FILES f"
|
." LEFT JOIN CC_FILES f"
|
||||||
." ON m.id = f.directory"
|
." ON m.id = f.directory"
|
||||||
." WHERE m.id = f.directory";
|
." WHERE m.id = f.directory"
|
||||||
|
." AND directory = $dir_id";
|
||||||
$rows = $CC_DBC->getAll($sql);
|
$rows = $CC_DBC->getAll($sql);
|
||||||
|
|
||||||
$results = array();
|
$results = array();
|
||||||
|
|
|
@ -105,7 +105,7 @@ class ApiClientInterface:
|
||||||
def update_media_metadata(self, md):
|
def update_media_metadata(self, md):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def list_all_db_files(self):
|
def list_all_db_files(self, dir_id):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def list_all_watched_dirs(self):
|
def list_all_watched_dirs(self):
|
||||||
|
@ -409,12 +409,13 @@ class AirTimeApiClient(ApiClientInterface):
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def list_all_db_files(self):
|
def list_all_db_files(self, dir_id):
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
try:
|
try:
|
||||||
url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["list_all_db_files"])
|
url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["list_all_db_files"])
|
||||||
|
|
||||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
url = url.replace("%%api_key%%", self.config["api_key"])
|
||||||
|
url = url.replace("%%dir_id%%", dir_id)
|
||||||
|
|
||||||
req = urllib2.Request(url)
|
req = urllib2.Request(url)
|
||||||
response = urllib2.urlopen(req).read()
|
response = urllib2.urlopen(req).read()
|
||||||
|
|
|
@ -26,17 +26,17 @@ class AirtimeMediaMonitorBootstrap():
|
||||||
|
|
||||||
self.logger.info("watched directories found: %s", directories)
|
self.logger.info("watched directories found: %s", directories)
|
||||||
|
|
||||||
for dir in directories:
|
for id, dir in directories:
|
||||||
self.check_for_diff(dir)
|
self.check_for_diff(id, dir)
|
||||||
|
|
||||||
def list_db_files(self):
|
def list_db_files(self, dir_id):
|
||||||
return self.api_client.list_all_db_files()
|
return self.api_client.list_all_db_files(dir_id)
|
||||||
|
|
||||||
def get_list_of_watched_dirs(self):
|
def get_list_of_watched_dirs(self):
|
||||||
json = self.api_client.list_all_watched_dirs()
|
json = self.api_client.list_all_watched_dirs()
|
||||||
return json["dirs"]
|
return json["dirs"]
|
||||||
|
|
||||||
def check_for_diff(self, dir):
|
def check_for_diff(self, dir_id, dir):
|
||||||
#set to hold new and/or modified files. We use a set to make it ok if files are added
|
#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
|
#twice. This is become some of the tests for new files return result sets that are not
|
||||||
#mutually exclusive from each other.
|
#mutually exclusive from each other.
|
||||||
|
@ -45,7 +45,7 @@ class AirtimeMediaMonitorBootstrap():
|
||||||
|
|
||||||
|
|
||||||
db_known_files_set = set()
|
db_known_files_set = set()
|
||||||
files = self.list_db_files()
|
files = self.list_db_files(dir_id)
|
||||||
for file in files['files']:
|
for file in files['files']:
|
||||||
db_known_files_set.add(file)
|
db_known_files_set.add(file)
|
||||||
|
|
||||||
|
|
|
@ -64,11 +64,14 @@ class AirtimeNotifier(Notifier):
|
||||||
self.md_manager.save_md_to_file(m)
|
self.md_manager.save_md_to_file(m)
|
||||||
|
|
||||||
elif m['event_type'] == "new_watch":
|
elif m['event_type'] == "new_watch":
|
||||||
self.logger.info("AIRTIME NOTIFIER add watched folder event " + m['directory'])
|
|
||||||
self.walk_newly_watched_directory(m['directory'])
|
|
||||||
|
|
||||||
mm = self.proc_fun()
|
mm = self.proc_fun()
|
||||||
mm.watch_directory(m['directory'])
|
if mm.has_correct_permissions(m['directory']):
|
||||||
|
self.logger.info("AIRTIME NOTIFIER add watched folder event " + m['directory'])
|
||||||
|
self.walk_newly_watched_directory(m['directory'])
|
||||||
|
|
||||||
|
mm.watch_directory(m['directory'])
|
||||||
|
else:
|
||||||
|
self.logger.warn("filepath '%s' has does not have sufficient read permissions. Ignoring.", full_filepath)
|
||||||
|
|
||||||
elif m['event_type'] == "remove_watch":
|
elif m['event_type'] == "remove_watch":
|
||||||
watched_directory = m['directory'].encode('utf-8')
|
watched_directory = m['directory'].encode('utf-8')
|
||||||
|
@ -170,7 +173,10 @@ class AirtimeNotifier(Notifier):
|
||||||
full_filepath = path+"/"+filename
|
full_filepath = path+"/"+filename
|
||||||
|
|
||||||
if mm.is_audio_file(full_filepath):
|
if mm.is_audio_file(full_filepath):
|
||||||
self.logger.info("importing %s", full_filepath)
|
if mm.has_correct_permissions(full_filepath):
|
||||||
event = {'filepath': full_filepath, 'mode': self.config.MODE_CREATE, 'is_recorded_show': False}
|
self.logger.info("importing %s", full_filepath)
|
||||||
mm.multi_queue.put(event)
|
event = {'filepath': full_filepath, 'mode': self.config.MODE_CREATE, 'is_recorded_show': False}
|
||||||
|
mm.multi_queue.put(event)
|
||||||
|
else:
|
||||||
|
self.logger.warn("file '%s' has does not have sufficient read permissions. Ignoring.", full_filepath)
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,13 @@ class AirtimeProcessEvent(ProcessEvent):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
#file needs to be readable by all users, and directories
|
||||||
|
#up to this file needs to be readable AND executable by all
|
||||||
|
#users.
|
||||||
|
def has_correct_permissions(self, filepath):
|
||||||
|
st = os.stat(filepath)
|
||||||
|
return bool(st.st_mode & stat.S_IROTH)
|
||||||
|
|
||||||
def set_needed_file_permissions(self, item, is_dir):
|
def set_needed_file_permissions(self, item, is_dir):
|
||||||
|
|
||||||
|
@ -100,7 +107,7 @@ class AirtimeProcessEvent(ProcessEvent):
|
||||||
omask = os.umask(0)
|
omask = os.umask(0)
|
||||||
os.rename(source, dest)
|
os.rename(source, dest)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.logger.error("failed to move file.")
|
self.logger.error("failed to move file. %s", e)
|
||||||
finally:
|
finally:
|
||||||
os.umask(omask)
|
os.umask(omask)
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ update_media_url = 'reload-metadata/format/json/api_key/%%api_key%%/mode/%%mode%
|
||||||
list_all_db_files = 'list-all-files/format/json/api_key/%%api_key%%'
|
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)
|
# 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%%'
|
list_all_watched_dirs = 'list-all-watched-dirs/format/json/api_key/%%api_key%%/dir_id/%%dir_id%%'
|
||||||
|
|
||||||
############################################
|
############################################
|
||||||
# RabbitMQ settings #
|
# RabbitMQ settings #
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue