[DB] Better reporting database scan results (skipped, import errors)

This commit is contained in:
emeric
2016-02-03 12:46:27 +01:00
parent 5676ef866c
commit 6da1b42f93
2 changed files with 192 additions and 188 deletions
+15 -14
View File
@@ -245,9 +245,10 @@ Updater::process(boost::system::error_code err)
LMS_LOG(DBUPDATER, INFO) << "Processing root directory '" << rootDirectory.path << "' DONE"; LMS_LOG(DBUPDATER, INFO) << "Processing root directory '" << rootDirectory.path << "' DONE";
} }
if (_running)
checkDuplicatedAudioFiles(stats); checkDuplicatedAudioFiles(stats);
LMS_LOG(DBUPDATER, INFO) << "Scan complete. Changes = " << stats.nbChanges() << " (added = " << stats.nbAdded << ", nbRemoved = " << stats.nbRemoved << ", nbModified = " << stats.nbModified << "), Errors = " << stats.nbScanErrors; LMS_LOG(DBUPDATER, INFO) << "Scan complete. Scanned = " << stats.nbScanned << ", Skipped = " << stats.nbSkipped << ", Changes = " << stats.nbChanges() << " (added = " << stats.nbAdded << ", nbRemoved = " << stats.nbRemoved << ", nbModified = " << stats.nbModified << "), Scan errors = " << stats.nbScanErrors << ", Not imported = " << stats.nbNotImported;
// Update database stats // Update database stats
boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
@@ -384,14 +385,18 @@ Updater::processAudioFile( const boost::filesystem::path& file, Stats& stats)
boost::posix_time::ptime lastWriteTime (boost::posix_time::from_time_t( boost::filesystem::last_write_time( file ) ) ); boost::posix_time::ptime lastWriteTime (boost::posix_time::from_time_t( boost::filesystem::last_write_time( file ) ) );
// Skip file if last write is the same // Skip file if last write is the same
// We chose not to compare
{ {
Wt::Dbo::Transaction transaction(_db.getSession()); Wt::Dbo::Transaction transaction(_db.getSession());
Wt::Dbo::ptr<Track> track = Track::getByPath(_db.getSession(), file); Wt::Dbo::ptr<Track> track = Track::getByPath(_db.getSession(), file);
if (track && track->getLastWriteTime() == lastWriteTime) if (track && track->getLastWriteTime() == lastWriteTime)
{
stats.nbSkipped++;
return; return;
} }
}
MetaData::Items items; MetaData::Items items;
if (!_metadataParser.parse(file, items)) if (!_metadataParser.parse(file, items))
@@ -400,6 +405,8 @@ Updater::processAudioFile( const boost::filesystem::path& file, Stats& stats)
return; return;
} }
stats.nbScanned++;
std::vector<unsigned char> checksum ; std::vector<unsigned char> checksum ;
computeCrc(file, checksum); computeCrc(file, checksum);
@@ -421,7 +428,7 @@ Updater::processAudioFile( const boost::filesystem::path& file, Stats& stats)
track.remove(); track.remove();
stats.nbRemoved++; stats.nbRemoved++;
} }
stats.nbScanErrors++; stats.nbNotImported++;
return; return;
} }
if (items.find(MetaData::Type::Duration) == items.end() if (items.find(MetaData::Type::Duration) == items.end()
@@ -435,13 +442,14 @@ Updater::processAudioFile( const boost::filesystem::path& file, Stats& stats)
track.remove(); track.remove();
stats.nbRemoved++; stats.nbRemoved++;
} }
stats.nbScanErrors++; stats.nbNotImported++;
return; return;
} }
// ***** Title // ***** Title
std::string title; std::string title;
if (items.find(MetaData::Type::Title) != items.end()) { if (items.find(MetaData::Type::Title) != items.end())
{
title = boost::any_cast<std::string>(items[MetaData::Type::Title]); title = boost::any_cast<std::string>(items[MetaData::Type::Title]);
} }
else else
@@ -451,7 +459,6 @@ Updater::processAudioFile( const boost::filesystem::path& file, Stats& stats)
title = file.filename().string(); title = file.filename().string();
} }
// ***** Genres // ***** Genres
std::vector< Genre::pointer > genres; std::vector< Genre::pointer > genres;
{ {
@@ -781,11 +788,10 @@ Updater::checkVideoFiles( Stats& stats )
LMS_LOG(DBUPDATER, DEBUG) << "Check video files done!"; LMS_LOG(DBUPDATER, DEBUG) << "Check video files done!";
} }
void void
Updater::processVideoFile( const boost::filesystem::path& file, Stats& stats) Updater::processVideoFile( const boost::filesystem::path& file, Stats& stats)
{ {
try {
// Check last update time // Check last update time
boost::posix_time::ptime lastWriteTime (boost::posix_time::from_time_t( boost::filesystem::last_write_time( file ) ) ); boost::posix_time::ptime lastWriteTime (boost::posix_time::from_time_t( boost::filesystem::last_write_time( file ) ) );
@@ -797,7 +803,8 @@ Updater::processVideoFile( const boost::filesystem::path& file, Stats& stats)
return; return;
MetaData::Items items; MetaData::Items items;
_metadataParser.parse(file, items); if (!_metadataParser.parse(file, items))
return;
// We estimate this is a video if: // We estimate this is a video if:
// - we found a least one video stream // - we found a least one video stream
@@ -850,11 +857,5 @@ Updater::processVideoFile( const boost::filesystem::path& file, Stats& stats)
transaction.commit(); transaction.commit();
} }
catch( std::exception& e )
{
LMS_LOG(DBUPDATER, ERROR) << "Exception while parsing video file : '" << file << "': '" << e.what() << "' => skipping!";
stats.nbScanErrors++;
}
}
} // namespace DatabaseUpdater } // namespace DatabaseUpdater
+4 -1
View File
@@ -44,10 +44,13 @@ class Updater
struct Stats struct Stats
{ {
std::size_t nbSkipped = 0; // no change since last scan
std::size_t nbScanned = 0;
std::size_t nbScanErrors = 0; // cannot scan file
std::size_t nbNotImported = 0; // Not imported (criteria not filled)
std::size_t nbAdded = 0; std::size_t nbAdded = 0;
std::size_t nbRemoved = 0; std::size_t nbRemoved = 0;
std::size_t nbModified = 0; std::size_t nbModified = 0;
std::size_t nbScanErrors = 0;
std::size_t nbChanges() const { return nbAdded + nbRemoved + nbModified;} std::size_t nbChanges() const { return nbAdded + nbRemoved + nbModified;}
}; };