config: add audio-upload-hooks
Hooks can be used to automate the process of updating database columns when new audio files are uploaded. A hook command reads the path of an audio file and output a list of database columns to be updated with their respective values. Currently, the only supported database tables are calcms_events and calcms_audio_recordings. Some examples are included
This commit is contained in:
@@ -76,6 +76,19 @@ domain ${DOMAIN}
|
||||
theme default
|
||||
</locations>
|
||||
|
||||
# Hooks can be used to automate the process of updating database columns
|
||||
# when new audio files are uploaded.
|
||||
# A hook command
|
||||
# reads the path of an audio file and
|
||||
# output a list of database columns to be updated with their respective values.
|
||||
# Currently, the only supported database tables are calcms_events and calcms_audio_recordings.
|
||||
|
||||
<audio-upload-hooks>
|
||||
command1 ${BASE_DIR}/../tools/audio-upload-hooks/set-size.sh
|
||||
command2 ${BASE_DIR}/../tools/audio-upload-hooks/set-loudness-duration.pl
|
||||
# command3 ${BASE_DIR}/../tools/audio-upload-hooks/set-podcast-url.sh
|
||||
</audio-upload-hooks>
|
||||
|
||||
<permissions>
|
||||
result_limit 500
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ use studios();
|
||||
use series();
|
||||
use template();
|
||||
use audio_recordings();
|
||||
use series_events();
|
||||
use events();
|
||||
use audio();
|
||||
use time();
|
||||
@@ -434,14 +435,54 @@ sub updateDatabase {
|
||||
$entry->{rmsRight} = 0.0;
|
||||
$entry->{audioDuration} = 0.0;
|
||||
$entry->{modified_at} = time();
|
||||
$params->{id} = audio_recordings::insert( $config, $dbh, $entry );
|
||||
$entry->{id} = audio_recordings::insert( $config, $dbh, $entry );
|
||||
$params->{id} = $entry->{id};
|
||||
}
|
||||
call_hooks($config, $entry, $params);
|
||||
$config->{access}->{write} = 0;
|
||||
$params->{action_result} = 'done!';
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
sub call_hooks {
|
||||
my ($config, $entry, $params) = @_;
|
||||
print STDERR Dumper($config->{"audio-upload-hooks"});
|
||||
my $dbh = db::connect($config);
|
||||
|
||||
$entry = audio_recordings::get(
|
||||
$config, {
|
||||
project_id => $entry->{project_id},
|
||||
studio_id => $entry->{studio_id},
|
||||
event_id => $entry->{event_id},
|
||||
path => $entry->{path}
|
||||
}
|
||||
)->[0] or die;
|
||||
|
||||
for my $cmd (sort values %{$config->{"audio-upload-hooks"}}) {
|
||||
my $audio_file = $config->{locations}->{local_audio_recordings_dir}.'/'.$entry->{path};
|
||||
open(my $fh, '-|', $cmd, $audio_file) or die "Failed to execute hook: $!";
|
||||
while (defined (my $line = (<$fh>))) {
|
||||
if ($line =~ m/^calcms_audio_recordings\.([a-zA-Z0-9_-]+)\s*=\s*(\S+)/) {
|
||||
my ($key, $value) = ($1, $2);
|
||||
$entry->{$key} = $value;
|
||||
die "invalid column $key for table calcms_audio_recordings"
|
||||
unless exists audio_recordings::get_columns($config)->{$key};
|
||||
audio_recordings::update( $config, $dbh, $entry );
|
||||
} elsif ($line =~ m/^calcms_events\.([a-zA-Z0-9_-]+)\s*=\s*(\S+)/) {
|
||||
my ($key, $value) = ($1, $2);
|
||||
die "invalid column $key for calcms_events\n"
|
||||
unless exists {map {$_=>1} series_events::get_content_columns($config)}->{$key};
|
||||
series_events::save_content($config, {
|
||||
id => $entry->{event_id},
|
||||
$key => $value
|
||||
});
|
||||
}
|
||||
}
|
||||
close $fh or die $!;
|
||||
}
|
||||
}
|
||||
|
||||
# return filename, filehandle and optionally error from upload
|
||||
sub getFilename {
|
||||
my $cgi = shift;
|
||||
|
||||
Reference in New Issue
Block a user