Fixed a case where moving a file may be broken (when skipping duplicate MBID is active) + only check for duplicate track MBID (instead of recording MBID) as we have have several different releases sharing the same recording MBID)

This commit is contained in:
emeric
2023-02-22 13:58:18 +01:00
parent 12d967fe4f
commit 8a69d3e309
6 changed files with 29 additions and 10 deletions
+1 -1
View File
@@ -79,7 +79,7 @@ cover-jpeg-quality = 75;
cover-preferred-file-names = ("cover", "front" ); cover-preferred-file-names = ("cover", "front" );
# Set to true if you want to hide duplicate tracks # Set to true if you want to hide duplicate tracks
scanner-skip-duplicate-recording-mbid = false; scanner-skip-duplicate-mbid = false;
# Scanner read style for metadata, maybe be 'fast', 'average' or 'accurate' # Scanner read style for metadata, maybe be 'fast', 'average' or 'accurate'
scanner-parser-read-style = "accurate"; scanner-parser-read-style = "accurate";
+12
View File
@@ -209,6 +209,18 @@ Track::exists(Session& session, TrackId id)
return session.getDboSession().query<int>("SELECT 1 from track").where("id = ?").bind(id).resultValue() == 1; return session.getDboSession().query<int>("SELECT 1 from track").where("id = ?").bind(id).resultValue() == 1;
} }
std::vector<Track::pointer>
Track::findByMBID(Session& session, const UUID& mbid)
{
session.checkSharedLocked();
auto res {session.getDboSession().find<Track>()
.where("mbid = ?").bind(std::string {mbid.getAsString()})
.resultList()};
return std::vector<Track::pointer>(res.begin(), res.end());
}
std::vector<Track::pointer> std::vector<Track::pointer>
Track::findByRecordingMBID(Session& session, const UUID& mbid) Track::findByRecordingMBID(Session& session, const UUID& mbid)
{ {
@@ -110,6 +110,7 @@ class Track : public Object<Track, TrackId>
static pointer find(Session& session, TrackId id); static pointer find(Session& session, TrackId id);
static bool exists(Session& session, TrackId id); static bool exists(Session& session, TrackId id);
static std::vector<pointer> findByRecordingMBID(Session& session, const UUID& MBID); static std::vector<pointer> findByRecordingMBID(Session& session, const UUID& MBID);
static std::vector<pointer> findByMBID(Session& session, const UUID& MBID);
static RangeResults<TrackId> findSimilarTracks(Session& session, const std::vector<TrackId>& trackIds, Range range); static RangeResults<TrackId> findSimilarTracks(Session& session, const std::vector<TrackId>& trackIds, Range range);
static RangeResults<TrackId> find(Session& session, const FindParameters& parameters); static RangeResults<TrackId> find(Session& session, const FindParameters& parameters);
@@ -283,16 +283,22 @@ namespace Scanner
Track::pointer track {Track::findByPath(dbSession, file) }; Track::pointer track {Track::findByPath(dbSession, file) };
// Skip duplicate recording MBID // Skip duplicate track MBID
if (trackInfo->recordingMBID && _settings.skipDuplicateRecordingMBID) if (trackInfo->trackMBID && _settings.skipDuplicateMBID)
{ {
for (Track::pointer otherTrack : Track::findByRecordingMBID(dbSession, *trackInfo->recordingMBID)) for (Track::pointer otherTrack : Track::findByMBID(dbSession, *trackInfo->trackMBID))
{ {
// Skip ourselves
if (track && track->getId() == otherTrack->getId()) if (track && track->getId() == otherTrack->getId())
continue; continue;
LMS_LOG(DBUPDATER, DEBUG) << "Skipped '" << file.string() << "' (similar recording MBID in '" << otherTrack->getPath().string() << "')"; // Skip if the other track found does not exists, as it may have been moved to the current scanned file
// This recording MBID already exists, just remove what we just scanned std::error_code ec;
if (!std::filesystem::exists(otherTrack->getPath(), ec))
continue;
LMS_LOG(DBUPDATER, DEBUG) << "Skipped '" << file.string() << "' (similar MBID in '" << otherTrack->getPath().string() << "')";
// As this MBID already exists, just remove what we just scanned
if (track) if (track)
{ {
track.remove(); track.remove();
@@ -336,7 +336,7 @@ ScannerService::refreshScanSettings()
return; return;
LMS_LOG(DBUPDATER, DEBUG) << "Scanner settings updated"; LMS_LOG(DBUPDATER, DEBUG) << "Scanner settings updated";
LMS_LOG(DBUPDATER, DEBUG) << "skipDuplicateRecordingMBID = " << newSettings.skipDuplicateRecordingMBID; LMS_LOG(DBUPDATER, DEBUG) << "skipDuplicateMBID = " << newSettings.skipDuplicateMBID;
LMS_LOG(DBUPDATER, DEBUG) << "Using scan settings version " << newSettings.scanVersion; LMS_LOG(DBUPDATER, DEBUG) << "Using scan settings version " << newSettings.scanVersion;
_settings = std::move(newSettings); _settings = std::move(newSettings);
@@ -366,7 +366,7 @@ ScannerService::readSettings()
{ {
ScannerSettings newSettings; ScannerSettings newSettings;
newSettings.skipDuplicateRecordingMBID = Service<IConfig>::get()->getBool("scanner-skip-duplicate-recording-mbid", false); newSettings.skipDuplicateMBID = Service<IConfig>::get()->getBool("scanner-skip-duplicate-mbid", false);
{ {
auto transaction {_dbSession.createSharedTransaction()}; auto transaction {_dbSession.createSharedTransaction()};
@@ -36,7 +36,7 @@ namespace Scanner
std::vector<std::filesystem::path> supportedExtensions; std::vector<std::filesystem::path> supportedExtensions;
Database::ScanSettings::RecommendationEngineType recommendationServiceType; Database::ScanSettings::RecommendationEngineType recommendationServiceType;
std::filesystem::path mediaDirectory; std::filesystem::path mediaDirectory;
bool skipDuplicateRecordingMBID {}; bool skipDuplicateMBID {};
std::set<std::string> clusterTypeNames; std::set<std::string> clusterTypeNames;
bool operator==(const ScannerSettings& rhs) const bool operator==(const ScannerSettings& rhs) const
@@ -47,7 +47,7 @@ namespace Scanner
&& supportedExtensions == rhs.supportedExtensions && supportedExtensions == rhs.supportedExtensions
&& recommendationServiceType == rhs.recommendationServiceType && recommendationServiceType == rhs.recommendationServiceType
&& mediaDirectory == rhs.mediaDirectory && mediaDirectory == rhs.mediaDirectory
&& skipDuplicateRecordingMBID == rhs.skipDuplicateRecordingMBID && skipDuplicateMBID == rhs.skipDuplicateMBID
&& clusterTypeNames == rhs.clusterTypeNames; && clusterTypeNames == rhs.clusterTypeNames;
} }
}; };