module TagLib.pm
#!/usr/bin/perl
#
#=====================================================================
+==========
#
# FILE: TagLib.pm
#
# DESCRIPTION: Isolate Tablib processing for podcasts .mp3 files
#
#=====================================================================
+==========
use strict;
use warnings;
package TagLib;
use Audio::TagLib;
use Exporter::Easy ( EXPORT => [qw(SetTags)] );
use Switch;
use feature "say";
no warnings "experimental";
sub GetTags {
my $file = shift; # Required
my $key = shift;
$file = $file . ''; # In case we're given an IO::All object
my $id3 = Audio::TagLib::FileRef->new( $file );
switch ( $key ) {
case ( 'artist' ) {
return $id3->tag()->artist()->toCString();
}
case ( 'album' ) {
return $id3->tag()->album()->toCString();
}
case ( 'title' ) {
return $id3->tag()->title()->toCString();
}
case ( 'all' ) {
my %values;
$values{artist} = $id3->tag()->artist()->toCString();
$values{album} = $id3->tag()->album()->toCString();
$values{title} = $id3->tag()->title()->toCString();
return \%values;
}
return undef;
}
}
sub ddump {
my ($file, $what) = @_;
say "Error $file $what";
}
# May be called either with three positional values/Media/USB/usb1/MUS
+IC
# or a hashref with whatever you want changed;
# TagLib::SetTags( $sfile_io, {'title' => "$date $stitle"});
sub SetTags {
my $file = shift; # Required
$file = $file . ''; # In case we're given an IO::All object
my %args;
if ( ref $_[0] eq 'HASH' ) {
while ( my $arg = shift ) {
for my $v ( keys %$arg ) {
$args{$v} = $arg->{$v};
}
}
}
else {
$args{artist} = shift;
$args{album} = shift;
$args{title} = shift;
}
my $id3 = Audio::TagLib::FileRef->new( $file );
# In some cases (haven't been able characterize), straight params
+causes
# loss of some/all of the text in taglib
for my $key ( keys %args ) {
switch ( $key ) {
case ( 'artist' ) {
my $arg = $args{'artist'} . '';
my $t = Audio::TagLib::String->new( $arg );
$id3->tag()->setArtist( $t );
#$id3->tag()->setArtist( Audio::TagLib::String->new( $arg
+) );
}
case ( 'album' ) {
my $arg = $args{'album'} . '';
my $t = Audio::TagLib::String->new( $arg );
$id3->tag()->setAlbum( $t );
#$id3->tag()->setAlbum( Audio::TagLib::String->new( $arg )
+ );
}
case ( 'title' ) {
my $arg = $args{'title'} . '';
my $t = Audio::TagLib::String->new( $arg );
$id3->tag()->setTitle($t);
#$id3->tag()->setTitle( Audio::TagLib::String->new( $arg )
+ );
}
}
}
$id3->tag()->setYear( 0 );
$id3->tag()->setTrack( 1 );
$id3->tag()->setComment( Audio::TagLib::String->new( '') );
$id3->tag()->setGenre( Audio::TagLib::String->new( '' ) );
$id3->save();
return;
}
1;
file t.pl uses TagLib
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
no warnings 'experimental';
use IO::Prompter;
# OK result
require '/home/geoff/Perl/modules/TagLib.pm';
# notOK result
use lib '/home/geoff/Perl/modules';
use TagLib;
my $me = shift;
if ( $me eq 'artist' ) {
my $new = scalar IO::Prompter::prompt -stdio, 'Artist> ';
foreach my $file ( @ARGV ) {
say $file;
TagLib::SetTags($file, {'artist' => $new});
}
}
elsif ( $me eq 'album' ) {
my $new = scalar IO::Prompter::prompt -stdio, 'Album> ';
foreach my $file ( @ARGV ) {
say $file;
TagLib::SetTags($file, {'album' => $new});
}
}
elsif ( $me eq 'title' ) {
foreach my $file ( @ARGV ) {
say $file;
my $new = scalar IO::Prompter::prompt -stdio, 'Title> ';
TagLib::SetTags($file, {'title' => $new});
}
}
else { exit 1; }
exit 0;
output of perl t.pl, OK result. Error is expected
Use of uninitialized value $me in string eq at t.pl line 15.
Use of uninitialized value $me in string eq at t.pl line 22.
Use of uninitialized value $me in string eq at t.pl line 29.
output of perl t.pl, notOK result
syntax error at /home/geoff/Perl/modules/TagLib.pm line 30, near ") {"
Execution of /home/geoff/Perl/modules/TagLib.pm aborted due to compila
+tion errors.
Compilation failed in require at t.pl line 10.
BEGIN failed--compilation aborted at t.pl line 10.
% perl -V
Summary of my perl5 (revision 5 version 38 subversion 3) configuration
+:
Platform:
osname=linux
osvers=6.9.7-100.fc39.x86_64
archname=x86_64-linux-thread-multi
uname='linux df445765349445719d9254c16278a84b 6.9.7-100.fc39.x86_6
+4 #1 smp preempt_dynamic thu jun 27 18:06:32 utc 2024 x86_64 gnulinux
+ '
config_args='-des -Doptimize=none -Dccflags=-O2 -flto=auto -ffat-l
+to-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wno-com
+plain-wrong-lang -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FOR
+TIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/re
+dhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat
+/redhat-annobin-cc1 -m64 -march=x86-64 -mtune=generic -fasynchronous
+-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-fra
+me-pointer -mno-omit-leaf-frame-pointer -Dldflags=-Wl,-z,relro -Wl,--
+as-needed -Wl,-z,pack-relative-relocs -Wl,-z,now -specs=/usr/lib/rpm
+/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-
+cc1 -Wl,--build-id=sha1 -Dccdlflags=-Wl,--enable-new-dtags -Wl,-z,
+relro -Wl,--as-needed -Wl,-z,pack-relative-relocs -Wl,-z,now -specs=
+/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/red
+hat-annobin-cc1 -Wl,--build-id=sha1 -Dlddlflags=-shared -Wl,-z,rel
+ro -Wl,--as-needed -Wl,-z,pack-relative-relocs -Wl,-z,now -specs=/us
+r/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat
+-annobin-cc1 -Wl,--build-id=sha1 -Dshrpdir=/usr/lib64 -DDEBUGGING=
+-g -Dversion=5.38.3 -Dmyhostname=localhost -Dperladmin=root@localhost
+ -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dprefix=/usr -Dman1dir=/usr/share/ma
+n/man1 -Dman3dir=/usr/share/man/man3 -Dvendorprefix=/usr -Dsiteprefix
+=/usr/local -Dsitelib=/usr/local/share/perl5/5.38 -Dsitearch=/usr/loc
+al/lib64/perl5/5.38 -Dprivlib=/usr/share/perl5 -Dvendorlib=/usr/share
+/perl5/vendor_perl -Darchlib=/usr/lib64/perl5 -Dvendorarch=/usr/lib64
+/perl5/vendor_perl -Darchname=x86_64-linux-thread-multi -Dlibpth=/usr
+/local/lib64 /lib64 /usr/lib64 -Duseshrplib -Dusethreads -Duseithread
+s -Dusedtrace=/usr/bin/dtrace -Duselargefiles -Dd_semctl_semun -Di_db
+ -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -D
+installusrbinperl=n -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/le
+ss -isr -Dd_gethostent_r_proto -Ud_endhostent_r_proto -Ud_sethostent_
+r_proto -Ud_endprotoent_r_proto -Ud_setprotoent_r_proto -Ud_endserven
+t_r_proto -Ud_setservent_r_proto -Dscriptdir=/usr/bin -Dusesitecustom
+ize -Duse64bitint'
hint=recommended
useposix=true
d_sigaction=define
useithreads=define
usemultiplicity=define
use64bitint=define
use64bitall=define
uselongdouble=undef
usemymalloc=n
default_inc_excludes_dot=define
Compiler:
cc='gcc'
ccflags ='-D_REENTRANT -D_GNU_SOURCE -O2 -flto=auto -ffat-lto-obje
+cts -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wno-complain-w
+rong-lang -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SO
+URCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-ha
+rdened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat
+-annobin-cc1 -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-
+tables -fstack-clash-protection -fcf-protection -fno-omit-frame-point
+er -mno-omit-leaf-frame-pointer -fwrapv -fno-strict-aliasing -I/usr/l
+ocal/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
optimize=' -g'
cppflags='-D_REENTRANT -D_GNU_SOURCE -O2 -flto=auto -ffat-lto-obje
+cts -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wno-complain-w
+rong-lang -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SO
+URCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-ha
+rdened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat
+-annobin-cc1 -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-
+tables -fstack-clash-protection -fcf-protection -fno-omit-frame-point
+er -mno-omit-leaf-frame-pointer -fwrapv -fno-strict-aliasing -I/usr/l
+ocal/include'
ccversion=''
gccversion='14.2.1 20240912 (Red Hat 14.2.1-3)'
gccosandvers=''
intsize=4
longsize=8
ptrsize=8
doublesize=8
byteorder=12345678
doublekind=3
d_longlong=define
longlongsize=8
d_longdbl=define
longdblsize=16
longdblkind=3
ivtype='long'
ivsize=8
nvtype='double'
nvsize=8
Off_t='off_t'
lseeksize=8
alignbytes=8
prototype=define
Linker and Libraries:
ld='gcc'
ldflags ='-Wl,-z,relro -Wl,--as-needed -Wl,-z,pack-relative-relocs
+ -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr
+/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -fstack-prote
+ctor-strong -L/usr/local/lib'
libpth=/usr/local/lib64 /lib64 /usr/lib64 /usr/local/lib /usr/lib
libs=-lpthread -lresolv -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -l
+gdbm_compat
perllibs=-lpthread -lresolv -ldl -lm -lcrypt -lutil -lc
libc=/lib/../lib64/libc.so.6
so=so
useshrplib=true
libperl=libperl.so
gnulibc_version='2.39'
Dynamic Linking:
dlsrc=dl_dlopen.xs
dlext=so
d_dlsymun=undef
ccdlflags='-Wl,--enable-new-dtags -Wl,-z,relro -Wl,--as-needed -Wl
+,-z,pack-relative-relocs -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat
+-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--buil
+d-id=sha1 '
cccdlflags='-fPIC'
lddlflags='-lpthread -shared -Wl,-z,relro -Wl,--as-needed -Wl,-z,p
+ack-relative-relocs -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hard
+ened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=
+sha1 -L/usr/local/lib -fstack-protector-strong'
Characteristics of this binary (from libperl):
Compile-time options:
HAS_LONG_DOUBLE
HAS_STRTOLD
HAS_TIMES
MULTIPLICITY
PERLIO_LAYERS
PERL_COPY_ON_WRITE
PERL_DONT_CREATE_GVSV
PERL_HASH_FUNC_SIPHASH13
PERL_HASH_USE_SBOX32
PERL_MALLOC_WRAP
PERL_OP_PARENT
PERL_PRESERVE_IVUV
PERL_USE_SAFE_PUTENV
USE_64_BIT_ALL
USE_64_BIT_INT
USE_ITHREADS
USE_LARGE_FILES
USE_LOCALE
USE_LOCALE_COLLATE
USE_LOCALE_CTYPE
USE_LOCALE_NUMERIC
USE_LOCALE_TIME
USE_PERLIO
USE_PERL_ATOF
USE_REENTRANT_API
USE_SITECUSTOMIZE
USE_THREAD_SAFE_LOCALE
Locally applied patches:
Fedora Patch1: Removes date check, Fedora/RHEL specific
Fedora Patch2: support for libdir64
Fedora Patch3: use libresolv instead of libbind
Fedora Patch4: USE_MM_LD_RUN_PATH
Fedora Patch5: Provide MM::maybe_command independently (bug #11294
+43)
Fedora Patch6: Dont run one io test due to random builder failures
Fedora Patch8: Define SONAME for libperl.so
Fedora Patch9: Install libperl.so to -Dshrpdir value
Fedora Patch10: Make *DBM_File desctructors thread-safe (RT#61912)
Fedora Patch11: Replace EU::MakeMaker dependency with EU::MM::Util
+s in IPC::Cmd (bug #1129443)
Fedora Patch12: Link XS modules to pthread library to fix linking
+with -z defs
Fedora Patch13: Pass the correct CFLAGS to dtrace
Fedora Patch200: Link XS modules to libperl.so with EU::CBuilder o
+n Linux
Fedora Patch201: Link XS modules to libperl.so with EU::MM on Linu
+x
Fedora Patch202: Add definition of OPTIMIZE to .ph files
Built under linux
Compiled at Jan 21 2025 00:00:00
@INC:
/usr/local/lib64/perl5/5.38
/usr/local/share/perl5/5.38
/usr/lib64/perl5/vendor_perl
/usr/share/perl5/vendor_perl
/usr/lib64/perl5
/usr/share/perl5