Migrated scanner stuff
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
add_library(lmsscanner SHARED
|
add_library(lmsscanner SHARED
|
||||||
impl/AcousticBrainzUtils.cpp
|
impl/AcousticBrainzUtils.cpp
|
||||||
impl/Scanner.cpp
|
impl/ScannerService.cpp
|
||||||
impl/ScannerStats.cpp
|
impl/ScannerStats.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,122 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2013 Emeric Poupon
|
|
||||||
*
|
|
||||||
* This file is part of LMS.
|
|
||||||
*
|
|
||||||
* LMS is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* LMS is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <shared_mutex>
|
|
||||||
#include <optional>
|
|
||||||
#include <unordered_set>
|
|
||||||
|
|
||||||
#include <Wt/WDateTime.h>
|
|
||||||
#include <Wt/WIOService.h>
|
|
||||||
#include <Wt/WSignal.h>
|
|
||||||
|
|
||||||
#include <boost/asio/system_timer.hpp>
|
|
||||||
|
|
||||||
#include "database/Types.hpp"
|
|
||||||
#include "database/ScanSettings.hpp"
|
|
||||||
#include "database/Session.hpp"
|
|
||||||
#include "metadata/IParser.hpp"
|
|
||||||
#include "scanner/IScanner.hpp"
|
|
||||||
#include "utils/Path.hpp"
|
|
||||||
|
|
||||||
class UUID;
|
|
||||||
|
|
||||||
namespace Recommendation
|
|
||||||
{
|
|
||||||
class IRecommendationService;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Scanner {
|
|
||||||
|
|
||||||
class Scanner : public IScanner
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Scanner(Database::Db& db, Recommendation::IRecommendationService& recommendationService);
|
|
||||||
~Scanner();
|
|
||||||
|
|
||||||
Scanner(const Scanner&) = delete;
|
|
||||||
Scanner(Scanner&&) = delete;
|
|
||||||
Scanner& operator=(const Scanner&) = delete;
|
|
||||||
Scanner& operator=(Scanner&&) = delete;
|
|
||||||
|
|
||||||
void requestReload() override;
|
|
||||||
void requestImmediateScan(bool force) override;
|
|
||||||
|
|
||||||
Status getStatus() const override;
|
|
||||||
Events& getEvents() override { return _events; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
void start();
|
|
||||||
void stop();
|
|
||||||
|
|
||||||
// Job handling
|
|
||||||
void scheduleNextScan();
|
|
||||||
void scheduleScan(bool force, const Wt::WDateTime& dateTime = {});
|
|
||||||
|
|
||||||
void abortScan();
|
|
||||||
|
|
||||||
// Update database (scheduled callback)
|
|
||||||
void scan(bool force);
|
|
||||||
|
|
||||||
void scanMediaDirectory( const std::filesystem::path& mediaDirectory, bool forceScan, ScanStats& stats);
|
|
||||||
bool fetchTrackFeatures(Database::TrackId trackId, const UUID& MBID);
|
|
||||||
void fetchTrackFeatures(ScanStats& stats);
|
|
||||||
|
|
||||||
// Helpers
|
|
||||||
void refreshScanSettings();
|
|
||||||
|
|
||||||
void countAllFiles(ScanStats& stats);
|
|
||||||
void removeMissingTracks(ScanStats& stats);
|
|
||||||
void removeOrphanEntries();
|
|
||||||
void checkDuplicatedAudioFiles(ScanStats& stats);
|
|
||||||
void scanAudioFile(const std::filesystem::path& file, bool forceScan, ScanStats& stats);
|
|
||||||
void notifyInProgressIfNeeded(const ScanStepStats& stats);
|
|
||||||
void notifyInProgress(const ScanStepStats& stats);
|
|
||||||
void reloadSimilarityEngine(ScanStats& stats);
|
|
||||||
|
|
||||||
Recommendation::IRecommendationService& _recommendationService;
|
|
||||||
|
|
||||||
std::mutex _controlMutex;
|
|
||||||
std::atomic<bool> _abortScan {};
|
|
||||||
Wt::WIOService _ioService;
|
|
||||||
boost::asio::system_timer _scheduleTimer {_ioService};
|
|
||||||
Events _events;
|
|
||||||
std::chrono::system_clock::time_point _lastScanInProgressEmit {};
|
|
||||||
Database::Session _dbSession;
|
|
||||||
std::unique_ptr<MetaData::IParser> _metadataParser;
|
|
||||||
|
|
||||||
mutable std::shared_mutex _statusMutex;
|
|
||||||
State _curState {State::NotScheduled};
|
|
||||||
std::optional<ScanStats> _lastCompleteScanStats;
|
|
||||||
std::optional<ScanStepStats> _currentScanStepStats;
|
|
||||||
Wt::WDateTime _nextScheduledScan;
|
|
||||||
|
|
||||||
// Current scan settings
|
|
||||||
std::size_t _scanVersion {};
|
|
||||||
Wt::WTime _startTime;
|
|
||||||
Database::ScanSettings::UpdatePeriod _updatePeriod {Database::ScanSettings::UpdatePeriod::Never};
|
|
||||||
std::unordered_set<std::filesystem::path> _fileExtensions;
|
|
||||||
std::filesystem::path _mediaDirectory;
|
|
||||||
Database::ScanSettings::RecommendationEngineType _recommendationServiceType;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // Scanner
|
|
||||||
|
|
||||||
+28
-28
@@ -17,7 +17,7 @@
|
|||||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Scanner.hpp"
|
#include "ScannerService.hpp"
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <boost/asio/placeholders.hpp>
|
#include <boost/asio/placeholders.hpp>
|
||||||
@@ -248,13 +248,13 @@ getOrCreateClusters(Session& session, const MetaData::Clusters& clustersNames)
|
|||||||
|
|
||||||
namespace Scanner {
|
namespace Scanner {
|
||||||
|
|
||||||
std::unique_ptr<IScanner>
|
std::unique_ptr<IScannerService>
|
||||||
createScanner(Database::Db& db, Recommendation::IRecommendationService& recommendationService)
|
createScannerService(Database::Db& db, Recommendation::IRecommendationService& recommendationService)
|
||||||
{
|
{
|
||||||
return std::make_unique<Scanner>(db, recommendationService);
|
return std::make_unique<ScannerService>(db, recommendationService);
|
||||||
}
|
}
|
||||||
|
|
||||||
Scanner::Scanner(Database::Db& db, Recommendation::IRecommendationService& recommendationService)
|
ScannerService::ScannerService(Database::Db& db, Recommendation::IRecommendationService& recommendationService)
|
||||||
: _recommendationService {recommendationService}
|
: _recommendationService {recommendationService}
|
||||||
, _dbSession {db}
|
, _dbSession {db}
|
||||||
{
|
{
|
||||||
@@ -268,14 +268,14 @@ Scanner::Scanner(Database::Db& db, Recommendation::IRecommendationService& recom
|
|||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
Scanner::~Scanner()
|
ScannerService::~ScannerService()
|
||||||
{
|
{
|
||||||
LMS_LOG(DBUPDATER, INFO) << "Shutting down Scanner...";
|
LMS_LOG(DBUPDATER, INFO) << "Shutting down Scanner...";
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Scanner::start()
|
ScannerService::start()
|
||||||
{
|
{
|
||||||
std::scoped_lock lock {_controlMutex};
|
std::scoped_lock lock {_controlMutex};
|
||||||
|
|
||||||
@@ -296,7 +296,7 @@ Scanner::start()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Scanner::stop()
|
ScannerService::stop()
|
||||||
{
|
{
|
||||||
std::scoped_lock lock {_controlMutex};
|
std::scoped_lock lock {_controlMutex};
|
||||||
|
|
||||||
@@ -307,7 +307,7 @@ Scanner::stop()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Scanner::abortScan()
|
ScannerService::abortScan()
|
||||||
{
|
{
|
||||||
LMS_LOG(DBUPDATER, DEBUG) << "Aborting scan...";
|
LMS_LOG(DBUPDATER, DEBUG) << "Aborting scan...";
|
||||||
std::scoped_lock lock {_controlMutex};
|
std::scoped_lock lock {_controlMutex};
|
||||||
@@ -325,7 +325,7 @@ Scanner::abortScan()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Scanner::requestImmediateScan(bool force)
|
ScannerService::requestImmediateScan(bool force)
|
||||||
{
|
{
|
||||||
abortScan();
|
abortScan();
|
||||||
_ioService.post([=]()
|
_ioService.post([=]()
|
||||||
@@ -338,7 +338,7 @@ Scanner::requestImmediateScan(bool force)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Scanner::requestReload()
|
ScannerService::requestReload()
|
||||||
{
|
{
|
||||||
abortScan();
|
abortScan();
|
||||||
_ioService.post([=]()
|
_ioService.post([=]()
|
||||||
@@ -350,8 +350,8 @@ Scanner::requestReload()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Scanner::Status
|
ScannerService::Status
|
||||||
Scanner::getStatus() const
|
ScannerService::getStatus() const
|
||||||
{
|
{
|
||||||
Status res;
|
Status res;
|
||||||
|
|
||||||
@@ -366,7 +366,7 @@ Scanner::getStatus() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Scanner::scheduleNextScan()
|
ScannerService::scheduleNextScan()
|
||||||
{
|
{
|
||||||
LMS_LOG(DBUPDATER, INFO) << "Scheduling next scan";
|
LMS_LOG(DBUPDATER, INFO) << "Scheduling next scan";
|
||||||
|
|
||||||
@@ -420,7 +420,7 @@ Scanner::scheduleNextScan()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Scanner::countAllFiles(ScanStats& stats)
|
ScannerService::countAllFiles(ScanStats& stats)
|
||||||
{
|
{
|
||||||
ScanStepStats stepStats{stats.startTime, ScanProgressStep::DiscoveringFiles};
|
ScanStepStats stepStats{stats.startTime, ScanProgressStep::DiscoveringFiles};
|
||||||
|
|
||||||
@@ -445,7 +445,7 @@ Scanner::countAllFiles(ScanStats& stats)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Scanner::scheduleScan(bool force, const Wt::WDateTime& dateTime)
|
ScannerService::scheduleScan(bool force, const Wt::WDateTime& dateTime)
|
||||||
{
|
{
|
||||||
auto cb {[=](boost::system::error_code ec)
|
auto cb {[=](boost::system::error_code ec)
|
||||||
{
|
{
|
||||||
@@ -474,7 +474,7 @@ Scanner::scheduleScan(bool force, const Wt::WDateTime& dateTime)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Scanner::scan(bool forceScan)
|
ScannerService::scan(bool forceScan)
|
||||||
{
|
{
|
||||||
_events.scanStarted.emit();
|
_events.scanStarted.emit();
|
||||||
|
|
||||||
@@ -543,7 +543,7 @@ Scanner::scan(bool forceScan)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Scanner::fetchTrackFeatures(Database::TrackId trackId, const UUID& recordingMBID)
|
ScannerService::fetchTrackFeatures(Database::TrackId trackId, const UUID& recordingMBID)
|
||||||
{
|
{
|
||||||
std::map<std::string, double> features;
|
std::map<std::string, double> features;
|
||||||
|
|
||||||
@@ -569,7 +569,7 @@ Scanner::fetchTrackFeatures(Database::TrackId trackId, const UUID& recordingMBID
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Scanner::fetchTrackFeatures(ScanStats& stats)
|
ScannerService::fetchTrackFeatures(ScanStats& stats)
|
||||||
{
|
{
|
||||||
if (_recommendationServiceType != ScanSettings::RecommendationEngineType::Features)
|
if (_recommendationServiceType != ScanSettings::RecommendationEngineType::Features)
|
||||||
return;
|
return;
|
||||||
@@ -619,7 +619,7 @@ Scanner::fetchTrackFeatures(ScanStats& stats)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Scanner::refreshScanSettings()
|
ScannerService::refreshScanSettings()
|
||||||
{
|
{
|
||||||
auto transaction {_dbSession.createSharedTransaction()};
|
auto transaction {_dbSession.createSharedTransaction()};
|
||||||
|
|
||||||
@@ -651,7 +651,7 @@ Scanner::refreshScanSettings()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Scanner::notifyInProgress(const ScanStepStats& stepStats)
|
ScannerService::notifyInProgress(const ScanStepStats& stepStats)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::unique_lock lock {_statusMutex};
|
std::unique_lock lock {_statusMutex};
|
||||||
@@ -664,7 +664,7 @@ Scanner::notifyInProgress(const ScanStepStats& stepStats)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Scanner::notifyInProgressIfNeeded(const ScanStepStats& stepStats)
|
ScannerService::notifyInProgressIfNeeded(const ScanStepStats& stepStats)
|
||||||
{
|
{
|
||||||
std::chrono::system_clock::time_point now {std::chrono::system_clock::now()};
|
std::chrono::system_clock::time_point now {std::chrono::system_clock::now()};
|
||||||
|
|
||||||
@@ -673,7 +673,7 @@ Scanner::notifyInProgressIfNeeded(const ScanStepStats& stepStats)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Scanner::scanAudioFile(const std::filesystem::path& file, bool forceScan, ScanStats& stats)
|
ScannerService::scanAudioFile(const std::filesystem::path& file, bool forceScan, ScanStats& stats)
|
||||||
{
|
{
|
||||||
Wt::WDateTime lastWriteTime;
|
Wt::WDateTime lastWriteTime;
|
||||||
try
|
try
|
||||||
@@ -836,7 +836,7 @@ Scanner::scanAudioFile(const std::filesystem::path& file, bool forceScan, ScanSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Scanner::scanMediaDirectory(const std::filesystem::path& mediaDirectory, bool forceScan, ScanStats& stats)
|
ScannerService::scanMediaDirectory(const std::filesystem::path& mediaDirectory, bool forceScan, ScanStats& stats)
|
||||||
{
|
{
|
||||||
ScanStepStats stepStats{stats.startTime, ScanProgressStep::ScanningFiles};
|
ScanStepStats stepStats{stats.startTime, ScanProgressStep::ScanningFiles};
|
||||||
stepStats.totalElems = stats.filesScanned;
|
stepStats.totalElems = stats.filesScanned;
|
||||||
@@ -903,7 +903,7 @@ checkFile(const std::filesystem::path& p, const std::filesystem::path& mediaDire
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Scanner::removeMissingTracks(ScanStats& stats)
|
ScannerService::removeMissingTracks(ScanStats& stats)
|
||||||
{
|
{
|
||||||
static constexpr std::size_t batchSize {50};
|
static constexpr std::size_t batchSize {50};
|
||||||
|
|
||||||
@@ -970,7 +970,7 @@ Scanner::removeMissingTracks(ScanStats& stats)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Scanner::removeOrphanEntries()
|
ScannerService::removeOrphanEntries()
|
||||||
{
|
{
|
||||||
LMS_LOG(DBUPDATER, DEBUG) << "Checking orphan clusters...";
|
LMS_LOG(DBUPDATER, DEBUG) << "Checking orphan clusters...";
|
||||||
{
|
{
|
||||||
@@ -1013,7 +1013,7 @@ Scanner::removeOrphanEntries()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Scanner::checkDuplicatedAudioFiles(ScanStats& stats)
|
ScannerService::checkDuplicatedAudioFiles(ScanStats& stats)
|
||||||
{
|
{
|
||||||
LMS_LOG(DBUPDATER, INFO) << "Checking duplicated audio files";
|
LMS_LOG(DBUPDATER, INFO) << "Checking duplicated audio files";
|
||||||
|
|
||||||
@@ -1033,7 +1033,7 @@ Scanner::checkDuplicatedAudioFiles(ScanStats& stats)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Scanner::reloadSimilarityEngine(ScanStats& stats)
|
ScannerService::reloadSimilarityEngine(ScanStats& stats)
|
||||||
{
|
{
|
||||||
ScanStepStats stepStats {stats.startTime, ScanProgressStep::ReloadingSimilarityEngine};
|
ScanStepStats stepStats {stats.startTime, ScanProgressStep::ReloadingSimilarityEngine};
|
||||||
|
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Emeric Poupon
|
||||||
|
*
|
||||||
|
* This file is part of LMS.
|
||||||
|
*
|
||||||
|
* LMS is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* LMS is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <shared_mutex>
|
||||||
|
#include <optional>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
|
#include <Wt/WDateTime.h>
|
||||||
|
#include <Wt/WIOService.h>
|
||||||
|
#include <Wt/WSignal.h>
|
||||||
|
|
||||||
|
#include <boost/asio/system_timer.hpp>
|
||||||
|
|
||||||
|
#include "database/Types.hpp"
|
||||||
|
#include "database/ScanSettings.hpp"
|
||||||
|
#include "database/Session.hpp"
|
||||||
|
#include "metadata/IParser.hpp"
|
||||||
|
#include "services/scanner/IScannerService.hpp"
|
||||||
|
#include "utils/Path.hpp"
|
||||||
|
|
||||||
|
class UUID;
|
||||||
|
|
||||||
|
namespace Recommendation
|
||||||
|
{
|
||||||
|
class IRecommendationService;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Scanner
|
||||||
|
{
|
||||||
|
class ScannerService : public IScannerService
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ScannerService(Database::Db& db, Recommendation::IRecommendationService& recommendationService);
|
||||||
|
~ScannerService();
|
||||||
|
|
||||||
|
ScannerService(const ScannerService&) = delete;
|
||||||
|
ScannerService(ScannerService&&) = delete;
|
||||||
|
ScannerService& operator=(const ScannerService&) = delete;
|
||||||
|
ScannerService& operator=(ScannerService&&) = delete;
|
||||||
|
|
||||||
|
void requestReload() override;
|
||||||
|
void requestImmediateScan(bool force) override;
|
||||||
|
|
||||||
|
Status getStatus() const override;
|
||||||
|
Events& getEvents() override { return _events; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void start();
|
||||||
|
void stop();
|
||||||
|
|
||||||
|
// Job handling
|
||||||
|
void scheduleNextScan();
|
||||||
|
void scheduleScan(bool force, const Wt::WDateTime& dateTime = {});
|
||||||
|
|
||||||
|
void abortScan();
|
||||||
|
|
||||||
|
// Update database (scheduled callback)
|
||||||
|
void scan(bool force);
|
||||||
|
|
||||||
|
void scanMediaDirectory( const std::filesystem::path& mediaDirectory, bool forceScan, ScanStats& stats);
|
||||||
|
bool fetchTrackFeatures(Database::TrackId trackId, const UUID& MBID);
|
||||||
|
void fetchTrackFeatures(ScanStats& stats);
|
||||||
|
|
||||||
|
// Helpers
|
||||||
|
void refreshScanSettings();
|
||||||
|
|
||||||
|
void countAllFiles(ScanStats& stats);
|
||||||
|
void removeMissingTracks(ScanStats& stats);
|
||||||
|
void removeOrphanEntries();
|
||||||
|
void checkDuplicatedAudioFiles(ScanStats& stats);
|
||||||
|
void scanAudioFile(const std::filesystem::path& file, bool forceScan, ScanStats& stats);
|
||||||
|
void notifyInProgressIfNeeded(const ScanStepStats& stats);
|
||||||
|
void notifyInProgress(const ScanStepStats& stats);
|
||||||
|
void reloadSimilarityEngine(ScanStats& stats);
|
||||||
|
|
||||||
|
Recommendation::IRecommendationService& _recommendationService;
|
||||||
|
|
||||||
|
std::mutex _controlMutex;
|
||||||
|
std::atomic<bool> _abortScan {};
|
||||||
|
Wt::WIOService _ioService;
|
||||||
|
boost::asio::system_timer _scheduleTimer {_ioService};
|
||||||
|
Events _events;
|
||||||
|
std::chrono::system_clock::time_point _lastScanInProgressEmit {};
|
||||||
|
Database::Session _dbSession;
|
||||||
|
std::unique_ptr<MetaData::IParser> _metadataParser;
|
||||||
|
|
||||||
|
mutable std::shared_mutex _statusMutex;
|
||||||
|
State _curState {State::NotScheduled};
|
||||||
|
std::optional<ScanStats> _lastCompleteScanStats;
|
||||||
|
std::optional<ScanStepStats> _currentScanStepStats;
|
||||||
|
Wt::WDateTime _nextScheduledScan;
|
||||||
|
|
||||||
|
// Current scan settings
|
||||||
|
std::size_t _scanVersion {};
|
||||||
|
Wt::WTime _startTime;
|
||||||
|
Database::ScanSettings::UpdatePeriod _updatePeriod {Database::ScanSettings::UpdatePeriod::Never};
|
||||||
|
std::unordered_set<std::filesystem::path> _fileExtensions;
|
||||||
|
std::filesystem::path _mediaDirectory;
|
||||||
|
Database::ScanSettings::RecommendationEngineType _recommendationServiceType;
|
||||||
|
};
|
||||||
|
} // Scanner
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "scanner/ScannerStats.hpp"
|
#include "services/scanner/ScannerStats.hpp"
|
||||||
|
|
||||||
namespace Scanner {
|
namespace Scanner {
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -37,10 +37,10 @@ namespace Recommendation
|
|||||||
namespace Scanner
|
namespace Scanner
|
||||||
{
|
{
|
||||||
|
|
||||||
class IScanner
|
class IScannerService
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~IScanner() = default;
|
virtual ~IScannerService() = default;
|
||||||
|
|
||||||
// Async requests
|
// Async requests
|
||||||
virtual void requestReload() = 0;
|
virtual void requestReload() = 0;
|
||||||
@@ -66,7 +66,7 @@ namespace Scanner
|
|||||||
virtual Events& getEvents() = 0;
|
virtual Events& getEvents() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<IScanner> createScanner(Database::Db& db, Recommendation::IRecommendationService& recommendationEngine);
|
std::unique_ptr<IScannerService> createScannerService(Database::Db& db, Recommendation::IRecommendationService& recommendationEngine);
|
||||||
|
|
||||||
} // Scanner
|
} // Scanner
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include "Scan.hpp"
|
#include "Scan.hpp"
|
||||||
|
|
||||||
#include "scanner/IScanner.hpp"
|
#include "services/scanner/IScannerService.hpp"
|
||||||
#include "utils/Service.hpp"
|
#include "utils/Service.hpp"
|
||||||
|
|
||||||
namespace API::Subsonic::Scan
|
namespace API::Subsonic::Scan
|
||||||
@@ -32,10 +32,10 @@ namespace API::Subsonic::Scan
|
|||||||
{
|
{
|
||||||
Response::Node statusResponse;
|
Response::Node statusResponse;
|
||||||
|
|
||||||
const IScanner::Status scanStatus {Service<IScanner>::get()->getStatus()};
|
const IScannerService::Status scanStatus {Service<IScannerService>::get()->getStatus()};
|
||||||
|
|
||||||
statusResponse.setAttribute("scanning", scanStatus.currentState == IScanner::State::InProgress);
|
statusResponse.setAttribute("scanning", scanStatus.currentState == IScannerService::State::InProgress);
|
||||||
if (scanStatus.currentState == IScanner::State::InProgress)
|
if (scanStatus.currentState == IScannerService::State::InProgress)
|
||||||
{
|
{
|
||||||
std::size_t count{};
|
std::size_t count{};
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ namespace API::Subsonic::Scan
|
|||||||
Response
|
Response
|
||||||
handleStartScan(RequestContext& context)
|
handleStartScan(RequestContext& context)
|
||||||
{
|
{
|
||||||
Service<IScanner>::get()->requestImmediateScan(false);
|
Service<IScannerService>::get()->requestImmediateScan(false);
|
||||||
|
|
||||||
Response response {Response::createOkResponse(context.serverProtocolVersion)};
|
Response response {Response::createOkResponse(context.serverProtocolVersion)};
|
||||||
response.addNode("scanStatus", createStatusResponseNode());
|
response.addNode("scanStatus", createStatusResponseNode());
|
||||||
|
|||||||
+3
-3
@@ -31,7 +31,7 @@
|
|||||||
#include "services/cover/ICoverService.hpp"
|
#include "services/cover/ICoverService.hpp"
|
||||||
#include "database/Db.hpp"
|
#include "database/Db.hpp"
|
||||||
#include "database/Session.hpp"
|
#include "database/Session.hpp"
|
||||||
#include "scanner/IScanner.hpp"
|
#include "services/scanner/IScannerService.hpp"
|
||||||
#include "subsonic/SubsonicResource.hpp"
|
#include "subsonic/SubsonicResource.hpp"
|
||||||
#include "services/recommendation/IRecommendationService.hpp"
|
#include "services/recommendation/IRecommendationService.hpp"
|
||||||
#include "services/scrobbling/IScrobblingService.hpp"
|
#include "services/scrobbling/IScrobblingService.hpp"
|
||||||
@@ -132,7 +132,7 @@ generateWtConfig(std::string execPath)
|
|||||||
|
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
proxyScannerEventsToApplication(Scanner::IScanner& scanner, Wt::WServer& server)
|
proxyScannerEventsToApplication(Scanner::IScannerService& scanner, Wt::WServer& server)
|
||||||
{
|
{
|
||||||
auto postAll {[](Wt::WServer& server, std::function<void()> cb)
|
auto postAll {[](Wt::WServer& server, std::function<void()> cb)
|
||||||
{
|
{
|
||||||
@@ -259,7 +259,7 @@ int main(int argc, char* argv[])
|
|||||||
Service<Http::IClient> httpClient {Http::createClient(ioContext)};
|
Service<Http::IClient> httpClient {Http::createClient(ioContext)};
|
||||||
Service<Cover::ICoverService> coverService {Cover::createCoverService(database, argv[0], server.appRoot() + "/images/unknown-cover.jpg")};
|
Service<Cover::ICoverService> coverService {Cover::createCoverService(database, argv[0], server.appRoot() + "/images/unknown-cover.jpg")};
|
||||||
Service<Recommendation::IRecommendationService> recommendationService {Recommendation::createRecommendationService(database)};
|
Service<Recommendation::IRecommendationService> recommendationService {Recommendation::createRecommendationService(database)};
|
||||||
Service<Scanner::IScanner> scannerService {Scanner::createScanner(database, *recommendationService)};
|
Service<Scanner::IScannerService> scannerService {Scanner::createScannerService(database, *recommendationService)};
|
||||||
|
|
||||||
scannerService->getEvents().scanComplete.connect([&]
|
scannerService->getEvents().scanComplete.connect([&]
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include <Wt/WApplication.h>
|
#include <Wt/WApplication.h>
|
||||||
|
|
||||||
#include "scanner/ScannerEvents.hpp"
|
#include "services/scanner/ScannerEvents.hpp"
|
||||||
|
|
||||||
namespace Database
|
namespace Database
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
#include "database/Cluster.hpp"
|
#include "database/Cluster.hpp"
|
||||||
#include "database/ScanSettings.hpp"
|
#include "database/ScanSettings.hpp"
|
||||||
#include "database/Session.hpp"
|
#include "database/Session.hpp"
|
||||||
#include "scanner/IScanner.hpp"
|
#include "services/scanner/IScannerService.hpp"
|
||||||
#include "utils/Logger.hpp"
|
#include "utils/Logger.hpp"
|
||||||
#include "utils/Service.hpp"
|
#include "utils/Service.hpp"
|
||||||
#include "utils/String.hpp"
|
#include "utils/String.hpp"
|
||||||
@@ -240,7 +240,7 @@ DatabaseSettingsView::refreshView()
|
|||||||
{
|
{
|
||||||
model->saveData();
|
model->saveData();
|
||||||
|
|
||||||
Service<Scanner::IScanner>::get()->requestImmediateScan(false);
|
Service<Scanner::IScannerService>::get()->requestImmediateScan(false);
|
||||||
LmsApp->notifyMsg(LmsApplication::MsgType::Success, Wt::WString::tr("Lms.Admin.Database.settings-saved"));
|
LmsApp->notifyMsg(LmsApplication::MsgType::Success, Wt::WString::tr("Lms.Admin.Database.settings-saved"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,7 +257,7 @@ DatabaseSettingsView::refreshView()
|
|||||||
|
|
||||||
immScanBtn->clicked().connect([=]
|
immScanBtn->clicked().connect([=]
|
||||||
{
|
{
|
||||||
Service<Scanner::IScanner>::get()->requestImmediateScan(false);
|
Service<Scanner::IScannerService>::get()->requestImmediateScan(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
t->updateView(model.get());
|
t->updateView(model.get());
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
#include "database/Session.hpp"
|
#include "database/Session.hpp"
|
||||||
#include "database/Track.hpp"
|
#include "database/Track.hpp"
|
||||||
#include "scanner/IScanner.hpp"
|
#include "services/scanner/IScannerService.hpp"
|
||||||
#include "utils/Service.hpp"
|
#include "utils/Service.hpp"
|
||||||
#include "LmsApplication.hpp"
|
#include "LmsApplication.hpp"
|
||||||
|
|
||||||
@@ -163,20 +163,20 @@ ScannerController::refreshContents()
|
|||||||
actionBtn->actionButton()->setText(Wt::WString::tr("Lms.Admin.ScannerController.scan-now"));
|
actionBtn->actionButton()->setText(Wt::WString::tr("Lms.Admin.ScannerController.scan-now"));
|
||||||
actionBtn->actionButton()->clicked().connect([]
|
actionBtn->actionButton()->clicked().connect([]
|
||||||
{
|
{
|
||||||
Service<Scanner::IScanner>::get()->requestImmediateScan(false);
|
Service<Scanner::IScannerService>::get()->requestImmediateScan(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
auto popup = std::make_unique<Wt::WPopupMenu>();
|
auto popup = std::make_unique<Wt::WPopupMenu>();
|
||||||
popup->addItem(Wt::WString::tr("Lms.Admin.ScannerController.force-scan-now"));
|
popup->addItem(Wt::WString::tr("Lms.Admin.ScannerController.force-scan-now"));
|
||||||
popup->itemSelected().connect([]
|
popup->itemSelected().connect([]
|
||||||
{
|
{
|
||||||
Service<Scanner::IScanner>::get()->requestImmediateScan(true);
|
Service<Scanner::IScannerService>::get()->requestImmediateScan(true);
|
||||||
});
|
});
|
||||||
actionBtn->dropDownButton()->setMenu(std::move(popup));
|
actionBtn->dropDownButton()->setMenu(std::move(popup));
|
||||||
actionBtn->dropDownButton()->addStyleClass("btn-primary");
|
actionBtn->dropDownButton()->addStyleClass("btn-primary");
|
||||||
|
|
||||||
|
|
||||||
const IScanner::Status status {Service<IScanner>::get()->getStatus()};
|
const IScannerService::Status status {Service<IScannerService>::get()->getStatus()};
|
||||||
if (status.lastCompleteScanStats)
|
if (status.lastCompleteScanStats)
|
||||||
{
|
{
|
||||||
bindString("last-scan", Wt::WString::tr("Lms.Admin.ScannerController.last-scan-status")
|
bindString("last-scan", Wt::WString::tr("Lms.Admin.ScannerController.last-scan-status")
|
||||||
@@ -200,16 +200,16 @@ ScannerController::refreshContents()
|
|||||||
|
|
||||||
switch (status.currentState)
|
switch (status.currentState)
|
||||||
{
|
{
|
||||||
case IScanner::State::NotScheduled:
|
case IScannerService::State::NotScheduled:
|
||||||
bindString("status", Wt::WString::tr("Lms.Admin.ScannerController.status-not-scheduled"));
|
bindString("status", Wt::WString::tr("Lms.Admin.ScannerController.status-not-scheduled"));
|
||||||
bindEmpty("step-status");
|
bindEmpty("step-status");
|
||||||
break;
|
break;
|
||||||
case IScanner::State::Scheduled:
|
case IScannerService::State::Scheduled:
|
||||||
bindString("status", Wt::WString::tr("Lms.Admin.ScannerController.status-scheduled")
|
bindString("status", Wt::WString::tr("Lms.Admin.ScannerController.status-scheduled")
|
||||||
.arg(status.nextScheduledScan.toString()));
|
.arg(status.nextScheduledScan.toString()));
|
||||||
bindEmpty("step-status");
|
bindEmpty("step-status");
|
||||||
break;
|
break;
|
||||||
case IScanner::State::InProgress:
|
case IScannerService::State::InProgress:
|
||||||
bindString("status", Wt::WString::tr("Lms.Admin.ScannerController.status-in-progress")
|
bindString("status", Wt::WString::tr("Lms.Admin.ScannerController.status-in-progress")
|
||||||
.arg(static_cast<int>(status.currentScanStepStats->currentStep) + 1)
|
.arg(static_cast<int>(status.currentScanStepStats->currentStep) + 1)
|
||||||
.arg(Scanner::ScanProgressStepCount));
|
.arg(Scanner::ScanProgressStepCount));
|
||||||
|
|||||||
Reference in New Issue
Block a user