has $opt :reader;
has $db;
has $db_generation;
+ has $db_needs_update = 1;
has $mpd :reader;
use constant DEFAULT_CONFIG_FILE => '/etc/mpd-feeder/mpd-feeder.conf';
$opt->parse_command_line;
+ $db_needs_update = 0 if $opt->skip_db_update;
+
Log::Any::Adapter->set( Stderr => log_level => $opt->log_level );
}
$log->info( "Connected to database " . $opt->db_path );
$db_generation = $self->db_get_option('generation');
$log->debug("DB generation is $db_generation");
- $self->update_db unless $opt->skip_db_update;
+ $self->update_db;
}
method db_get_option($name) {
)->execute( $item->{artist}, $item->{album} );
}
- method update_db() {
+ method update_db($force = undef) {
+ if (!$db_needs_update and !$force) {
+ $log->debug("Skipping DB update");
+ return;
+ }
+
$log->info('Updating song database');
+ $self->connect_mpd;
+ $self->connect_db;
+
$mpd->send('listallinfo')->on_done(
sub {
try {
}
method queue_songs($num = undef, $callback = undef) {
- $self->connect_mpd;
if (!defined $num) {
+ $self->connect_mpd;
$mpd->send('playlist')->on_done(
sub {
my $present = scalar @{ $_[0] };
for (@paths) {
push @commands, [ add => "\"$_\"" ];
}
+ $self->connect_mpd;
my $f = $mpd->send( \@commands );
warn "here";
$f->on_fail( sub { die @_ } );
use JSON; warn to_json($result);
if ( $result->{changed} eq 'database' ) {
- $self->update_db;
+ $self->update_db(1);
$self->prepare_to_wait_idle;
}
elsif ( $result->{changed} eq 'playlist' ) {