Changeset 19 in mp3-find


Ignore:
Timestamp:
03/28/06 19:38:39 (19 years ago)
Author:
peter
Message:
  • added "status_callback" option to the constructor for MP3::Find::DB
  • default status callback just prints the status code and the file name to STDERR as before
  • using an empty status_callback in t/03-db.t (status_callback => sub {}) to keep the test output more legible
  • updated docs in Find.pm
  • mkreadme now prints a blank line between the file header and the DESCRIPION section
  • generated new README file
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/README

    r1 r19  
    1 MP3::Find version 0.01 
     1MP3::Find version 0.04 
    22====================== 
     3 
    34DESCRIPTION 
    45    This module allows you to search for MP3 files by their ID3 tags. You 
     
    78    formatted string for each file using its ID3 tags, or the actual Perl 
    89    data structure representing the results. 
     10 
     11    There are currently two backends to this module: MP3::Find::Filesystem 
     12    and MP3::Find::DB. You choose which one you want by passing its name as 
     13    the argument to you "use" statement; MP3::Find will look for a 
     14    MP3::Find::$BACKEND module. If no backend name is given, it will default 
     15    to using MP3::Find::Filesystem. 
     16 
     17    Note: I'm still working out some kinks in the DB backend, so it is 
     18    currently not as stable as the Filesystem backend. 
     19 
     20    Note the second: This whole project is still in the alpha stage, so I 
     21    can make no guarentees that there won't be significant interface changes 
     22    in the next few versions or so. Also, comments about what about the API 
     23    rocks (or sucks!) are appreciated. 
    924 
    1025INSTALL 
     
    1732 
    1833SYNOPSIS 
    19         use MP3Find; 
     34        # select with backend you want 
     35        use MP3::Find qw(Filesystem); 
    2036     
    2137        print "$_\n" foreach find_mp3s( 
     
    2642            }, 
    2743            ignore_case => 1, 
    28             match_words => 1, 
     44            exact_match => 1, 
    2945            sort => [qw(year album tracknum)], 
    3046            printf => '%2n. %a - %t (%b: %y)', 
     
    3248 
    3349REQUIRES 
    34     File::Find, MP3::Info, Scalar::Util 
     50    File::Find, MP3::Info, and Scalar::Util are needed for the filesystem 
     51    backend (MP3::Find::Filesystem). In addition, if MP3::Tag is available, 
     52    you can search by explicit ID3v2 tag frames. 
    3553 
    36     DBI and DBD::SQLite are needed if you want to have a database backend. 
     54    DBI, DBD::SQLite, and SQL::Abstract are needed for the database backend 
     55    (MP3::Find::DB). 
    3756 
    3857COPYRIGHT AND LICENSE 
  • trunk/lib/MP3/Find.pm

    r18 r19  
    4747        }, 
    4848        ignore_case => 1, 
    49         match_words => 1, 
     49        exact_match => 1, 
    5050        sort => [qw(year album tracknum)], 
    5151        printf => '%2n. %a - %t (%b: %y)', 
     
    7777 
    7878L<File::Find>, L<MP3::Info>, and L<Scalar::Util> are needed for 
    79 the filesystem backend (L<MP3::Find::Filesystem>). 
     79the filesystem backend (L<MP3::Find::Filesystem>). In addition, 
     80if L<MP3::Tag> is available, you can search by explicit ID3v2 
     81tag frames. 
    8082 
    8183L<DBI>, L<DBD::SQLite>, and L<SQL::Abstract> are needed for the 
     
    184186currently only uses the filesystem backend). 
    185187 
     188L<mp3db> is a (currently rather barebones) command line  
     189frontend for creating and updating a SQLite database for  
     190use with L<MP3::Find::DB>. 
     191 
    186192See L<MP3::Info> for more information about the fields you can 
    187 search and sort on. 
     193search and sort on. See L<http://id3.org/> for information about 
     194ID3v2 tags. 
    188195 
    189196L<File::Find::Rule::MP3Info> is another way to search for MP3 
  • trunk/lib/MP3/Find/DB.pm

    r13 r19  
    4343); 
    4444 
     45my $DEFAULT_STATUS_CALLBACK = sub { 
     46    my ($action_code, $filename) = @_; 
     47    print STDERR "$action_code $filename\n"; 
     48}; 
    4549 
    4650sub search { 
     
    8993sub update_db { 
    9094    my $self = shift; 
    91     my $db_file = shift or croak "Need the name of the databse to update"; 
     95    my $db_file = shift or croak "Need the name of the database to update"; 
    9296    my $dirs = shift; 
     97     
     98    my $status_callback = $self->{status_callback} || $DEFAULT_STATUS_CALLBACK; 
    9399     
    94100    my @dirs = ref $dirs eq 'ARRAY' ? @$dirs : ($dirs); 
     
    126132        if (@$records == 0) { 
    127133            $insert_sth->execute(map { $mp3->{$$_[0]} } @COLUMNS); 
    128             print STDERR "A $$mp3{FILENAME}\n"; 
     134            $status_callback->(A => $$mp3{FILENAME}); 
    129135            $count++; 
    130136        } elsif ($mp3->{mtime} > $$records[0][0]) { 
    131137            # the mp3 file is newer than its record 
    132138            $update_sth->execute((map { $mp3->{$$_[0]} } @COLUMNS), $mp3->{FILENAME}); 
    133             print STDERR "U $$mp3{FILENAME}\n"; 
     139            $status_callback->(U => $$mp3{FILENAME}); 
    134140            $count++; 
    135141        } 
     
    140146    foreach ($mtime_sth, $insert_sth, $update_sth) { 
    141147        $_->{RaiseError} = 0;  # don't die on error 
     148        $_->{PrintError} = 0;  # ...and don't even say anything 
    142149        $_->{Active} = 1; 
    143150        $_->finish; 
     
    150157    my $self = shift; 
    151158    my $db_file = shift or croak "Need the name of the databse to sync"; 
    152      
     159 
     160    my $status_callback = $self->{status_callback} || $DEFAULT_STATUS_CALLBACK; 
     161 
    153162    my $dbh = DBI->connect("dbi:SQLite:dbname=$db_file", '', '', {RaiseError => 1}); 
    154163    my $select_sth = $dbh->prepare('SELECT FILENAME FROM mp3'); 
     
    162171        unless (-e $filename) { 
    163172            $delete_sth->execute($filename); 
    164             print STDERR "D $filename\n"; 
     173            $status_callback->(D => $filename); 
    165174            $count++; 
    166175        } 
  • trunk/mkreadme

    r1 r19  
    11#!/bin/sh 
    2 perl -I./lib -M$1 -e"\$ver = '$1 version ' . $1->VERSION; print qq[\$ver\\n] . '=' x length(\$ver) . qq[\\n]" 
     2perl -I./lib -M$1 -e"\$ver = '$1 version ' . $1->VERSION; print qq[\$ver\\n] . '=' x length(\$ver) . qq[\\n\\n]" 
    33 
    44PM_FILE=./lib/`echo $1 | sed 's/::/\//g'`.pm 
  • trunk/t/03-db.t

    r12 r19  
    2323# exercise the object 
    2424 
    25 my $finder = MP3::Find::DB->new; 
     25my $finder = MP3::Find::DB->new( 
     26    status_callback => sub {},  # be quiet about updates 
     27); 
    2628isa_ok($finder, 'MP3::Find::DB'); 
    2729 
Note: See TracChangeset for help on using the changeset viewer.