AnyData
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/AnyData/Format/Mp3.pm view on Meta::CPAN
=cut
use strict;
use warnings;
use AnyData::Format::Base;
use AnyData::Storage::FileSys;
use AnyData::Storage::File;
use vars qw( @ISA $VERSION);
@AnyData::Format::Mp3::ISA = qw( AnyData::Format::Base );
$VERSION = '0.12';
sub new {
my $class = shift;
my $self = shift || {};
#use Data::Dumper; die Dumper $self;
my $dirs = $self->{dirs} || $self->{file_name} || $self->{recs};
$self->{col_names} = 'song,artist,album,year,genre,filename,filesize';
$self->{recs} =
$self->{records} = get_data( $dirs );
return bless $self, $class;
}
sub storage_type { 'RAM'; }
sub read_fields {
my $self = shift;
my $thing = shift;
return @$thing if ref $thing eq 'ARRAY';
return split ',', $thing;
}
sub write_fields { die "WRITING NOT IMPLEMENTED FOR FORMAT Mp3"; }
sub get_data {
my $dirs = shift;
my $table = [];
my @files = AnyData::Storage::FileSys::get_filename_parts(
{},
part => 'ext',
re => 'mp3',
dirs => $dirs
);
for my $file_info(@files) {
my $file = $file_info->[0];
my $cols = get_mp3_tag($file) || next;
my $filesize = -s $file;
$filesize = sprintf "%1.fmb", $filesize/1000000;
my @row = (@$cols,$file,$filesize);
push @$table, \@row;
# 'file_name,path,ext,fullpath,size,'
# 'name,artist,album,year,comment,genre';
}
return $table;
}
sub get_mp3_tag {
my($file) = shift;
my $adf = AnyData::Storage::File->new;
my(undef,$fh,undef) = $adf->open_local_file($file,'r');
local $/ = '';
$fh->seek(-128,2);
my $str = <$fh> || '';
$fh->close;
return undef if !($str =~ /^TAG/);
#$file = sprintf("%-255s",$file);
#$str =~ s/^TAG(.*)/$file$1/;
$str =~ s/^TAG(.*)/$1/;
my $genre = $str;
$genre =~ s/^.*(.)$/$1/g;
$str =~ s/(.)$//g;
$genre = unpack( 'C', $genre );
my @genres =("Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", "Hip-Hop", "Jazz", "Metal", "New Age", "Oldies", "Other", "Pop", "R&B", "Rap", "Reggae", "Rock", "Techno", "Industrial", "Alternative", "Ska", "Death Metal", "Pranks...
$genre = $genres[$genre] || '';
my @cols = unpack 'A30 A30 A30 A4 A30', $str;
my $comment = pop @cols;
#print $comment;
@cols = map{$_ || ''} @cols;
push @cols, $genre;
return \@cols;
}
1;
view all matches for this distributionview release on metacpan - search on metacpan
( run in 3.899 seconds using v1.00-cache-2.02-grep-82fe00e-cpan-cec75d87357c )