Sanitize MBID usage: do not trust MBID coming from files' metadata

This commit is contained in:
emeric
2020-02-08 12:38:28 +01:00
parent a4bcd3bbaa
commit 52a0f62491
25 changed files with 298 additions and 132 deletions
+13 -8
View File
@@ -92,9 +92,9 @@ getOrCreateArtists(Session& session, const std::vector<MetaData::Artist>& artist
Artist::pointer artist;
// First try to get by MBID
if (!artistInfo.musicBrainzArtistID.empty())
if (artistInfo.musicBrainzArtistID)
{
artist = Artist::getByMBID(session, artistInfo.musicBrainzArtistID);
artist = Artist::getByMBID(session, *artistInfo.musicBrainzArtistID);
if (!artist)
artist = Artist::create(session, artistInfo.name, artistInfo.musicBrainzArtistID);
@@ -107,7 +107,8 @@ getOrCreateArtists(Session& session, const std::vector<MetaData::Artist>& artist
{
for (const Artist::pointer& sameNamedArtist : Artist::getByName(session, artistInfo.name))
{
if (sameNamedArtist->getMBID().empty())
// Do not fallback on artist that is correctly tagged
if (!sameNamedArtist->getMBID())
{
artist = sameNamedArtist;
break;
@@ -132,9 +133,9 @@ getOrCreateRelease(Session& session, const MetaData::Album& album)
Release::pointer release;
// First try to get by MBID
if (!album.musicBrainzAlbumID.empty())
if (album.musicBrainzAlbumID)
{
release = Release::getByMBID(session, album.musicBrainzAlbumID);
release = Release::getByMBID(session, *album.musicBrainzAlbumID);
if (!release)
release = Release::create(session, album.name, album.musicBrainzAlbumID);
@@ -146,7 +147,8 @@ getOrCreateRelease(Session& session, const MetaData::Album& album)
{
for (const Release::pointer& sameNamedRelease : Release::getByName(session, album.name))
{
if (sameNamedRelease->getMBID().empty())
// do not fallback on properly tagged releases
if (!sameNamedRelease->getMBID())
{
release = sameNamedRelease;
break;
@@ -810,8 +812,11 @@ MediaScanner::checkDuplicatedAudioFiles(ScanStats& stats)
const std::vector<Track::pointer> tracks = Database::Track::getMBIDDuplicates(_dbSession);
for (const Track::pointer& track : tracks)
{
LMS_LOG(DBUPDATER, INFO) << "Found duplicated MBID [" << track->getMBID() << "], file: " << track->getPath().string() << " - " << track->getName();
stats.duplicates.emplace_back(ScanDuplicate {track->getPath(), DuplicateReason::SameMBID});
if (track->getMBID())
{
LMS_LOG(DBUPDATER, INFO) << "Found duplicated MBID [" << track->getMBID()->getAsString() << "], file: " << track->getPath().string() << " - " << track->getName();
stats.duplicates.emplace_back(ScanDuplicate {track->getPath(), DuplicateReason::SameMBID});
}
}
LMS_LOG(DBUPDATER, INFO) << "Checking duplicated audio files done!";