Last change
on this file since 39 was
39,
checked in by peter, 13 years ago
|
Add the META.yml metadata file to version control
|
File size:
1.2 KB
|
Rev | Line | |
---|
[1] | 1 | package MP3::Find::Util; |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
| 5 | |
---|
| 6 | use base qw(Exporter); |
---|
| 7 | use vars qw(@EXPORT_OK); |
---|
| 8 | |
---|
[29] | 9 | @EXPORT_OK = qw(build_query get_mp3_metadata); |
---|
[1] | 10 | |
---|
[29] | 11 | use Carp; |
---|
| 12 | use MP3::Info; |
---|
| 13 | |
---|
| 14 | eval { require MP3::Tag }; |
---|
| 15 | my $CAN_USE_ID3V2 = $@ ? 0 : 1; |
---|
| 16 | |
---|
[1] | 17 | sub build_query { |
---|
| 18 | my @args = @_; |
---|
| 19 | |
---|
| 20 | # first find all the directories |
---|
| 21 | my @dirs; |
---|
| 22 | while (local $_ = shift @args) { |
---|
| 23 | if (/^-/) { |
---|
| 24 | # whoops, there's the beginning of the query |
---|
| 25 | unshift @args, $_; |
---|
| 26 | last; |
---|
| 27 | } else { |
---|
| 28 | push @dirs, $_; |
---|
| 29 | } |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | # now build the query hash |
---|
| 33 | my %query; |
---|
| 34 | my $field; |
---|
| 35 | while (local $_ = shift @args) { |
---|
| 36 | if (/^--?(.*)/) { |
---|
| 37 | $field = uc $1; |
---|
| 38 | } else { |
---|
| 39 | $field ? push @{ $query{$field} }, $_ : die "Need a field name before value '$_'\n"; |
---|
| 40 | } |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | return (\@dirs, \%query); |
---|
| 44 | } |
---|
| 45 | |
---|
[29] | 46 | sub get_mp3_metadata { |
---|
| 47 | my $args = shift; |
---|
| 48 | |
---|
| 49 | my $filename = $args->{filename} or croak "get_mp3_metadata needs a 'filename' argument"; |
---|
| 50 | |
---|
| 51 | my $mp3 = { |
---|
| 52 | FILENAME => $filename, |
---|
[39] | 53 | # ID3v2 tags, if present, override ID3v1 tags |
---|
| 54 | %{ get_mp3tag($filename, 0, 2) || {} }, |
---|
| 55 | %{ get_mp3info($filename) || {} }, |
---|
[29] | 56 | }; |
---|
| 57 | |
---|
| 58 | return $mp3; |
---|
| 59 | } |
---|
| 60 | |
---|
[1] | 61 | # module return |
---|
| 62 | 1; |
---|
Note: See
TracBrowser
for help on using the repository browser.