Add a scan version field for each scanned track
This commit is contained in:
@@ -77,6 +77,7 @@ ScanSettings::setMediaDirectory(boost::filesystem::path p)
|
||||
void
|
||||
ScanSettings::setClusterTypes(const std::set<std::string>& clusterTypeNames)
|
||||
{
|
||||
bool needRescan = false;
|
||||
assert(session());
|
||||
|
||||
// Backup the old list
|
||||
@@ -91,6 +92,7 @@ ScanSettings::setClusterTypes(const std::set<std::string>& clusterTypeNames)
|
||||
{
|
||||
LMS_LOG(DB, INFO) << "Creating cluster type " << clusterTypeName;
|
||||
clusterType = ClusterType::create(*session(), clusterTypeName);
|
||||
needRescan = true;
|
||||
}
|
||||
_clusterTypes.insert(clusterType);
|
||||
}
|
||||
@@ -103,8 +105,12 @@ ScanSettings::setClusterTypes(const std::set<std::string>& clusterTypeNames)
|
||||
{
|
||||
LMS_LOG(DB, INFO) << "Deleting cluster type " << oldClusterType->getName();
|
||||
oldClusterType.remove();
|
||||
needRescan = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (needRescan)
|
||||
_scanVersion += 1;
|
||||
}
|
||||
|
||||
} // namespace Database
|
||||
|
||||
@@ -44,6 +44,7 @@ class ScanSettings : public Wt::Dbo::Dbo<ScanSettings>
|
||||
static pointer get(Wt::Dbo::Session& session);
|
||||
|
||||
// Getters
|
||||
std::size_t getScanVersion() const { return _scanVersion; }
|
||||
boost::filesystem::path getMediaDirectory() const { return _mediaDirectory; }
|
||||
Wt::WTime getUpdateStartTime() const { return _startTime; }
|
||||
UpdatePeriod getUpdatePeriod() const { return _updatePeriod; }
|
||||
@@ -60,6 +61,7 @@ class ScanSettings : public Wt::Dbo::Dbo<ScanSettings>
|
||||
template<class Action>
|
||||
void persist(Action& a)
|
||||
{
|
||||
Wt::Dbo::field(a, _scanVersion, "scan_version");
|
||||
Wt::Dbo::field(a, _mediaDirectory, "media_directory");
|
||||
Wt::Dbo::field(a, _startTime, "start_time");
|
||||
Wt::Dbo::field(a, _updatePeriod, "update_period");
|
||||
@@ -69,6 +71,7 @@ class ScanSettings : public Wt::Dbo::Dbo<ScanSettings>
|
||||
|
||||
private:
|
||||
|
||||
int _scanVersion = 0;
|
||||
std::string _mediaDirectory = "";
|
||||
Wt::WTime _startTime = Wt::WTime(0,0,0);
|
||||
UpdatePeriod _updatePeriod = UpdatePeriod::Never;
|
||||
|
||||
+21
-17
@@ -81,6 +81,7 @@ class Track : public Wt::Dbo::Dbo<Track>
|
||||
static void removeClusters(std::string type);
|
||||
|
||||
// Accessors
|
||||
void setScanVersion(std::size_t version) {_scanVersion = version; }
|
||||
void setTrackNumber(int num) { _trackNumber = num; }
|
||||
void setTotalTrackNumber(int num) { _totalTrackNumber = num; }
|
||||
void setDiscNumber(int num) { _discNumber = num; }
|
||||
@@ -98,29 +99,31 @@ class Track : public Wt::Dbo::Dbo<Track>
|
||||
void setArtist(Wt::Dbo::ptr<Artist> artist) { _artist = artist; }
|
||||
void setRelease(Wt::Dbo::ptr<Release> release) { _release = release; }
|
||||
|
||||
boost::optional<std::size_t> getTrackNumber(void) const;
|
||||
boost::optional<std::size_t> getTotalTrackNumber(void) const;
|
||||
boost::optional<std::size_t> getDiscNumber(void) const;
|
||||
boost::optional<std::size_t> getTotalDiscNumber(void) const;
|
||||
std::string getName(void) const { return _name; }
|
||||
boost::filesystem::path getPath(void) const { return _filePath; }
|
||||
std::chrono::milliseconds getDuration(void) const { return _duration; }
|
||||
boost::optional<int> getYear(void) const;
|
||||
boost::optional<int> getOriginalYear(void) const;
|
||||
Wt::WDateTime getLastWriteTime(void) const { return _fileLastWrite; }
|
||||
Wt::WDateTime getAddedTime(void) const { return _fileAdded; }
|
||||
const std::vector<unsigned char>& getChecksum(void) const { return _fileChecksum; }
|
||||
CoverType getCoverType(void) const { return _coverType; }
|
||||
const std::string& getMBID(void) const { return _MBID; }
|
||||
Wt::Dbo::ptr<Artist> getArtist(void) const { return _artist; }
|
||||
Wt::Dbo::ptr<Release> getRelease(void) const { return _release; }
|
||||
std::vector<Wt::Dbo::ptr<Cluster>> getClusters(void) const;
|
||||
std::size_t getScanVersion() const { return _scanVersion; }
|
||||
boost::optional<std::size_t> getTrackNumber() const;
|
||||
boost::optional<std::size_t> getTotalTrackNumber() const;
|
||||
boost::optional<std::size_t> getDiscNumber() const;
|
||||
boost::optional<std::size_t> getTotalDiscNumber() const;
|
||||
std::string getName() const { return _name; }
|
||||
boost::filesystem::path getPath() const { return _filePath; }
|
||||
std::chrono::milliseconds getDuration() const { return _duration; }
|
||||
boost::optional<int> getYear() const;
|
||||
boost::optional<int> getOriginalYear() const;
|
||||
Wt::WDateTime getLastWriteTime() const { return _fileLastWrite; }
|
||||
Wt::WDateTime getAddedTime() const { return _fileAdded; }
|
||||
const std::vector<unsigned char>& getChecksum() const { return _fileChecksum; }
|
||||
CoverType getCoverType() const { return _coverType; }
|
||||
const std::string& getMBID() const { return _MBID; }
|
||||
Wt::Dbo::ptr<Artist> getArtist() const { return _artist; }
|
||||
Wt::Dbo::ptr<Release> getRelease() const { return _release; }
|
||||
std::vector<Wt::Dbo::ptr<Cluster>> getClusters() const;
|
||||
|
||||
std::vector<std::vector<Wt::Dbo::ptr<Cluster>>> getClusterGroups(std::vector<Wt::Dbo::ptr<ClusterType>> clusterTypes, std::size_t size) const;
|
||||
|
||||
template<class Action>
|
||||
void persist(Action& a)
|
||||
{
|
||||
Wt::Dbo::field(a, _scanVersion, "scan_version");
|
||||
Wt::Dbo::field(a, _trackNumber, "track_number");
|
||||
Wt::Dbo::field(a, _totalTrackNumber, "total_track_number");
|
||||
Wt::Dbo::field(a, _discNumber, "disc_number");
|
||||
@@ -146,6 +149,7 @@ class Track : public Wt::Dbo::Dbo<Track>
|
||||
|
||||
static const std::size_t _maxNameLength = 128;
|
||||
|
||||
int _scanVersion = 0;
|
||||
int _trackNumber = 0;
|
||||
int _totalTrackNumber = 0;
|
||||
int _discNumber = 0;
|
||||
|
||||
@@ -345,6 +345,7 @@ MediaScanner::refreshScanSettings()
|
||||
|
||||
auto scanSettings = ScanSettings::get(_db.getSession());
|
||||
|
||||
_scanVersion = scanSettings->getScanVersion();
|
||||
_startTime = scanSettings->getUpdateStartTime();
|
||||
_updatePeriod = scanSettings->getUpdatePeriod();
|
||||
|
||||
@@ -369,16 +370,14 @@ MediaScanner::scanAudioFile(const boost::filesystem::path& file, bool forceScan,
|
||||
if (!forceScan)
|
||||
{
|
||||
// Skip file if last write is the same
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
|
||||
Wt::Dbo::ptr<Track> track = Track::getByPath(_db.getSession(), file);
|
||||
|
||||
if (track && track->getLastWriteTime() == lastWriteTime && track->getScanVersion() == _scanVersion)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||
|
||||
Wt::Dbo::ptr<Track> track = Track::getByPath(_db.getSession(), file);
|
||||
|
||||
if (track && track->getLastWriteTime() == lastWriteTime)
|
||||
{
|
||||
stats.skips++;
|
||||
return;
|
||||
}
|
||||
stats.skips++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -508,6 +507,7 @@ MediaScanner::scanAudioFile(const boost::filesystem::path& file, bool forceScan,
|
||||
|
||||
assert(track);
|
||||
|
||||
track.modify()->setScanVersion(_scanVersion);
|
||||
track.modify()->setChecksum(checksum);
|
||||
track.modify()->setArtist(artist);
|
||||
track.modify()->setRelease(release);
|
||||
|
||||
@@ -97,6 +97,7 @@ class MediaScanner
|
||||
Database::Handler _db;
|
||||
|
||||
// Current scan settings
|
||||
std::size_t _scanVersion;
|
||||
Wt::WTime _startTime;
|
||||
Database::ScanSettings::UpdatePeriod _updatePeriod;
|
||||
std::set<boost::filesystem::path> _fileExtensions;
|
||||
|
||||
Reference in New Issue
Block a user