I am writing an audio playlist generator. However, I want it to output not only name and numeration in a strict row but also duration of an audio file. Is it any way I can do so without such hacks like:
print "#: $number\tDuration: ";
system("mp3info -p \"%m:%s\" \"$track\"");
print "\tNAME: $name";
If it is any important, my perl version is v5.16.3.
Ideally you want to determine the file type based on the file content instead of the extension, File::Type comes in handy for this. MP3::Info and Audio::Flac::Header are well written perl modules.
use File::Type;
use MP3::Info;
use Audio::FLAC::Header;
my $duration = -1;
my $ft = File::Type->new()->checktype_filename($track);
$duration = Audio::FLAC::Header
->new($track)
->tags()
->{trackTotalLengthSeconds}
if($ft eq 'audio/flac');
$duration = MP3::Info
->get_mp3info($track)
->{SECS}
if($ft eq 'audio/mpeg3');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With