Update the artist and album names if they are outdated (and if they contain a MBID). Fixes #30

This commit is contained in:
emeric
2020-02-14 13:27:40 +01:00
parent ab2efcc5ad
commit 6578d3f339
4 changed files with 28 additions and 6 deletions
+4 -3
View File
@@ -70,8 +70,8 @@ class Artist : public Wt::Dbo::Dbo<Artist>
static std::vector<pointer> getLastAdded(Session& session, Wt::WDateTime after, std::optional<std::size_t> size = {});
// Accessors
const std::string& getName(void) const { return _name; }
std::optional<UUID> getMBID(void) const { return UUID::fromString(_MBID); }
const std::string& getName(void) const { return _name; }
std::optional<UUID> getMBID(void) const { return UUID::fromString(_MBID); }
std::vector<Wt::Dbo::ptr<Release>> getReleases(const std::set<IdType>& 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<Artist>
// size is the max number of cluster per cluster type
std::vector<std::vector<Wt::Dbo::ptr<Cluster>>> getClusterGroups(std::vector<Wt::Dbo::ptr<ClusterType>> clusterTypes, std::size_t size) const;
void setMBID(const std::optional<UUID>& mbid) { _MBID = mbid ? mbid->getAsString() : ""; }
void setName(std::string_view name) { _name = name; }
void setMBID(const std::optional<UUID>& mbid) { _MBID = mbid ? mbid->getAsString() : ""; }
void setSortName(const std::string& sortName);
// Create
+3 -2
View File
@@ -88,7 +88,7 @@ class Release : public Wt::Dbo::Dbo<Release>
void setTotalTrackNumber(std::size_t num) { _totalTrackNumber = static_cast<int>(num); }
// Accessors
std::string getName() const { return _name; }
const std::string& getName() const { return _name; }
std::optional<UUID> getMBID() const { return UUID::fromString(_MBID); }
std::optional<std::size_t> getTotalTrackNumber() const;
std::optional<std::size_t> getTotalDiscNumber() const;
@@ -100,7 +100,8 @@ class Release : public Wt::Dbo::Dbo<Release>
bool hasVariousArtists() const;
std::vector<pointer> getSimilarReleases(std::optional<std::size_t> offset = {}, std::optional<std::size_t> count = {}) const;
void setMBID(const std::optional<UUID>& mbid) { _MBID = mbid ? mbid->getAsString() : ""; }
void setName(std::string_view name) { _name = name; }
void setMBID(const std::optional<UUID>& mbid) { _MBID = mbid ? mbid->getAsString() : ""; }
template<class Action>
void persist(Action& a)
+7 -1
View File
@@ -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";
+14
View File
@@ -95,7 +95,14 @@ getOrCreateArtists(Session& session, const std::vector<MetaData::Artist>& 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;
}