has $opt :reader;
has $db;
has $db_generation;
- has $mpd;
+ has $mpd :reader;
use constant DEFAULT_CONFIG_FILE => '/etc/mpd-feeder/mpd-feeder.conf';
+use DBD::Pg;
+use DBI;
+use Net::Async::MPD;
ADJUST {
$opt = Options->new;
$opt->parse_command_line;
unless ($opt->dump_config) {
- $mpd = Net::Async::MPD->new(
- host => $opt->mpd_host,
- port => $opt->mpd_port,
- auto_connect => 1,
- );
+ my %conn = ( auto_connect => 1 );
+ $conn{host} = $opt->mpd_host if $opt->mpd_host;
+ $conn{port} = $opt->mpd_port if $opt->mpd_port;
+
+ $mpd = Net::Async::MPD->new(%conn);
$self->connect_db;
$self->update_db unless $self->opt->skip_db_update;
$mpd->send('listallinfo')->on_done(
sub {
try {
- $db->begin;
+ my $rows = shift;
+ $db->begin_work;
$db_generation++;
- my ($song, $artist, $album);
-
- foreach my $row (@_) {
- chomp($row);
-
- if ($row =~ s/^file:\s*//) {
- $self->db_store_song( $song, $artist, $album );
- $song = $row;
- $artist = $album = undef;
- }
- elsif ( $row =~ s/^Artist:\s*// ) {
- $artist = $row;
- }
- elsif ( $row =~ s/^Album:\s*// ) {
- $album = $row;
- }
+ my $song_count;
+
+ foreach my $entry (@$rows) {
+ next unless exists $entry->{file};
+ $self->db_store_song( $entry->{file},
+ $entry->{Artist}, $entry->{Album} );
+ $song_count++;
}
$self->db_store_song($song, $artist, $album);