CC-1799 Put Airtime Storage into a Human Readable File Naming Convention
about to merge, need to test more with blank metadata/change paths according to spec. Should test case about moving to trash from UI.
This commit is contained in:
parent
ff61972e82
commit
c06b15b964
|
@ -104,6 +104,10 @@ class StoredFile {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
foreach ($p_md as $dbColumn => $mdValue) {
|
foreach ($p_md as $dbColumn => $mdValue) {
|
||||||
|
//don't blank out name, defaults to original filename on first insertion to database.
|
||||||
|
if($p_category == "track_title" && (is_null($p_value) || $p_value == "")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$propelColumn = $this->_dbMD[$dbColumn];
|
$propelColumn = $this->_dbMD[$dbColumn];
|
||||||
$method = "set$propelColumn";
|
$method = "set$propelColumn";
|
||||||
$this->_file->$method($mdValue);
|
$this->_file->$method($mdValue);
|
||||||
|
@ -136,6 +140,10 @@ class StoredFile {
|
||||||
*/
|
*/
|
||||||
public function setDbColMetadataValue($p_category, $p_value)
|
public function setDbColMetadataValue($p_category, $p_value)
|
||||||
{
|
{
|
||||||
|
//don't blank out name, defaults to original filename on first insertion to database.
|
||||||
|
if($p_category == "track_title" && (is_null($p_value) || $p_value == "")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$propelColumn = $this->_dbMD[$p_category];
|
$propelColumn = $this->_dbMD[$p_category];
|
||||||
$method = "set$propelColumn";
|
$method = "set$propelColumn";
|
||||||
$this->_file->$method($p_value);
|
$this->_file->$method($p_value);
|
||||||
|
@ -736,6 +744,7 @@ class StoredFile {
|
||||||
$md['MDATA_KEY_TITLE'] = $fileName;
|
$md['MDATA_KEY_TITLE'] = $fileName;
|
||||||
|
|
||||||
StoredFile::Insert($md);
|
StoredFile::Insert($md);
|
||||||
|
$r = @chmod($audio_file, 0666);
|
||||||
$r = @rename($audio_file, $audio_stor);
|
$r = @rename($audio_file, $audio_stor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,11 +11,11 @@ SCRIPTPATH=`dirname $SCRIPT`
|
||||||
|
|
||||||
echo -e "\n******************************** Install Begin *********************************"
|
echo -e "\n******************************** Install Begin *********************************"
|
||||||
|
|
||||||
php ${SCRIPTPATH}/airtime-install.php $@
|
|
||||||
|
|
||||||
echo -e "\n*** Creating Pypo User ***"
|
echo -e "\n*** Creating Pypo User ***"
|
||||||
python ${SCRIPTPATH}/../python_apps/create-pypo-user.py
|
python ${SCRIPTPATH}/../python_apps/create-pypo-user.py
|
||||||
|
|
||||||
|
php ${SCRIPTPATH}/airtime-install.php $@
|
||||||
|
|
||||||
echo -e "\n*** Pypo Installation ***"
|
echo -e "\n*** Pypo Installation ***"
|
||||||
python ${SCRIPTPATH}/../python_apps/pypo/install/pypo-install.py
|
python ${SCRIPTPATH}/../python_apps/pypo/install/pypo-install.py
|
||||||
|
|
||||||
|
|
|
@ -121,8 +121,6 @@ if ($db_install) {
|
||||||
|
|
||||||
AirtimeInstall::InstallStorageDirectory();
|
AirtimeInstall::InstallStorageDirectory();
|
||||||
|
|
||||||
AirtimeInstall::ChangeDirOwnerToWebserver($CC_CONFIG["storageDir"]);
|
|
||||||
|
|
||||||
AirtimeInstall::CreateSymlinksToUtils();
|
AirtimeInstall::CreateSymlinksToUtils();
|
||||||
|
|
||||||
AirtimeInstall::CreateZendPhpLogFile();
|
AirtimeInstall::CreateZendPhpLogFile();
|
||||||
|
|
|
@ -116,42 +116,39 @@ class AirtimeInstall
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function ChangeDirOwnerToWebserver($filePath)
|
|
||||||
{
|
|
||||||
global $CC_CONFIG;
|
|
||||||
echo "* Giving Apache permission to access $filePath".PHP_EOL;
|
|
||||||
|
|
||||||
$success = chgrp($filePath, $CC_CONFIG["webServerUser"]);
|
|
||||||
$fileperms=@fileperms($filePath);
|
|
||||||
$fileperms = $fileperms | 0x0010; // group write bit
|
|
||||||
$fileperms = $fileperms | 0x0400; // group sticky bit
|
|
||||||
chmod($filePath, $fileperms);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function InstallStorageDirectory()
|
public static function InstallStorageDirectory()
|
||||||
{
|
{
|
||||||
global $CC_CONFIG, $CC_DBC;
|
global $CC_CONFIG, $CC_DBC;
|
||||||
echo "* Storage directory setup".PHP_EOL;
|
echo "* Storage directory setup".PHP_EOL;
|
||||||
|
|
||||||
foreach (array('baseFilesDir', 'storageDir') as $d) {
|
$stor_dir = $CC_CONFIG['storageDir'];
|
||||||
if ( !file_exists($CC_CONFIG[$d]) ) {
|
|
||||||
@mkdir($CC_CONFIG[$d], 02775, true);
|
if (!file_exists($stor_dir)) {
|
||||||
if (file_exists($CC_CONFIG[$d])) {
|
@mkdir($stor_dir, 02777, true);
|
||||||
$rp = realpath($CC_CONFIG[$d]);
|
if (file_exists($stor_dir)) {
|
||||||
echo "* Directory $rp created".PHP_EOL;
|
$rp = realpath($stor_dir);
|
||||||
} else {
|
echo "* Directory $rp created".PHP_EOL;
|
||||||
echo "* Failed creating {$CC_CONFIG[$d]}".PHP_EOL;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
} elseif (is_writable($CC_CONFIG[$d])) {
|
|
||||||
$rp = realpath($CC_CONFIG[$d]);
|
|
||||||
echo "* Skipping directory already exists: $rp".PHP_EOL;
|
|
||||||
} else {
|
} else {
|
||||||
$rp = realpath($CC_CONFIG[$d]);
|
echo "* Failed creating {$stor_dir}".PHP_EOL;
|
||||||
echo "* WARNING: Directory already exists, but is not writable: $rp".PHP_EOL;
|
exit(1);
|
||||||
}
|
}
|
||||||
$CC_CONFIG[$d] = $rp;
|
|
||||||
}
|
}
|
||||||
|
else if (is_writable($stor_dir)) {
|
||||||
|
$rp = realpath($stor_dir);
|
||||||
|
echo "* Skipping directory already exists: $rp".PHP_EOL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$rp = realpath($stor_dir);
|
||||||
|
echo "* WARNING: Directory already exists, but is not writable: $rp".PHP_EOL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "* Giving Apache permission to access $rp".PHP_EOL;
|
||||||
|
$success = chgrp($rp, $CC_CONFIG["webServerUser"]);
|
||||||
|
$success = chown($rp, "pypo");
|
||||||
|
$success = chmod($rp, 02777);
|
||||||
|
$CC_CONFIG['storageDir'] = $rp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function CreateDatabaseUser()
|
public static function CreateDatabaseUser()
|
||||||
|
@ -300,7 +297,7 @@ class AirtimeInstall
|
||||||
echo "* Installing airtime-update-db-settings".PHP_EOL;
|
echo "* Installing airtime-update-db-settings".PHP_EOL;
|
||||||
$dir = AirtimeInstall::CONF_DIR_BINARIES."/utils/airtime-update-db-settings";
|
$dir = AirtimeInstall::CONF_DIR_BINARIES."/utils/airtime-update-db-settings";
|
||||||
exec("ln -s $dir /usr/bin/airtime-update-db-settings");
|
exec("ln -s $dir /usr/bin/airtime-update-db-settings");
|
||||||
|
|
||||||
echo "* Installing airtime-check-system".PHP_EOL;
|
echo "* Installing airtime-check-system".PHP_EOL;
|
||||||
$dir = AirtimeInstall::CONF_DIR_BINARIES."/utils/airtime-check-system";
|
$dir = AirtimeInstall::CONF_DIR_BINARIES."/utils/airtime-check-system";
|
||||||
exec("ln -s $dir /usr/bin/airtime-check-system");
|
exec("ln -s $dir /usr/bin/airtime-check-system");
|
||||||
|
|
|
@ -186,7 +186,7 @@ class MediaMonitor(ProcessEvent):
|
||||||
try:
|
try:
|
||||||
omask = os.umask(0)
|
omask = os.umask(0)
|
||||||
if ((not os.path.exists(directory)) or ((os.path.exists(directory) and not os.path.isdir(directory)))):
|
if ((not os.path.exists(directory)) or ((os.path.exists(directory) and not os.path.isdir(directory)))):
|
||||||
os.makedirs(directory, 02775)
|
os.makedirs(directory, 02777)
|
||||||
self.watch_directory(directory)
|
self.watch_directory(directory)
|
||||||
finally:
|
finally:
|
||||||
os.umask(omask)
|
os.umask(omask)
|
||||||
|
@ -212,38 +212,49 @@ class MediaMonitor(ProcessEvent):
|
||||||
|
|
||||||
global storage_directory
|
global storage_directory
|
||||||
|
|
||||||
original_name = os.path.basename(imported_filepath)
|
try:
|
||||||
file_ext = os.path.splitext(imported_filepath)[1]
|
#get rid of file extention from original name, name might have more than 1 '.' in it.
|
||||||
file_info = mutagen.File(imported_filepath, easy=True)
|
original_name = os.path.basename(imported_filepath)
|
||||||
|
#self.logger.info('original name: %s', original_name)
|
||||||
|
original_name = original_name.split(".")[0:-1]
|
||||||
|
#self.logger.info('original name: %s', original_name)
|
||||||
|
original_name = ''.join(original_name)
|
||||||
|
#self.logger.info('original name: %s', original_name)
|
||||||
|
|
||||||
metadata = {'artist':None,
|
file_ext = os.path.splitext(imported_filepath)[1]
|
||||||
'album':None,
|
file_info = mutagen.File(imported_filepath, easy=True)
|
||||||
'title':None,
|
|
||||||
'tracknumber':None}
|
|
||||||
|
|
||||||
for key in metadata.keys():
|
metadata = {'artist':None,
|
||||||
if key in file_info:
|
'album':None,
|
||||||
metadata[key] = file_info[key][0]
|
'title':None,
|
||||||
|
'tracknumber':None}
|
||||||
|
|
||||||
if metadata['artist'] is not None:
|
for key in metadata.keys():
|
||||||
base = "%s/%s" % (storage_directory, metadata['artist'])
|
if key in file_info:
|
||||||
if metadata['album'] is not None:
|
metadata[key] = file_info[key][0]
|
||||||
base = "%s/%s" % (base, metadata['album'])
|
|
||||||
if metadata['title'] is not None:
|
if metadata['artist'] is not None:
|
||||||
if metadata['tracknumber'] is not None:
|
base = "%s/%s" % (storage_directory, metadata['artist'])
|
||||||
metadata['tracknumber'] = "%02d" % (int(metadata['tracknumber']))
|
if metadata['album'] is not None:
|
||||||
base = "%s/%s - %s" % (base, metadata['tracknumber'], metadata['title'])
|
base = "%s/%s" % (base, metadata['album'])
|
||||||
|
if metadata['title'] is not None:
|
||||||
|
if metadata['tracknumber'] is not None:
|
||||||
|
metadata['tracknumber'] = "%02d" % (int(metadata['tracknumber']))
|
||||||
|
base = "%s/%s - %s" % (base, metadata['tracknumber'], metadata['title'])
|
||||||
|
else:
|
||||||
|
base = "%s/%s" % (base, metadata['title'])
|
||||||
else:
|
else:
|
||||||
base = "%s/%s" % (base, metadata['title'])
|
base = "%s/%s" % (base, original_name)
|
||||||
else:
|
else:
|
||||||
base = "%s/%s" % (base, original_name)
|
base = "%s/%s" % (storage_directory, original_name)
|
||||||
else:
|
|
||||||
base = "%s/%s" % (storage_directory, original_name)
|
|
||||||
|
|
||||||
base = "%s%s" % (base, file_ext)
|
base = "%s%s" % (base, file_ext)
|
||||||
|
|
||||||
filepath = self.create_unique_filename(base)
|
filepath = self.create_unique_filename(base)
|
||||||
self.ensure_dir(filepath)
|
self.ensure_dir(filepath)
|
||||||
|
|
||||||
|
except Exception, e:
|
||||||
|
self.logger.error('Exception: %s', e)
|
||||||
|
|
||||||
return filepath
|
return filepath
|
||||||
|
|
||||||
|
@ -335,7 +346,8 @@ class MediaMonitor(ProcessEvent):
|
||||||
#this file is new, md5 does not exist in Airtime.
|
#this file is new, md5 does not exist in Airtime.
|
||||||
if(response['airtime_status'] == 0):
|
if(response['airtime_status'] == 0):
|
||||||
filepath = self.create_file_path(event.pathname)
|
filepath = self.create_file_path(event.pathname)
|
||||||
self.file_events.append({'old_filepath': event.pathname, 'mode': MODE_CREATE, 'filepath': filepath})
|
os.rename(event.pathname, filepath)
|
||||||
|
self.file_events.append({'mode': MODE_CREATE, 'filepath': filepath})
|
||||||
|
|
||||||
def process_IN_MODIFY(self, event):
|
def process_IN_MODIFY(self, event):
|
||||||
if not event.dir:
|
if not event.dir:
|
||||||
|
@ -364,7 +376,6 @@ class MediaMonitor(ProcessEvent):
|
||||||
del self.moved_files[event.cookie]
|
del self.moved_files[event.cookie]
|
||||||
|
|
||||||
global plupload_directory
|
global plupload_directory
|
||||||
#add a modify event to send md to Airtime for the plupload file.
|
|
||||||
if self.is_parent_directory(old_filepath, plupload_directory):
|
if self.is_parent_directory(old_filepath, plupload_directory):
|
||||||
#file renamed from /tmp/plupload does not have a path in our naming scheme yet.
|
#file renamed from /tmp/plupload does not have a path in our naming scheme yet.
|
||||||
md_filepath = self.create_file_path(event.pathname)
|
md_filepath = self.create_file_path(event.pathname)
|
||||||
|
@ -374,6 +385,13 @@ class MediaMonitor(ProcessEvent):
|
||||||
else:
|
else:
|
||||||
self.file_events.append({'filepath': event.pathname, 'mode': MODE_MOVED})
|
self.file_events.append({'filepath': event.pathname, 'mode': MODE_MOVED})
|
||||||
|
|
||||||
|
else:
|
||||||
|
#TODO need to pass in if md5 exists to this file creation function, identical files will just replace current files not have a (1) etc.
|
||||||
|
#file has been most likely dropped into stor folder from an unwatched location. (from gui, mv command not cp)
|
||||||
|
md_filepath = self.create_file_path(event.pathname)
|
||||||
|
os.rename(event.pathname, md_filepath)
|
||||||
|
self.file_events.append({'mode': MODE_CREATE, 'filepath': md_filepath})
|
||||||
|
|
||||||
def process_IN_DELETE(self, event):
|
def process_IN_DELETE(self, event):
|
||||||
if not event.dir:
|
if not event.dir:
|
||||||
self.logger.info("%s: %s", event.maskname, event.pathname)
|
self.logger.info("%s: %s", event.maskname, event.pathname)
|
||||||
|
@ -386,10 +404,6 @@ class MediaMonitor(ProcessEvent):
|
||||||
|
|
||||||
while len(self.file_events) > 0:
|
while len(self.file_events) > 0:
|
||||||
file_info = self.file_events.popleft()
|
file_info = self.file_events.popleft()
|
||||||
|
|
||||||
if(file_info['mode'] == MODE_CREATE):
|
|
||||||
os.rename(file_info['old_filepath'], file_info['filepath'])
|
|
||||||
|
|
||||||
self.update_airtime(file_info)
|
self.update_airtime(file_info)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue