Update the artist and album names if they are outdated (and if they contain a MBID). Fixes #30
This commit is contained in:
@@ -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 = {});
|
static std::vector<pointer> getLastAdded(Session& session, Wt::WDateTime after, std::optional<std::size_t> size = {});
|
||||||
|
|
||||||
// Accessors
|
// Accessors
|
||||||
const std::string& getName(void) const { return _name; }
|
const std::string& getName(void) const { return _name; }
|
||||||
std::optional<UUID> getMBID(void) const { return UUID::fromString(_MBID); }
|
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::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;
|
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
|
// 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;
|
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);
|
void setSortName(const std::string& sortName);
|
||||||
|
|
||||||
// Create
|
// Create
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ class Release : public Wt::Dbo::Dbo<Release>
|
|||||||
void setTotalTrackNumber(std::size_t num) { _totalTrackNumber = static_cast<int>(num); }
|
void setTotalTrackNumber(std::size_t num) { _totalTrackNumber = static_cast<int>(num); }
|
||||||
|
|
||||||
// Accessors
|
// 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<UUID> getMBID() const { return UUID::fromString(_MBID); }
|
||||||
std::optional<std::size_t> getTotalTrackNumber() const;
|
std::optional<std::size_t> getTotalTrackNumber() const;
|
||||||
std::optional<std::size_t> getTotalDiscNumber() const;
|
std::optional<std::size_t> getTotalDiscNumber() const;
|
||||||
@@ -100,7 +100,8 @@ class Release : public Wt::Dbo::Dbo<Release>
|
|||||||
bool hasVariousArtists() const;
|
bool hasVariousArtists() const;
|
||||||
std::vector<pointer> getSimilarReleases(std::optional<std::size_t> offset = {}, std::optional<std::size_t> count = {}) 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>
|
template<class Action>
|
||||||
void persist(Action& a)
|
void persist(Action& a)
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
namespace Database {
|
namespace Database {
|
||||||
|
|
||||||
#define LMS_DATABASE_VERSION 12
|
#define LMS_DATABASE_VERSION 13
|
||||||
|
|
||||||
using Version = std::size_t;
|
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
|
// Just increment the scan version of the settings to make the next scheduled scan rescan everything
|
||||||
ScanSettings::get(*this).modify()->incScanVersion();
|
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
|
else
|
||||||
{
|
{
|
||||||
LMS_LOG(DB, ERROR) << "Database version " << version << " cannot be handled using migration";
|
LMS_LOG(DB, ERROR) << "Database version " << version << " cannot be handled using migration";
|
||||||
|
|||||||
@@ -95,7 +95,14 @@ getOrCreateArtists(Session& session, const std::vector<MetaData::Artist>& artist
|
|||||||
{
|
{
|
||||||
artist = Artist::getByMBID(session, *artistInfo.musicBrainzArtistID);
|
artist = Artist::getByMBID(session, *artistInfo.musicBrainzArtistID);
|
||||||
if (!artist)
|
if (!artist)
|
||||||
|
{
|
||||||
artist = Artist::create(session, artistInfo.name, artistInfo.musicBrainzArtistID);
|
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));
|
artists.emplace_back(std::move(artist));
|
||||||
continue;
|
continue;
|
||||||
@@ -136,7 +143,14 @@ getOrCreateRelease(Session& session, const MetaData::Album& album)
|
|||||||
{
|
{
|
||||||
release = Release::getByMBID(session, *album.musicBrainzAlbumID);
|
release = Release::getByMBID(session, *album.musicBrainzAlbumID);
|
||||||
if (!release)
|
if (!release)
|
||||||
|
{
|
||||||
release = Release::create(session, album.name, album.musicBrainzAlbumID);
|
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;
|
return release;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user