X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FApp%2FMusicExpo.pm;h=61f9412f97cf231933d75194461aa0c36a02a181;hb=2457a24f2a6dae6ef517f204af18ed6d66c06f62;hp=5eb5a6a840d427b16b8efebd2f442e6ca8f50815;hpb=3ae7eb15f60751bb36dcf6be01c7c4c997b3ba7c;p=app-musicexpo.git diff --git a/lib/App/MusicExpo.pm b/lib/App/MusicExpo.pm index 5eb5a6a..61f9412 100644 --- a/lib/App/MusicExpo.pm +++ b/lib/App/MusicExpo.pm @@ -3,15 +3,12 @@ use 5.014000; use strict; use warnings; -our $VERSION = '1.001_000'; +our $VERSION = '1.003'; -use Audio::FLAC::Header qw//; use HTML::Template::Compiled qw//; use Memoize qw/memoize/; -use MP3::Info qw/get_mp3tag/; -use Ogg::Vorbis::Header::PurePerl; -use MP4::Info qw/get_mp4tag get_mp4info/; +use Carp qw/carp/; use DB_File qw//; use Encode qw/encode/; use File::Basename qw/fileparse/; @@ -53,7 +50,7 @@ sub flacinfo{ sub mp3info{ my $file=$_[0]; - my %tag = map { encode 'UTF-8', $_ } %{get_mp3tag $file}; + my %tag = map { encode 'UTF-8', $_ } %{MP3::Info::get_mp3tag $file}; my @trkn = split m#/#s, $tag{TRACKNUM} // ''; freeze +{ @@ -95,8 +92,8 @@ sub mp4_format ($){ ## no critic (ProhibitSubroutinePrototypes) sub mp4info{ my $file=$_[0]; - my %tag = map { ref() ? $_ : encode 'UTF-8', $_ } %{get_mp4tag $file}; - my %info = %{get_mp4info $file}; + my %tag = map { ref() ? $_ : encode 'UTF-8', $_ } %{MP4::Info::get_mp4tag $file}; + my %info = %{MP4::Info::get_mp4info $file}; freeze +{ format => mp4_format $info{ENCODING}, @@ -113,46 +110,53 @@ sub mp4info{ sub opusinfo { my $file = $_[0]; - my %info; - my @info = `opusinfo \Q$file`; - return unless @info; - for (@info) { - chomp; - $info{$1} = $2 if /\s*([A-Z]+)=(.*)$/; - } + my $of = Audio::Opusfile->new_from_file($file); + my $tags = $of->tags; my %data = ( format => 'Opus', - title => $info{TITLE}, - artist => $info{ARTIST}, - year => $info{DATE}, - album => $info{ALBUM}, - tracknumber => $info{TRACKNUMBER}, - tracktotal => $info{TRACKTOTAL}, - genre => $info{GENRE}, - file => scalar fileparse $file + title => $tags->query('TITLE'), + artist => $tags->query('ARTIST'), + year => $tags->query('DATE'), + album => $tags->query('ALBUM'), + tracknumber => $tags->query('TRACKNUMBER'), + tracktotal => $tags->query('TRACKTOTAL'), + genre => $tags->query('GENRE'), + file => scalar fileparse $file, ); freeze \%data; } -my %info = ( - '.flac' => \&flacinfo, - '.mp3' => \&mp3info, - '.ogg' => \&vorbisinfo, - '.oga' => \&vorbisinfo, - '.mp4' => \&mp4info, - '.aac' => \&mp4info, - '.m4a' => \&mp4info, - '.opus' => \&opusinfo, +my @optional_modules = ( + [ 'Audio::FLAC::Header', \&flacinfo, '.flac' ], + [ 'MP3::Info', \&mp3info, '.mp3' ], + [ 'Ogg::Vorbis::Header::PurePerl', \&vorbisinfo, '.ogg', '.oga' ], + [ 'MP4::Info', \&mp4info, '.mp4', '.aac', '.m4a' ], + [ 'Audio::Opusfile', \&opusinfo, '.opus' ], ); +my %info; + +for (@optional_modules) { + my ($module, $coderef, @extensions_handled) = @$_; + if (eval "require $module") { + $info{$_} = $coderef for @extensions_handled + } +} + +unless (%info) { + carp 'No tags-reading module detected. Install one of the following modules: ' . join ', ', map { $_->[0] } @optional_modules; +} + sub normalizer{ "$_[0]|".(stat $_[0])[9] } sub make_fragment{ join '-', map { lc =~ y/a-z0-9/_/csr } @_ } +sub extensions_handled { keys %info } + sub run { if ($cache) { tie my %cache, 'DB_File', $cache, O_RDWR|O_CREAT, 0644; ## no critic (ProhibitTie) @@ -162,6 +166,7 @@ sub run { my %files; for my $file (@ARGV) { my ($basename, undef, $suffix) = fileparse $file, keys %info; + next unless $suffix; $files{$basename} //= []; push @{$files{$basename}}, thaw scalar $info{$suffix}->($file); } @@ -263,7 +268,7 @@ Marius Gavrilescu, Emarius@ieval.roE =head1 COPYRIGHT AND LICENSE -Copyright (C) 2013-2016 by Marius Gavrilescu +Copyright (C) 2013-2017 by Marius Gavrilescu This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.2 or,