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:
@@ -22,15 +22,18 @@ use images();
|
|||||||
|
|
||||||
# check permissions, insert and update events related to series
|
# check permissions, insert and update events related to series
|
||||||
|
|
||||||
#use base 'Exporter';
|
sub get_content_columns($) {
|
||||||
our @EXPORT_OK = qw(
|
my ($config) = @_;
|
||||||
check_permission
|
return (
|
||||||
save_content
|
'series_name', 'title', 'excerpt', 'content',
|
||||||
save_event_time
|
'html_content', 'user_title', 'user_excerpt', 'topic',
|
||||||
insert_event
|
'html_topic', 'episode', 'image', 'image_label',
|
||||||
delete_event
|
'series_image', 'series_image_label', 'podcast_url', 'archive_url',
|
||||||
set_playout_status
|
'live', 'published', 'playout', 'archived',
|
||||||
);
|
'rerun', 'draft', 'disable_event_sync', 'modified_by',
|
||||||
|
'content_format'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
# update main fields of the event by id
|
# update main fields of the event by id
|
||||||
# do not check for project,studio,series
|
# do not check for project,studio,series
|
||||||
@@ -65,16 +68,7 @@ sub save_content($$) {
|
|||||||
|
|
||||||
#TODO: double check series_name (needed for reassignment but not for editing...)
|
#TODO: double check series_name (needed for reassignment but not for editing...)
|
||||||
my @keys = ();
|
my @keys = ();
|
||||||
for my $key (
|
for my $key (get_content_columns($config)) {
|
||||||
'series_name', 'title', 'excerpt', 'content',
|
|
||||||
'html_content', 'user_title', 'user_excerpt', 'topic',
|
|
||||||
'html_topic', 'episode', 'image', 'image_label',
|
|
||||||
'series_image', 'series_image_label', 'podcast_url', 'archive_url',
|
|
||||||
'live', 'published', 'playout', 'archived',
|
|
||||||
'rerun', 'draft', 'disable_event_sync', 'modified_by',
|
|
||||||
'content_format'
|
|
||||||
)
|
|
||||||
{
|
|
||||||
push @keys, $key if defined $entry->{$key};
|
push @keys, $key if defined $entry->{$key};
|
||||||
}
|
}
|
||||||
$entry->{rerun} = 0 unless $entry->{rerun};
|
$entry->{rerun} = 0 unless $entry->{rerun};
|
||||||
|
|||||||
29
tools/audio-upload-hooks/set-loudness-duration.pl
Executable file
29
tools/audio-upload-hooks/set-loudness-duration.pl
Executable file
@@ -0,0 +1,29 @@
|
|||||||
|
#!/usr/bin/perl
|
||||||
|
use warnings;
|
||||||
|
use strict;
|
||||||
|
use Symbol 'gensym';
|
||||||
|
use IPC::Open3 qw(open3);
|
||||||
|
$| = 1;
|
||||||
|
|
||||||
|
# measure duration and rms
|
||||||
|
# requires sox and libsox-fmt-all
|
||||||
|
|
||||||
|
die unless $ARGV[0];
|
||||||
|
my $pid
|
||||||
|
= open3(undef, undef, my $err = gensym(), "sox", $ARGV[0], "-n", "stats");
|
||||||
|
|
||||||
|
while (defined(my $line = <$err>)) {
|
||||||
|
my @fields = split /\s+/, $line;
|
||||||
|
if ($line =~ /^RMS lev dB/) {
|
||||||
|
print "calcms_audio_recordings.rmsLeft = "
|
||||||
|
. int($fields[3] + 0.5) . "\n";
|
||||||
|
print "calcms_audio_recordings.rmsRight = "
|
||||||
|
. int($fields[4] + 0.5) . "\n";
|
||||||
|
} elsif ($line =~ /^Length\ss/) {
|
||||||
|
print "calcms_audio_recordings.audioDuration = "
|
||||||
|
. int($fields[2] + 0.5)
|
||||||
|
. "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
waitpid($pid, 0);
|
||||||
|
die if $?;
|
||||||
3
tools/audio-upload-hooks/set-podcast-url.sh
Executable file
3
tools/audio-upload-hooks/set-podcast-url.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
echo "calcms_events.podcast_url = http://podcasts.org/files/$1"
|
||||||
|
|
||||||
2
tools/audio-upload-hooks/set-size.sh
Executable file
2
tools/audio-upload-hooks/set-size.sh
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
echo "calcms_audio_recordings.size = $(du -b $1 | cut -f1)"
|
||||||
@@ -76,6 +76,19 @@ domain ${DOMAIN}
|
|||||||
theme default
|
theme default
|
||||||
</locations>
|
</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>
|
<permissions>
|
||||||
result_limit 500
|
result_limit 500
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ use studios();
|
|||||||
use series();
|
use series();
|
||||||
use template();
|
use template();
|
||||||
use audio_recordings();
|
use audio_recordings();
|
||||||
|
use series_events();
|
||||||
use events();
|
use events();
|
||||||
use audio();
|
use audio();
|
||||||
use time();
|
use time();
|
||||||
@@ -434,14 +435,54 @@ sub updateDatabase {
|
|||||||
$entry->{rmsRight} = 0.0;
|
$entry->{rmsRight} = 0.0;
|
||||||
$entry->{audioDuration} = 0.0;
|
$entry->{audioDuration} = 0.0;
|
||||||
$entry->{modified_at} = time();
|
$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;
|
$config->{access}->{write} = 0;
|
||||||
$params->{action_result} = 'done!';
|
$params->{action_result} = 'done!';
|
||||||
|
|
||||||
return $params;
|
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
|
# return filename, filehandle and optionally error from upload
|
||||||
sub getFilename {
|
sub getFilename {
|
||||||
my $cgi = shift;
|
my $cgi = shift;
|
||||||
|
|||||||
Reference in New Issue
Block a user