+sub mp4_format ($){ ## no critic (ProhibitSubroutinePrototypes)
+ my $encoding = $_[0];
+ return 'AAC' if $encoding eq 'mp4a';
+ return 'ALAC' if $encoding eq 'alac';
+ "MP4-$encoding"
+}
+
+sub mp4info{
+ my $file=$_[0];
+ my %tag = map { ref() ? $_ : encode 'UTF-8', $_ } %{get_mp4tag $file};
+ my %info = %{get_mp4info $file};
+
+ freeze +{
+ format => mp4_format $info{ENCODING},
+ title => $tag{TITLE},
+ artist => $tag{ARTIST},
+ year => $tag{YEAR},
+ album => $tag{ALBUM},
+ tracknumber => $tag{TRACKNUM},
+ tracktotal => ($tag{TRKN} ? $tag{TRKN}->[1] : undef),
+ genre => $tag{GENRE},
+ file => scalar fileparse $file,
+ };
+}
+
+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,
+ '.ogg' => \&vorbisinfo,
+ '.oga' => \&vorbisinfo,
+ '.mp4' => \&mp4info,
+ '.aac' => \&mp4info,
+ '.m4a' => \&mp4info,
+ '.opus' => \&opusinfo,
+);
+