From 6578d3f339077c1396f808a288a42a4b2b85a9db Mon Sep 17 00:00:00 2001 From: emeric Date: Fri, 14 Feb 2020 13:27:40 +0100 Subject: [PATCH] Update the artist and album names if they are outdated (and if they contain a MBID). Fixes #30 --- src/database/Artist.hpp | 7 ++++--- src/database/Release.hpp | 5 +++-- src/database/Session.cpp | 8 +++++++- src/scanner/MediaScanner.cpp | 14 ++++++++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/database/Artist.hpp b/src/database/Artist.hpp index 01d261b3..83b51ef2 100644 --- a/src/database/Artist.hpp +++ b/src/database/Artist.hpp @@ -70,8 +70,8 @@ class Artist : public Wt::Dbo::Dbo static std::vector getLastAdded(Session& session, Wt::WDateTime after, std::optional size = {}); // Accessors - const std::string& getName(void) const { return _name; } - std::optional getMBID(void) const { return UUID::fromString(_MBID); } + const std::string& getName(void) const { return _name; } + std::optional getMBID(void) const { return UUID::fromString(_MBID); } std::vector> getReleases(const std::set& clusterIds = {}) const; // if non empty, get the releases that match all these clusters std::size_t getReleaseCount() const; @@ -85,7 +85,8 @@ class Artist : public Wt::Dbo::Dbo // size is the max number of cluster per cluster type std::vector>> getClusterGroups(std::vector> clusterTypes, std::size_t size) const; - void setMBID(const std::optional& mbid) { _MBID = mbid ? mbid->getAsString() : ""; } + void setName(std::string_view name) { _name = name; } + void setMBID(const std::optional& mbid) { _MBID = mbid ? mbid->getAsString() : ""; } void setSortName(const std::string& sortName); // Create diff --git a/src/database/Release.hpp b/src/database/Release.hpp index c0a638f3..76446bc6 100644 --- a/src/database/Release.hpp +++ b/src/database/Release.hpp @@ -88,7 +88,7 @@ class Release : public Wt::Dbo::Dbo void setTotalTrackNumber(std::size_t num) { _totalTrackNumber = static_cast(num); } // Accessors - std::string getName() const { return _name; } + const std::string& getName() const { return _name; } std::optional getMBID() const { return UUID::fromString(_MBID); } std::optional getTotalTrackNumber() const; std::optional getTotalDiscNumber() const; @@ -100,7 +100,8 @@ class Release : public Wt::Dbo::Dbo bool hasVariousArtists() const; std::vector getSimilarReleases(std::optional offset = {}, std::optional count = {}) const; - void setMBID(const std::optional& mbid) { _MBID = mbid ? mbid->getAsString() : ""; } + void setName(std::string_view name) { _name = name; } + void setMBID(const std::optional& mbid) { _MBID = mbid ? mbid->getAsString() : ""; } template void persist(Action& a) diff --git a/src/database/Session.cpp b/src/database/Session.cpp index 0c3aab24..d96d8448 100644 --- a/src/database/Session.cpp +++ b/src/database/Session.cpp @@ -40,7 +40,7 @@ namespace Database { -#define LMS_DATABASE_VERSION 12 +#define LMS_DATABASE_VERSION 13 using Version = std::size_t; @@ -151,6 +151,12 @@ CREATE TABLE IF NOT EXISTS "track_bookmark" ( // Just increment the scan version of the settings to make the next scheduled scan rescan everything ScanSettings::get(*this).modify()->incScanVersion(); } + else if (version == 12) + { + // Artist and release that have a baddly parsed name but a MBID had no chance to updat the name + // Just increment the scan version of the settings to make the next scheduled scan rescan everything + ScanSettings::get(*this).modify()->incScanVersion(); + } else { LMS_LOG(DB, ERROR) << "Database version " << version << " cannot be handled using migration"; diff --git a/src/scanner/MediaScanner.cpp b/src/scanner/MediaScanner.cpp index fb835855..b7c09754 100644 --- a/src/scanner/MediaScanner.cpp +++ b/src/scanner/MediaScanner.cpp @@ -95,7 +95,14 @@ getOrCreateArtists(Session& session, const std::vector& artist { artist = Artist::getByMBID(session, *artistInfo.musicBrainzArtistID); if (!artist) + { artist = Artist::create(session, artistInfo.name, artistInfo.musicBrainzArtistID); + } + else if (artist->getName() != artistInfo.name) + { + // Name may have been updated + artist.modify()->setName(artistInfo.name); + } artists.emplace_back(std::move(artist)); continue; @@ -136,7 +143,14 @@ getOrCreateRelease(Session& session, const MetaData::Album& album) { release = Release::getByMBID(session, *album.musicBrainzAlbumID); if (!release) + { release = Release::create(session, album.name, album.musicBrainzAlbumID); + } + else if (release->getName() != album.name) + { + // Name may have been updated + release.modify()->setName(album.name); + } return release; }