Audio-DB

 view release on metacpan or  search on metacpan

DB/Build.pm  view on Meta::CPAN

  my $tmp = $self->{tmp};
  foreach (@tables) {
    if (-e "$tmp/$_") {
      if ($adaptor =~ /sqlite/) {
	# SQLite does not support infile loads, apparently. Bummer.
      } elsif ($adaptor =~ /mysql/) {
	# $dbh->do("lock tables $_ write; delete from $_; load data infile '$tmp/$_' replace into table $_; unlock tables");
	if (defined $self->{shout}) { print STDERR "loading table $_...\n"; }
	$dbh->do("load data infile '$tmp/$_' replace into table $_") or warn "COULDN'T LOAD TABLE $_";
      } else {};
    }
    unlink "$self->{tmp}/$_";
  }
}


sub get_couldnt_read {
  my $self = shift;
  my @couldnt = @{$self->{couldnt_read}};
  return \@couldnt;
}


sub print_msg {
  my $msg = shift;
  print STDERR $msg;
  print STDERR -t STDOUT && !$ENV{EMACS} ? "\r" : "\n";
}

1;

=pod

=head1 NAME
    
Audio::DB - Tools for generating relational databases of MP3s
    
=head1 SYNOPSIS

      use Audio::DB;
      my $mp3 = Audio::DB->new(-user    =>'user',
			       -pass    =>'password',
			       -host    =>'db_host',
			       -dsn     =>'music_db',
                               -adaptor => 'mysql');

      $mp3->initialize(1);

      $mp3->load_database(-dirs =>['/path/to/MP3s/'],
		          -tmp  =>'/tmp');

=head1 DESCRIPTION

Audio::DB is a module for creating relational databases of MP3 files
directly from data stored in ID3 tags or from flatfiles of information
of track information.  Once created, Audio::DB provides various methods
for creating reports and web pages of your collection. Although it's
nutritious and delicious on its own, Audio::DB was created for use with
Apache::Audio::DB, a subclass of Apache::MP3.  This module makes it easy
to make your collection web-accessible, complete with browsing,
searching, streaming, multiple users, playlists, ratings, and more!

=head1 REQUIRES
    
B<MP3::Info> for reading ID3 tags, B<LWP::MediaTypes> for distinguising 
types of readable files;

=head1 EXPORTS
    
No methods are exported.
    
=head1 CAVEATS

Metrics for assigning songs to albums:
Since Audio::DB processes file-by-file, it uses a number of parameters to assign
tracks to albums.  The quality of the results of Audio::DB will depend directly 
on the quality and integrity of the ID3 tags of your files.

Single tracks (those not belonging to a specific album) are distinguished by 
either undef or the label "single" in the album tag.  In this way, all the single tracks
for a given artist can be easily grouped together and fetched as a sort of 
pseudo-album. Of course, since you've ripped all of your MP3z from albums that you own,
this shouldn't be a problem ;).

If two or more albums have the same name ("Greatest Hits"), Audio::DB checks 
to see if the year they were released and the total number of tracks is the same.  
If so, it thinks they are the same album, and all tracks are grouped together.  
This works most of the time, but obviously will fail sometimes. If you haven't
assigned either of these tags, you'll have one less metric for distinguishing 
tracks.  If you have a better metric for distinguishing tracks, please let me know!

=head1 METHODS

=head2 initialize

 Title   : initialize
 Usage   : $mp3->initialize(-erase=>$erase);
 Function: initialize a new database
 Returns : true if initialization successful
 Args    : a set of named parameters
 Status  : Public

This method can be used to initialize an empty database.  It takes the following
named arguments:

  -erase     A boolean value.  If true the database will be wiped clean if it
             already contains data.

A single true argument ($mp3->initialize(1) is the same as initialize(-erase=>1).
Future versions may support additional options for initialization and database
construction (ie custom schemas).

=head2 load_database

 Title   : load_database
 Usage   :

       Creating a database by reading the tags from MP3 files:
       $stats = $mp3->load_database(-dirs    => ['/path/to/MP3s/'],
                	            -tmp     => '/tmp',
                                    -verbose => 100);



( run in 0.931 second using v1.01-cache-2.11-cpan-39bf76dae61 )