Index: Slim/Plugin/MusicMagic/Plugin.pm =================================================================== --- Slim/Plugin/MusicMagic/Plugin.pm (revision 22316) +++ Slim/Plugin/MusicMagic/Plugin.pm (working copy) @@ -308,32 +308,28 @@ sub isMusicLibraryFileChanged { - my $http = Slim::Player::Protocols::HTTP->new({ - 'url' => "http://$MMSHost:$MMSport/api/cacheid?contents", - 'create' => 0, - 'timeout' => 5, - }) || return 0; + my $http = Slim::Networking::SimpleAsyncHTTP->new( + \&_cacheidOK, + \&_musicipError, + { + timeout => 30, + }, + ); + + $http->get( "http://$MMSHost:$MMSport/api/cacheid?contents" ); +} - my $fileMTime = $http->content; +sub _statusOK { + my $http = shift; + my $params = $http->params('params'); + + my $content = $http->content; + chomp($content); + + $log->debug( "Read status $content" ); + + my $fileMTime = $params->{fileMTime}; - chomp($fileMTime); - - $log->info("Read cacheid of $fileMTime"); - - $http->close; - - $http = Slim::Player::Protocols::HTTP->new({ - 'url' => "http://$MMSHost:$MMSport/api/getStatus", - 'create' => 0, - 'timeout' => 5, - }) || return 0; - - if ( $log->is_info ) { - $log->info("Got status: ", $http->content); - } - - $http->close; - # Only say "yes" if it has been more than one minute since we last finished scanning # and the file mod time has changed since we last scanned. Note that if we are # just starting, $lastMMMChange is undef, so both $fileMTime @@ -364,7 +360,7 @@ if ((time - $lastScanTime) > $scanInterval) { - return 1; + Slim::Control::Request::executeRequest(undef, ['rescan']); } $log->info("Waiting for $scanInterval seconds to pass before rescanning"); @@ -380,9 +376,9 @@ return; } - if (!$firstTime && !Slim::Music::Import->stillScanning && isMusicLibraryFileChanged()) { - - Slim::Control::Request::executeRequest(undef, ['rescan']); + if (!$firstTime && !Slim::Music::Import->stillScanning) { + + isMusicLibraryFileChanged(); } # make sure we aren't doing this more than once... @@ -392,6 +388,38 @@ Slim::Utils::Timers::setTimer(undef, (Time::HiRes::time() + 120), \&checker); } +sub _cacheidOK { + my $http = shift; + my $params = $http->params('params'); + + my $content = $http->content; + chomp($content); + + $log->debug( "Read cacheid of $content" ); + + $params->{fileMTime} = $content; + + #do status check + my $http = Slim::Networking::SimpleAsyncHTTP->new( + \&_statusOK, + \&_musicipError, + { + params => $params, + timeout => 30, + }, + ); + + $http->get( "http://$MMSHost:$MMSport/api/getStatus" ); +} + +sub _musicipError { + my $http = shift; + my $error = $http->error; + my $params = $http->params('params'); + + $log->error( $params(error) || "MusicIP: http error, no response."); +} + sub prefName { my $class = shift;