X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FApp%2FMusicExpo.pm;h=5eb5a6a840d427b16b8efebd2f442e6ca8f50815;hb=3ae7eb15f60751bb36dcf6be01c7c4c997b3ba7c;hp=18ee13c4d248698de27f861c8074342d51138029;hpb=a71c6c1eabd8e0fafdc49c29638de376da6f1b67;p=app-musicexpo.git diff --git a/lib/App/MusicExpo.pm b/lib/App/MusicExpo.pm index 18ee13c..5eb5a6a 100644 --- a/lib/App/MusicExpo.pm +++ b/lib/App/MusicExpo.pm @@ -1,9 +1,9 @@ package App::MusicExpo; -use v5.14; +use 5.014000; use strict; use warnings; -our $VERSION = '0.005'; +our $VERSION = '1.001_000'; use Audio::FLAC::Header qw//; use HTML::Template::Compiled qw//; @@ -29,9 +29,9 @@ our $cache=''; our $template=''; GetOptions ( - "template:s" => \$template, - "prefix:s" => \$prefix, - "cache:s" => \$cache, + 'template:s' => \$template, + 'prefix:s' => \$prefix, + 'cache:s' => \$cache, ); sub flacinfo{ @@ -54,7 +54,7 @@ sub flacinfo{ sub mp3info{ my $file=$_[0]; my %tag = map { encode 'UTF-8', $_ } %{get_mp3tag $file}; - my @trkn = split '/', $tag{TRACKNUM} // ''; + my @trkn = split m#/#s, $tag{TRACKNUM} // ''; freeze +{ format => 'MP3', @@ -75,18 +75,18 @@ sub vorbisinfo{ freeze +{ format => 'Vorbis', - title => $ogg->comment('TITLE'), - artist => $ogg->comment('artist'), - year => $ogg->comment('DATE'), - album => $ogg->comment('ALBUM'), - tracknumber => $ogg->comment('TRACKNUMBER'), - tracktotal => $ogg->comment('TRACKTOTAL'), - genre => $ogg->comment('GENRE'), + title => scalar $ogg->comment('TITLE'), + artist => scalar $ogg->comment('artist'), + year => scalar $ogg->comment('DATE'), + album => scalar $ogg->comment('ALBUM'), + tracknumber => scalar $ogg->comment('TRACKNUMBER'), + tracktotal => scalar $ogg->comment('TRACKTOTAL'), + genre => scalar $ogg->comment('GENRE'), file => scalar fileparse $file, } } -sub mp4_format ($){ +sub mp4_format ($){ ## no critic (ProhibitSubroutinePrototypes) my $encoding = $_[0]; return 'AAC' if $encoding eq 'mp4a'; return 'ALAC' if $encoding eq 'alac'; @@ -111,6 +111,31 @@ 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 %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 + ); + + freeze \%data; +} + my %info = ( '.flac' => \&flacinfo, '.mp3' => \&mp3info, @@ -119,6 +144,7 @@ my %info = ( '.mp4' => \&mp4info, '.aac' => \&mp4info, '.m4a' => \&mp4info, + '.opus' => \&opusinfo, ); sub normalizer{ @@ -128,9 +154,8 @@ sub normalizer{ sub make_fragment{ join '-', map { lc =~ y/a-z0-9/_/csr } @_ } sub run { - my %info = %info; if ($cache) { - tie my %cache, 'DB_File', $cache, O_RDWR|O_CREAT, 0644; + tie my %cache, 'DB_File', $cache, O_RDWR|O_CREAT, 0644; ## no critic (ProhibitTie) $info{$_} = memoize $info{$_}, INSTALL => undef, NORMALIZER => \&normalizer, LIST_CACHE => 'FAULT', SCALAR_CACHE => [HASH => \%cache] for keys %info; } @@ -164,7 +189,7 @@ sub run { @files = sort { $a->{title} cmp $b->{title} } @files; $ht->param(files => \@files, prefix => $prefix); - print $ht->output; + print $ht->output; ## no critic (RequireCheckedSyscalls) } $default_template = <<'HTML'; @@ -238,7 +263,7 @@ Marius Gavrilescu, Emarius@ieval.roE =head1 COPYRIGHT AND LICENSE -Copyright (C) 2013-2015 by Marius Gavrilescu +Copyright (C) 2013-2016 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,