Add --mp3 option to generate MP3 files
This commit is contained in:
parent
bed025d42d
commit
fa2522c41b
@ -29,11 +29,13 @@ my ($help,$config,$verbose,$dryrun);
|
||||
my $meta_data_script = "lav-outils/podcasts/scripts/make-metadata-image-podcast.sh";
|
||||
|
||||
my $verbose;
|
||||
my $textwebpage="<ul>\n\n";
|
||||
my $mp3;
|
||||
my $textwebpage="<ul>\n";
|
||||
|
||||
GetOptions ("help" => \$help,
|
||||
"config=s" => \$config,
|
||||
"verbose" => \$verbose,
|
||||
"mp3" => \$mp3,
|
||||
"verbose" => \$verbose,
|
||||
"dryrun" => \$dryrun);
|
||||
|
||||
if($help) {
|
||||
@ -49,6 +51,7 @@ sub usage {
|
||||
Needs JSON perl library (apt install libjson-perl)
|
||||
$0 --config conf_file.json
|
||||
--config conf_file.json the configuration file containing stuff
|
||||
--mp3 generate mp3 files
|
||||
--help show this message
|
||||
--verbose increase verbosity
|
||||
--dryrun print commands without executing them
|
||||
@ -73,7 +76,7 @@ sub read_config {
|
||||
}
|
||||
|
||||
sub process {
|
||||
my ($config,$verbose,$dryrun)=@_;
|
||||
my ($config,$mp3,$verbose,$dryrun)=@_;
|
||||
my $data = read_config($config);
|
||||
|
||||
my $short_date = $data->{short_date};
|
||||
@ -82,7 +85,20 @@ sub process {
|
||||
my $source_name = "libre-a-vous-$short_date";
|
||||
my $title = "Libre à vous ! du $long_date sur Cause Commune";
|
||||
my $ffmpeg_bin = $data->{ffmpeg_bin};
|
||||
for my $chapter (values @{$data->{chapters}}) {
|
||||
|
||||
my $option_mp3_meta_data_script;
|
||||
my @formats_files;
|
||||
|
||||
if($mp3) {
|
||||
@formats_files = qw/ogg mp3/;
|
||||
$option_mp3_meta_data_script = "yes";
|
||||
}
|
||||
else {
|
||||
@formats_files = qw/ogg/;
|
||||
$option_mp3_meta_data_script = "no";
|
||||
}
|
||||
|
||||
for my $chapter (values @{$data->{chapters}}) {
|
||||
my $start = $chapter->{start_timestamp};
|
||||
my $end = $chapter->{end_timestamp};
|
||||
my $short_chapter_name = $chapter->{short_chapter_name};
|
||||
@ -106,7 +122,7 @@ sub process {
|
||||
|
||||
# putting metadata
|
||||
my $url = "https://media.april.org/audio/radio-cause-commune/libre-a-vous/emissions/$short_date/$source_name-$short_chapter_name.ogg";
|
||||
my $command = "$meta_data_script -s \"$source_name-$short_chapter_name.ogg\" -d \"output\" -u \"$url\" -t \"$title - Partie $chapter_title\" -p \"$ffmpeg_bin\" -y \"$year\"";
|
||||
my $command = "$meta_data_script -s \"$source_name-$short_chapter_name.ogg\" -d \"output\" -u \"$url\" -t \"$title - Partie $chapter_title\" -p \"$ffmpeg_bin\" -y \"$year\" -m \"$option_mp3_meta_data_script\"";
|
||||
|
||||
if($dryrun) {
|
||||
print "$command\n";
|
||||
@ -143,12 +159,12 @@ sub process {
|
||||
$ret[0] =~ s/s/secondes/ig;
|
||||
$ret[0] =~ s/min/minutes/ig;
|
||||
my $url2 = $url =~ s/\.ogg/\.mp3/r;
|
||||
$textwebpage = $textwebpage . "<li><a href=\"$url\">$chapter_title</a> (format OGG) (et <a href=\"$url2\">format MP3</a>) ($ret[0])</li>\n\n";
|
||||
$textwebpage = $textwebpage . "<li><a href=\"$url\">$chapter_title</a> (format OGG) (et <a href=\"$url2\">format MP3</a>) ($ret[0])</li>\n";
|
||||
}
|
||||
}
|
||||
|
||||
# renaming to target OGG and MP3
|
||||
for my $format ("ogg","mp3") {
|
||||
foreach my $format (@formats_files) {
|
||||
my $target_name = "$source_name-$short_chapter_name.$format";
|
||||
my $command = "mv output.$format $target_name";
|
||||
if($dryrun) {
|
||||
@ -186,7 +202,7 @@ sub process {
|
||||
|
||||
# putting metadata in main podcast
|
||||
my $url = "https://media.april.org/audio/radio-cause-commune/libre-a-vous/emissions/$short_date/$source_name.ogg";
|
||||
my $command = "$meta_data_script -s \"$source_name.ogg\" -d \"output\" -u \"$url\" -t \"$title\" -p \"$ffmpeg_bin\" -y \"$year\"";
|
||||
my $command = "$meta_data_script -s \"$source_name.ogg\" -d \"output\" -u \"$url\" -t \"$title\" -p \"$ffmpeg_bin\" -y \"$year\" -m \"$option_mp3_meta_data_script\"";
|
||||
if($dryrun) {
|
||||
print "$command\n";
|
||||
} else {
|
||||
@ -202,7 +218,7 @@ sub process {
|
||||
}
|
||||
|
||||
# renaming to target OGG and MP3
|
||||
for my $format ("ogg","mp3") {
|
||||
foreach my $format (@formats_files) {
|
||||
|
||||
my $command = "mv output.$format $source_name.$format";
|
||||
if($dryrun) {
|
||||
@ -239,8 +255,12 @@ sub process {
|
||||
$textwebpage = $textwebpage . "</ul>\n\n";
|
||||
|
||||
binmode(STDOUT, ":utf8");
|
||||
print "Pour la page web consacrée à l'émission :\n\n$textwebpage\n\n";
|
||||
print "\nText for the web page of the radio program :\n\n$textwebpage\n";
|
||||
|
||||
if(! $mp3) {
|
||||
print "MP3 files not generated, please use --mp3 option to generate them\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
process($config,$verbose,$dryrun);
|
||||
process($config,$mp3,$verbose,$dryrun);
|
||||
|
@ -17,45 +17,50 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
usage() { echo "$0 -s source_file -d destination_file -u http://... -t \"title\" -p path/to/ffmpeg/binary"; exit 0; }
|
||||
[ $# -eq 0 ] && usage
|
||||
while getopts "s:d:u:t:p:y:h" arg; do
|
||||
case $arg in
|
||||
s)
|
||||
source=${OPTARG}
|
||||
;;
|
||||
d)
|
||||
destination=${OPTARG}
|
||||
;;
|
||||
u)
|
||||
url=${OPTARG}
|
||||
;;
|
||||
t)
|
||||
title=${OPTARG}
|
||||
;;
|
||||
p)
|
||||
FFmpegBin=${OPTARG}
|
||||
;;
|
||||
y)
|
||||
year=${OPTARG}
|
||||
;;
|
||||
usage() { echo "$0 -s source_file -d destination_file -u http://... -t \"title\" -p path/to/ffmpeg/binary -y \"year\" -m \"yes or no\""; exit 0; }
|
||||
|
||||
h | *) # Display help.
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
[ $# -eq 0 ] && usage
|
||||
|
||||
while getopts "s:d:u:t:p:y:m:h" arg; do
|
||||
case $arg in
|
||||
s)
|
||||
source=${OPTARG}
|
||||
;;
|
||||
d)
|
||||
destination=${OPTARG}
|
||||
;;
|
||||
u)
|
||||
url=${OPTARG}
|
||||
;;
|
||||
t)
|
||||
title=${OPTARG}
|
||||
;;
|
||||
p)
|
||||
FFmpegBin=${OPTARG}
|
||||
;;
|
||||
y)
|
||||
year=${OPTARG}
|
||||
;;
|
||||
m)
|
||||
mp3=${OPTARG}
|
||||
;;
|
||||
h | *) # Display help.
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ ! -f $source ]; then
|
||||
echo "File $source does not exist"
|
||||
usage
|
||||
exit 1
|
||||
echo "File $source does not exist"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$FFmpegBin" ]; then
|
||||
echo "$FFmpegBin is not executable"
|
||||
usage
|
||||
exit 1
|
||||
echo "$FFmpegBin is not executable"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
image="lav-outils/podcasts/images/image-pour-etiqueter-podcast.jpg"
|
||||
@ -72,27 +77,31 @@ ${FFmpegBin} -y -i ${source} -acodec copy -map 0:0 -map_metadata -1 -metadata ti
|
||||
|
||||
${FFmpegBin} -y -i ${fichiertempogg} -i i.meta -acodec copy -map 0:0 -map_metadata 1 ${destination}.ogg
|
||||
|
||||
# Generation du fichier MP3 avec conservation de l'image de pochette (cover), des métadonnées en deux passes
|
||||
if [ "$mp3" = "yes" ]; then
|
||||
|
||||
# Conservation de l'image de pochette (cover) et des métadonnées
|
||||
# Generation du fichier MP3 avec conservation de l'image de pochette (cover), des métadonnées en deux passes
|
||||
|
||||
${FFmpegBin} -y -i ${destination}.ogg -map_metadata 0:s:0 ${fichiertempmp3}
|
||||
# Conservation de l'image de pochette (cover) et des métadonnées
|
||||
|
||||
# Passe pour avoir le champ Duration dans le fichier (qui n'est pas présent suite à la conversion de OGG en MP3)
|
||||
${FFmpegBin} -y -i ${destination}.ogg -map_metadata 0:s:0 ${fichiertempmp3}
|
||||
|
||||
${FFmpegBin} -y -i ${fichiertempmp3} -acodec copy ${destination}.mp3
|
||||
# Passe pour avoir le champ Duration dans le fichier (qui n'est pas présent suite à la conversion de OGG en MP3)
|
||||
|
||||
# Mise à jour des métadonnées pour tenir compte des métadonnées MP3
|
||||
${FFmpegBin} -y -i ${fichiertempmp3} -acodec copy ${destination}.mp3
|
||||
|
||||
eyeD3 --user-text-frame="LICENSE:" ${destination}.mp3
|
||||
# Mise à jour des métadonnées pour tenir compte des métadonnées MP3
|
||||
|
||||
eyeD3 --user-text-frame="comment:" ${destination}.mp3
|
||||
eyeD3 --user-text-frame="LICENSE:" ${destination}.mp3
|
||||
|
||||
eyeD3 -c "`echo "${text}"|sed '1,$s/.ogg/.mp3/'`" ${destination}.mp3
|
||||
eyeD3 --user-text-frame="comment:" ${destination}.mp3
|
||||
|
||||
eyeD3 --user-text-frame="WOAF:`echo ${url%.ogg}.mp3`" ${destination}.mp3
|
||||
eyeD3 -c "`echo "${text}"|sed '1,$s/.ogg/.mp3/'`" ${destination}.mp3
|
||||
|
||||
eyeD3 --text-frame="TCOP:${year} April - Cause Commune Fichier diffusé selon les termes d’au moins une des licences suivantes : licence Art libre version 1.3 ou ultérieure http://artlibre.org/licence/lal/, licence Creative Commons By Sa version 2.0 ou ultérieure http://creativecommons.org/licenses/by-sa/2.0/fr/ et licence GNU FDL version 1.3 ou ultérieure http://www.gnu.org/licenses/fdl-1.3.html. Pour vérifier voir https://www.april.org/libre-a-vous" ${destination}.mp3
|
||||
eyeD3 --user-text-frame="WOAF:`echo ${url%.ogg}.mp3`" ${destination}.mp3
|
||||
|
||||
eyeD3 --text-frame="TCOP:${year} April - Cause Commune Fichier diffusé selon les termes d’au moins une des licences suivantes : licence Art libre version 1.3 ou ultérieure http://artlibre.org/licence/lal/, licence Creative Commons By Sa version 2.0 ou ultérieure http://creativecommons.org/licenses/by-sa/2.0/fr/ et licence GNU FDL version 1.3 ou ultérieure http://www.gnu.org/licenses/fdl-1.3.html. Pour vérifier voir https://www.april.org/libre-a-vous" ${destination}.mp3
|
||||
|
||||
fi
|
||||
|
||||
rm ${fichiertempogg}
|
||||
rm ${fichiertempmp3}
|
||||
|
Loading…
Reference in New Issue
Block a user