Changeset 28 in mp3-find for trunk/lib/MP3/Find


Ignore:
Timestamp:
04/29/06 20:44:39 (19 years ago)
Author:
peter
Message:
  • check for presence of MP3::Tag when Filesystem.pm is loaded
  • use the "Text" value of hash MP3::Tag::ID3v2 frames for searching
  • check for definedness of MP3::Tag before trying to read tags (keep from dying in the middle of a search)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/MP3/Find/Filesystem.pm

    r25 r28  
    1717my $USE_SORT_KEY = $@ ? 0 : 1; 
    1818 
     19 
     20eval { require MP3::Tag }; 
     21my $CAN_USE_ID3V2 = $@ ? 0 : 1; 
     22 
    1923use_winamp_genres(); 
    2024 
     
    4751    } 
    4852     
     53    if ($$options{use_id3v2} and not $CAN_USE_ID3V2) { 
     54        # they want to use ID3v2, but don't have MP3::Tag 
     55        warn "MP3::Tag is required to search ID3v2 tags\n"; 
     56    } 
     57         
    4958    # run the actual find 
    5059    my @results; 
     
    95104    }; 
    96105     
    97     if ($$options{use_id3v2}) { 
    98         eval { require MP3::Tag }; 
    99         if ($@) { 
    100             # we weren't able to load MP3::Tag! 
    101             warn "MP3::Tag is required to search ID3v2 tags"; 
     106    if ($CAN_USE_ID3V2 and $$options{use_id3v2}) { 
     107        # add ID3v2 tag info, if present 
     108        my $mp3_tags = MP3::Tag->new($filename); 
     109        unless (defined $mp3_tags) { 
     110            warn "Can't get MP3::Tag object for $filename\n"; 
    102111        } else { 
    103             # add ID3v2 tag info, if present 
    104             my $mp3_tags = MP3::Tag->new($filename); 
    105112            $mp3_tags->get_tags; 
    106113            if (my $id3v2 = $mp3_tags->{ID3v2}) { 
     
    108115                    my ($info) = $id3v2->get_frame($frame_id); 
    109116                    if (ref $info eq 'HASH') { 
    110                         #TODO: how should we handle these? 
     117                        # use the "Text" value as the value for this frame, if present 
     118                        $mp3->{$frame_id} = $info->{Text} if exists $info->{Text}; 
    111119                    } else { 
    112120                        $mp3->{$frame_id} = $info; 
Note: See TracChangeset for help on using the changeset viewer.