WIP. Adding audio stats when refreshing database, and use it to refresh database lastUpdated entry
This commit is contained in:
@@ -25,7 +25,7 @@ Updater::Updater(boost::filesystem::path dbPath, MetaData::Parser& parser)
|
|||||||
void
|
void
|
||||||
Updater::process(void)
|
Updater::process(void)
|
||||||
{
|
{
|
||||||
removeMissingAudioFiles();
|
removeMissingAudioFiles(_result.audioStats);
|
||||||
// TODO video files
|
// TODO video files
|
||||||
|
|
||||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||||
@@ -36,17 +36,24 @@ Updater::process(void)
|
|||||||
{
|
{
|
||||||
switch (directory->getType()) {
|
switch (directory->getType()) {
|
||||||
case MediaDirectory::Audio:
|
case MediaDirectory::Audio:
|
||||||
refreshAudioDirectory(directory->getPath());
|
refreshAudioDirectory(directory->getPath(), _result.audioStats);
|
||||||
break;
|
break;
|
||||||
case MediaDirectory::Video:
|
case MediaDirectory::Video:
|
||||||
refreshVideoDirectory(directory->getPath());
|
refreshVideoDirectory(directory->getPath());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (_result.audioStats.nbChanges() + _result.videoStats.nbChanges() > 0)
|
||||||
|
{
|
||||||
|
Database::MediaDirectorySettings::pointer settings = Database::MediaDirectorySettings::get(_db.getSession());
|
||||||
|
settings.modify()->setLastUpdate(boost::posix_time::second_clock::local_time());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Updater::processAudioFile( const boost::filesystem::path& file)
|
Updater::processAudioFile( const boost::filesystem::path& file, Stats& stats)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@@ -99,8 +106,10 @@ Updater::processAudioFile( const boost::filesystem::path& file)
|
|||||||
std::cerr << "Skipped '" << file << "' (duration null!)" << std::endl;
|
std::cerr << "Skipped '" << file << "' (duration null!)" << std::endl;
|
||||||
|
|
||||||
// If Track exists here, delete it!
|
// If Track exists here, delete it!
|
||||||
if (track)
|
if (track) {
|
||||||
track.remove();
|
track.remove();
|
||||||
|
stats.nbRemoved++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string title;
|
std::string title;
|
||||||
@@ -172,10 +181,12 @@ Updater::processAudioFile( const boost::filesystem::path& file)
|
|||||||
// Create a new song
|
// Create a new song
|
||||||
track = Track::create(_db.getSession(), file, artist, release);
|
track = Track::create(_db.getSession(), file, artist, release);
|
||||||
std::cout << "Adding '" << file << "'" << std::endl;
|
std::cout << "Adding '" << file << "'" << std::endl;
|
||||||
|
stats.nbAdded++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "Updating '" << file << "'" << std::endl;
|
std::cout << "Updating '" << file << "'" << std::endl;
|
||||||
|
stats.nbModified++;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(track);
|
assert(track);
|
||||||
@@ -222,7 +233,7 @@ Updater::processAudioFile( const boost::filesystem::path& file)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Updater::refreshAudioDirectory( const boost::filesystem::path& p)
|
Updater::refreshAudioDirectory( const boost::filesystem::path& p, Stats& stats)
|
||||||
{
|
{
|
||||||
std::cout << "Refreshing audio directory " << p << std::endl;
|
std::cout << "Refreshing audio directory " << p << std::endl;
|
||||||
if (boost::filesystem::exists(p) && boost::filesystem::is_directory(p)) {
|
if (boost::filesystem::exists(p) && boost::filesystem::is_directory(p)) {
|
||||||
@@ -238,10 +249,10 @@ Updater::refreshAudioDirectory( const boost::filesystem::path& p)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (boost::filesystem::is_directory(file)) {
|
if (boost::filesystem::is_directory(file)) {
|
||||||
refreshAudioDirectory( file );
|
refreshAudioDirectory( file, stats );
|
||||||
}
|
}
|
||||||
else if (boost::filesystem::is_regular(file)) {
|
else if (boost::filesystem::is_regular(file)) {
|
||||||
processAudioFile( file );
|
processAudioFile( file, stats );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::cout << "Skipped '" << file << "' (not regular)" << std::endl;
|
std::cout << "Skipped '" << file << "' (not regular)" << std::endl;
|
||||||
@@ -256,7 +267,7 @@ Updater::refreshAudioDirectory( const boost::filesystem::path& p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Updater::removeMissingAudioFiles( void )
|
Updater::removeMissingAudioFiles( Stats& stats )
|
||||||
{
|
{
|
||||||
std::cerr << "Removing missing files..." << std::endl;
|
std::cerr << "Removing missing files..." << std::endl;
|
||||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||||
@@ -272,13 +283,14 @@ Updater::removeMissingAudioFiles( void )
|
|||||||
|| !boost::filesystem::is_regular( p ) )
|
|| !boost::filesystem::is_regular( p ) )
|
||||||
{
|
{
|
||||||
(*i).remove();
|
(*i).remove();
|
||||||
|
stats.nbRemoved++;
|
||||||
std::cerr << "Removing file '" << p << "'" << std::endl;
|
std::cerr << "Removing file '" << p << "'" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
|
|
||||||
std::cerr << "Refrshing missing files done!" << std::endl;
|
std::cerr << "Refreshing missing files done!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
Path::pointer
|
Path::pointer
|
||||||
|
|||||||
@@ -14,13 +14,33 @@ class Updater
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
struct Stats
|
||||||
|
{
|
||||||
|
std::size_t nbAdded;
|
||||||
|
std::size_t nbRemoved;
|
||||||
|
std::size_t nbModified;
|
||||||
|
Stats() : nbAdded(0), nbRemoved(0), nbModified(0) {}
|
||||||
|
|
||||||
|
std::size_t nbChanges() const { return nbAdded + nbRemoved + nbModified;}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Result
|
||||||
|
{
|
||||||
|
Stats audioStats;
|
||||||
|
Stats videoStats;
|
||||||
|
};
|
||||||
|
|
||||||
Updater(boost::filesystem::path db, MetaData::Parser& parser);
|
Updater(boost::filesystem::path db, MetaData::Parser& parser);
|
||||||
|
|
||||||
// Update database
|
// Update database
|
||||||
|
// TODO add a callback to get notifed once finished
|
||||||
void process();
|
void process();
|
||||||
|
|
||||||
|
const Result& getResult(void) const { return _result; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
||||||
// void refresh(const WatchedDirectory& directory);
|
// void refresh(const WatchedDirectory& directory);
|
||||||
|
|
||||||
// Video
|
// Video
|
||||||
@@ -28,15 +48,17 @@ class Updater
|
|||||||
void processVideoFile( const boost::filesystem::path& file);
|
void processVideoFile( const boost::filesystem::path& file);
|
||||||
|
|
||||||
// Audio
|
// Audio
|
||||||
void removeMissingAudioFiles( void );
|
void removeMissingAudioFiles( Stats& stats );
|
||||||
void refreshAudioDirectory( const boost::filesystem::path& directory);
|
void refreshAudioDirectory( const boost::filesystem::path& directory, Stats& stats);
|
||||||
void processAudioFile( const boost::filesystem::path& file);
|
void processAudioFile( const boost::filesystem::path& file, Stats& stats);
|
||||||
|
|
||||||
Database::Path::pointer getAddPath(const boost::filesystem::path& path);
|
Database::Path::pointer getAddPath(const boost::filesystem::path& path);
|
||||||
|
|
||||||
Database::Handler _db;
|
Database::Handler _db;
|
||||||
|
|
||||||
MetaData::Parser& _metadataParser;
|
MetaData::Parser& _metadataParser;
|
||||||
|
|
||||||
|
Result _result; // update results
|
||||||
}; // class Updater
|
}; // class Updater
|
||||||
|
|
||||||
} // DatabaseUpdater
|
} // DatabaseUpdater
|
||||||
|
|||||||
Reference in New Issue
Block a user