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 {
|
||||
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];
|
||||
$method = "set$propelColumn";
|
||||
$this->_file->$method($mdValue);
|
||||
|
@ -136,6 +140,10 @@ class StoredFile {
|
|||
*/
|
||||
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];
|
||||
$method = "set$propelColumn";
|
||||
$this->_file->$method($p_value);
|
||||
|
@ -736,6 +744,7 @@ class StoredFile {
|
|||
$md['MDATA_KEY_TITLE'] = $fileName;
|
||||
|
||||
StoredFile::Insert($md);
|
||||
$r = @chmod($audio_file, 0666);
|
||||
$r = @rename($audio_file, $audio_stor);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,11 +11,11 @@ SCRIPTPATH=`dirname $SCRIPT`
|
|||
|
||||
echo -e "\n******************************** Install Begin *********************************"
|
||||
|
||||
php ${SCRIPTPATH}/airtime-install.php $@
|
||||
|
||||
echo -e "\n*** Creating Pypo User ***"
|
||||
python ${SCRIPTPATH}/../python_apps/create-pypo-user.py
|
||||
|
||||
php ${SCRIPTPATH}/airtime-install.php $@
|
||||
|
||||
echo -e "\n*** Pypo Installation ***"
|
||||
python ${SCRIPTPATH}/../python_apps/pypo/install/pypo-install.py
|
||||
|
||||
|
|
|
@ -121,8 +121,6 @@ if ($db_install) {
|
|||
|
||||
AirtimeInstall::InstallStorageDirectory();
|
||||
|
||||
AirtimeInstall::ChangeDirOwnerToWebserver($CC_CONFIG["storageDir"]);
|
||||
|
||||
AirtimeInstall::CreateSymlinksToUtils();
|
||||
|
||||
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()
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
echo "* Storage directory setup".PHP_EOL;
|
||||
|
||||
foreach (array('baseFilesDir', 'storageDir') as $d) {
|
||||
if ( !file_exists($CC_CONFIG[$d]) ) {
|
||||
@mkdir($CC_CONFIG[$d], 02775, true);
|
||||
if (file_exists($CC_CONFIG[$d])) {
|
||||
$rp = realpath($CC_CONFIG[$d]);
|
||||
echo "* Directory $rp created".PHP_EOL;
|
||||
} else {
|
||||
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;
|
||||
$stor_dir = $CC_CONFIG['storageDir'];
|
||||
|
||||
if (!file_exists($stor_dir)) {
|
||||
@mkdir($stor_dir, 02777, true);
|
||||
if (file_exists($stor_dir)) {
|
||||
$rp = realpath($stor_dir);
|
||||
echo "* Directory $rp created".PHP_EOL;
|
||||
} else {
|
||||
$rp = realpath($CC_CONFIG[$d]);
|
||||
echo "* WARNING: Directory already exists, but is not writable: $rp".PHP_EOL;
|
||||
echo "* Failed creating {$stor_dir}".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()
|
||||
|
@ -300,7 +297,7 @@ class AirtimeInstall
|
|||
echo "* Installing airtime-update-db-settings".PHP_EOL;
|
||||
$dir = AirtimeInstall::CONF_DIR_BINARIES."/utils/airtime-update-db-settings";
|
||||
exec("ln -s $dir /usr/bin/airtime-update-db-settings");
|
||||
|
||||
|
||||
echo "* Installing airtime-check-system".PHP_EOL;
|
||||
$dir = AirtimeInstall::CONF_DIR_BINARIES."/utils/airtime-check-system";
|
||||
exec("ln -s $dir /usr/bin/airtime-check-system");
|
||||
|
|
|
@ -186,7 +186,7 @@ class MediaMonitor(ProcessEvent):
|
|||
try:
|
||||
omask = os.umask(0)
|
||||
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)
|
||||
finally:
|
||||
os.umask(omask)
|
||||
|
@ -212,38 +212,49 @@ class MediaMonitor(ProcessEvent):
|
|||
|
||||
global storage_directory
|
||||
|
||||
original_name = os.path.basename(imported_filepath)
|
||||
file_ext = os.path.splitext(imported_filepath)[1]
|
||||
file_info = mutagen.File(imported_filepath, easy=True)
|
||||
try:
|
||||
#get rid of file extention from original name, name might have more than 1 '.' in it.
|
||||
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,
|
||||
'album':None,
|
||||
'title':None,
|
||||
'tracknumber':None}
|
||||
file_ext = os.path.splitext(imported_filepath)[1]
|
||||
file_info = mutagen.File(imported_filepath, easy=True)
|
||||
|
||||
for key in metadata.keys():
|
||||
if key in file_info:
|
||||
metadata[key] = file_info[key][0]
|
||||
metadata = {'artist':None,
|
||||
'album':None,
|
||||
'title':None,
|
||||
'tracknumber':None}
|
||||
|
||||
if metadata['artist'] is not None:
|
||||
base = "%s/%s" % (storage_directory, metadata['artist'])
|
||||
if metadata['album'] is not None:
|
||||
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'])
|
||||
for key in metadata.keys():
|
||||
if key in file_info:
|
||||
metadata[key] = file_info[key][0]
|
||||
|
||||
if metadata['artist'] is not None:
|
||||
base = "%s/%s" % (storage_directory, metadata['artist'])
|
||||
if metadata['album'] is not None:
|
||||
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:
|
||||
base = "%s/%s" % (base, metadata['title'])
|
||||
base = "%s/%s" % (base, original_name)
|
||||
else:
|
||||
base = "%s/%s" % (base, original_name)
|
||||
else:
|
||||
base = "%s/%s" % (storage_directory, original_name)
|
||||
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)
|
||||
self.ensure_dir(filepath)
|
||||
filepath = self.create_unique_filename(base)
|
||||
self.ensure_dir(filepath)
|
||||
|
||||
except Exception, e:
|
||||
self.logger.error('Exception: %s', e)
|
||||
|
||||
return filepath
|
||||
|
||||
|
@ -335,7 +346,8 @@ class MediaMonitor(ProcessEvent):
|
|||
#this file is new, md5 does not exist in Airtime.
|
||||
if(response['airtime_status'] == 0):
|
||||
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):
|
||||
if not event.dir:
|
||||
|
@ -364,7 +376,6 @@ class MediaMonitor(ProcessEvent):
|
|||
del self.moved_files[event.cookie]
|
||||
|
||||
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):
|
||||
#file renamed from /tmp/plupload does not have a path in our naming scheme yet.
|
||||
md_filepath = self.create_file_path(event.pathname)
|
||||
|
@ -374,6 +385,13 @@ class MediaMonitor(ProcessEvent):
|
|||
else:
|
||||
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):
|
||||
if not event.dir:
|
||||
self.logger.info("%s: %s", event.maskname, event.pathname)
|
||||
|
@ -386,10 +404,6 @@ class MediaMonitor(ProcessEvent):
|
|||
|
||||
while len(self.file_events) > 0:
|
||||
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)
|
||||
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue