Normalized indent.

This commit is contained in:
Christian P. MOMON 2019-05-25 22:40:17 +02:00
parent a6ee3cff73
commit 0e94130627

View File

@ -32,9 +32,9 @@ my $verbose;
my $textwebpage="<ul>\n\n"; my $textwebpage="<ul>\n\n";
GetOptions ("help" => \$help, GetOptions ("help" => \$help,
"config=s" => \$config, "config=s" => \$config,
"verbose" => \$verbose, "verbose" => \$verbose,
"dryrun" => \$dryrun); "dryrun" => \$dryrun);
if($help) { if($help) {
usage(); usage();
@ -53,7 +53,7 @@ $0 --config conf_file.json
--verbose increase verbosity --verbose increase verbosity
--dryrun print commands without executing them --dryrun print commands without executing them
EOS EOS
; ;
} }
sub read_config { sub read_config {
@ -61,10 +61,10 @@ sub read_config {
my $json_text = do { #read all the file in one shot my $json_text = do { #read all the file in one shot
open(my $json_fh, '<:encoding(UTF-8)', $filename) open(my $json_fh, '<:encoding(UTF-8)', $filename)
or die("Can't open \$filename\": $!\n"); or die("Can't open \$filename\": $!\n");
local $/; local $/;
<$json_fh> <$json_fh>
}; };
my $json = JSON->new; my $json = JSON->new;
my $data = $json->decode($json_text); my $data = $json->decode($json_text);
@ -77,7 +77,7 @@ sub process {
my $data = read_config($config); my $data = read_config($config);
my $short_date = $data->{short_date}; my $short_date = $data->{short_date};
my $year = substr $short_date,0,4; my $year = substr $short_date,0,4;
my $long_date = $data->{long_date}; my $long_date = $data->{long_date};
my $source_name = "libre-a-vous-$short_date"; my $source_name = "libre-a-vous-$short_date";
my $title = "Libre à vous ! du $long_date sur Cause Commune"; my $title = "Libre à vous ! du $long_date sur Cause Commune";
@ -123,69 +123,66 @@ sub process {
} }
} }
# Update string for web site # Update string for web site
my $command = "mediainfo --Inform=\"Audio;%Duration/String%\" output.ogg"; my $command = "mediainfo --Inform=\"Audio;%Duration/String%\" output.ogg";
if($dryrun) {
print "$command\n";
} else {
my @ret = `$command`;
if($?) {
print "Error while updating string for web site\n";
if($verbose) {
print Dumper @ret;
print Dumper $data;
}
return 0;
} else {
chomp($ret[0]);
$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";
}
}
if($dryrun) {
print "$command\n";
} else {
my @ret = `$command`;
if($?) {
print "Error while updating string for web site\n";
if($verbose) {
print Dumper @ret;
print Dumper $data;
}
return 0;
} else {
chomp($ret[0]);
$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";
}
}
# renaming to target OGG and MP3 # renaming to target OGG and MP3
for my $format ("ogg","mp3") { for my $format ("ogg","mp3") {
my $target_name = "$source_name-$short_chapter_name.$format"; my $target_name = "$source_name-$short_chapter_name.$format";
my $command = "mv output.$format $target_name"; my $command = "mv output.$format $target_name";
if($dryrun) { if($dryrun) {
print "$command\n"; print "$command\n";
} else { } else {
my @ret = `$command`; my @ret = `$command`;
if($?) { if($?) {
print "Error while renaming $short_chapter_name.$format\n"; print "Error while renaming $short_chapter_name.$format\n";
if($verbose) { if($verbose) {
print Dumper @ret; print Dumper @ret;
print Dumper $data; print Dumper $data;
} }
return 0; return 0;
} }
} }
# hashing
my $command = "sha1sum $target_name > $target_name.sha1";
if($dryrun) {
print "$command\n";
} else {
my @ret = `$command`;
if($?) {
print "Error while hashing $target_name\n";
if($verbose) {
print Dumper @ret;
print Dumper $data;
}
return 0;
}
}
}
# hashing }
my $command = "sha1sum $target_name > $target_name.sha1";
if($dryrun) {
print "$command\n";
} else {
my @ret = `$command`;
if($?) {
print "Error while hashing $target_name\n";
if($verbose) {
print Dumper @ret;
print Dumper $data;
}
return 0;
}
}
}
}
# putting metadata in main podcast # 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 $url = "https://media.april.org/audio/radio-cause-commune/libre-a-vous/emissions/$short_date/$source_name.ogg";
@ -204,45 +201,45 @@ sub process {
} }
} }
# renaming to target OGG and MP3 # renaming to target OGG and MP3
for my $format ("ogg","mp3") { for my $format ("ogg","mp3") {
my $command = "mv output.$format $source_name.$format"; my $command = "mv output.$format $source_name.$format";
if($dryrun) { if($dryrun) {
print "$command\n"; print "$command\n";
} else { } else {
my @ret = `$command`; my @ret = `$command`;
if($?) { if($?) {
print "Error while renaming $source_name.$format\n"; print "Error while renaming $source_name.$format\n";
if($verbose) { if($verbose) {
print Dumper @ret; print Dumper @ret;
print Dumper $data; print Dumper $data;
} }
return 0; return 0;
} }
} }
# hashing # hashing
my $command = "sha1sum $source_name.$format > $source_name.$format.sha1"; my $command = "sha1sum $source_name.$format > $source_name.$format.sha1";
if($dryrun) { if($dryrun) {
print "$command\n"; print "$command\n";
} else { } else {
my @ret = `$command`; my @ret = `$command`;
if($?) { if($?) {
print "Error while hashing $source_name.$format\n"; print "Error while hashing $source_name.$format\n";
if($verbose) { if($verbose) {
print Dumper @ret; print Dumper @ret;
print Dumper $data; print Dumper $data;
} }
return 0; return 0;
} }
} }
} }
$textwebpage = $textwebpage . "</ul>\n\n"; $textwebpage = $textwebpage . "</ul>\n\n";
binmode(STDOUT, ":utf8"); binmode(STDOUT, ":utf8");
print "Pour la page web consacrée à l'émission :\n\n$textwebpage\n\n"; print "Pour la page web consacrée à l'émission :\n\n$textwebpage\n\n";
} }