NAME
MP3::Find::DB - SQLite database backend to MP3::Find
SYNOPSIS
use MP3::Find::DB;
my $finder = MP3::Find::DB->new;
my @mp3s = $finder->find_mp3s(
dir => '/home/peter/music',
query => {
artist => 'ilyaimy',
album => 'myxomatosis',
},
ignore_case => 1,
db_file => 'mp3.db',
);
# you can do things besides just searching the database
# create another database
$finder->create_db('my_mp3s.db');
# update the database from the filesystem
$finder->update_db('my_mp3s.db', ['/home/peter/mp3', '/home/peter/cds']);
# and then blow it away
$finder->destroy_db('my_mp3s.db');
REQUIRES
DBI, DBD::SQLite, SQL::Abstract
DESCRIPTION
This is the SQLite database backend for MP3::Find.
Note: I'm still working out some kinks in here, so this backend is currently not as stable as the Filesystem backend.
Special Options
db_file
-
The name of the SQLite database file to use. Defaults to ~/mp3.db.
The database should have at least one table named
mp3
with the following schema:CREATE TABLE mp3 ( mtime INTEGER, FILENAME TEXT, TITLE TEXT, ARTIST TEXT, ALBUM TEXT, YEAR INTEGER, COMMENT TEXT, GENRE TEXT, TRACKNUM INTEGER, VERSION NUMERIC, LAYER INTEGER, STEREO TEXT, VBR TEXT, BITRATE INTEGER, FREQUENCY INTEGER, SIZE INTEGER, OFFSET INTEGER, SECS INTEGER, MM INTEGER, SS INTEGER, MS INTEGER, TIME TEXT, COPYRIGHT TEXT, PADDING INTEGER, MODE INTEGER, FRAMES INTEGER, FRAME_LENGTH INTEGER, VBR_SCALE INTEGER );
METHODS
new
my $finder = MP3::Find::DB->new(
status_callback => \&callback,
);
The status_callback
gets called each time an entry in the database is added, updated, or deleted by the update_db
and sync_db
methods. The arguments passed to the callback are a status code (A, U, or D) and the filename for that entry. The default callback just prints these to STDERR
:
sub default_callback {
my ($status_code, $filename) = @_;
print STDERR "$status_code $filename\n";
}
To suppress any output, set status_callback
to an empty sub:
status_callback => sub {}
create_db
$finder->create_db($db_filename);
Creates a SQLite database in the file named c<$db_filename>.
update_db
my $count = $finder->update_db($db_filename, \@dirs);
Searches for all mp3 files in the directories named by @dirs
using MP3::Find::Filesystem, and adds or updates the ID3 info from those files to the database. If a file already has a record in the database, then it will only be updated if it has been modified sinc ethe last time update_db
was run.
sync_db
my $count = $finder->sync_db($db_filename);
Removes entries from the database that refer to files that no longer exist in the filesystem. Returns the count of how many records were removed.
destroy_db
$finder->destroy_db($db_filename);
Permanantly removes the database.
TODO
Database maintanence routines (e.g. clear out old entries)
Allow the passing of a DSN or an already created $dbh
instead of a SQLite database filename; or write driver classes to handle database dependent tasks (create_db/destroy_db).
SEE ALSO
MP3::Find, MP3::Find::Filesystem, mp3db
AUTHOR
Peter Eichman <peichman@cpan.org>
COPYRIGHT AND LICENSE
Copyright (c) 2006 by Peter Eichman. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.