aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Marshall <jmarshall@xbmc.org>2013-12-01 20:55:17 +1300
committerJonathan Marshall <jmarshall@xbmc.org>2013-12-24 13:48:53 +1300
commit7f9ecd9c44473673f1158eb56c881e90d463d3b0 (patch)
tree9392f68178a15b9d8aaf93dc370c34e5e96f654d
parentc77042d75b79235bde56e8ca35acfc049b8cd710 (diff)
[musicdb] adds Merge functions to CAlbum, CArtist and CSong for merging scraped and local information
-rw-r--r--xbmc/music/Album.cpp54
-rw-r--r--xbmc/music/Album.h1
-rw-r--r--xbmc/music/Artist.cpp28
-rw-r--r--xbmc/music/Artist.h2
-rw-r--r--xbmc/music/Song.cpp13
-rw-r--r--xbmc/music/Song.h1
6 files changed, 99 insertions, 0 deletions
diff --git a/xbmc/music/Album.cpp b/xbmc/music/Album.cpp
index 8a0438db18..66d1b2524e 100644
--- a/xbmc/music/Album.cpp
+++ b/xbmc/music/Album.cpp
@@ -53,6 +53,60 @@ CAlbum::CAlbum(const CFileItem& item)
iTimesPlayed = 0;
}
+void CAlbum::MergeScrapedAlbum(const CAlbum& source, bool override /* = true */)
+{
+ /*
+ We don't merge musicbrainz album ID so that a refresh of album information
+ allows a lookup based on name rather than directly (re)using musicbrainz.
+ In future, we may wish to be able to override lookup by musicbrainz so
+ this might be dropped.
+ */
+// strMusicBrainzAlbumID = source.strMusicBrainzAlbumID;
+ if ((override && !source.genre.empty()) || genre.empty())
+ genre = source.genre;
+ if ((override && !source.strAlbum.empty()) || strAlbum.empty())
+ strAlbum = source.strAlbum;
+ if ((override && source.iYear > 0) || iYear == 0)
+ iYear = source.iYear;
+ if (override)
+ bCompilation = source.bCompilation;
+ // iTimesPlayed = source.iTimesPlayed; // times played is derived from songs
+ for (std::map<std::string, std::string>::const_iterator i = source.art.begin(); i != source.art.end(); ++i)
+ {
+ if (override || art.find(i->first) == art.end())
+ art[i->first] = i->second;
+ }
+ strLabel = source.strLabel;
+ thumbURL = source.thumbURL;
+ moods = source.moods;
+ styles = source.styles;
+ themes = source.themes;
+ strReview = source.strReview;
+ strType = source.strType;
+// strPath = source.strPath; // don't merge the path
+ m_strDateOfRelease = source.m_strDateOfRelease;
+ iRating = source.iRating;
+ if (override)
+ {
+ artistCredits = source.artistCredits;
+ artist = source.artist; // artist information is read-only from the database. artistCredits is what counts on scan
+ }
+ else if (source.artistCredits.size() > artistCredits.size())
+ artistCredits.insert(artistCredits.end(), source.artistCredits.begin()+artistCredits.size(), source.artistCredits.end());
+ if (!strMusicBrainzAlbumID.empty())
+ {
+ /* update local songs with MB information */
+ for (VECSONGS::iterator song = songs.begin(); song != songs.end(); ++song)
+ {
+ if (!song->strMusicBrainzTrackID.empty())
+ for (VECSONGS::const_iterator sourceSong = source.infoSongs.begin(); sourceSong != source.infoSongs.end(); ++sourceSong)
+ if (sourceSong->strMusicBrainzTrackID == song->strMusicBrainzTrackID)
+ song->MergeScrapedSong(*sourceSong, override);
+ }
+ }
+ infoSongs = source.infoSongs;
+}
+
CStdString CAlbum::GetArtistString() const
{
return StringUtils::Join(artist, g_advancedSettings.m_musicItemSeparator);
diff --git a/xbmc/music/Album.h b/xbmc/music/Album.h
index ac071b84d5..116aa08841 100644
--- a/xbmc/music/Album.h
+++ b/xbmc/music/Album.h
@@ -38,6 +38,7 @@ public:
CAlbum(const CFileItem& item);
CAlbum() { idAlbum = 0; iRating = 0; iYear = 0; iTimesPlayed = 0; };
bool operator<(const CAlbum &a) const;
+ void MergeScrapedAlbum(const CAlbum& album, bool override = true);
void Reset()
{
diff --git a/xbmc/music/Artist.cpp b/xbmc/music/Artist.cpp
index b718b9a2e8..e864fd82ae 100644
--- a/xbmc/music/Artist.cpp
+++ b/xbmc/music/Artist.cpp
@@ -24,6 +24,34 @@
using namespace std;
+void CArtist::MergeScrapedArtist(const CArtist& source, bool override /* = true */)
+{
+ /*
+ We don't merge musicbrainz artist ID so that a refresh of artist information
+ allows a lookup based on name rather than directly (re)using musicbrainz.
+ In future, we may wish to be able to override lookup by musicbrainz so
+ this might be dropped.
+ */
+ // strMusicBrainzArtistID = source.strMusicBrainzArtistID;
+ if ((override && !source.strArtist.empty()) || strArtist.empty())
+ strArtist = source.strArtist;
+
+ genre = source.genre;
+ strBiography = source.strBiography;
+ styles = source.styles;
+ moods = source.moods;
+ instruments = source.instruments;
+ strBorn = source.strBorn;
+ strFormed = source.strFormed;
+ strDied = source.strDied;
+ strDisbanded = source.strDisbanded;
+ yearsActive = source.yearsActive;
+ thumbURL = source.thumbURL;
+ fanart = source.fanart;
+ discography = source.discography;
+}
+
+
bool CArtist::Load(const TiXmlElement *artist, bool append, bool prioritise)
{
if (!artist) return false;
diff --git a/xbmc/music/Artist.h b/xbmc/music/Artist.h
index e43634bb28..5be55e5793 100644
--- a/xbmc/music/Artist.h
+++ b/xbmc/music/Artist.h
@@ -47,6 +47,8 @@ public:
if (strMusicBrainzArtistID > a.strMusicBrainzArtistID) return false;
return false;
}
+
+ void MergeScrapedArtist(const CArtist& source, bool override = true);
void Reset()
{
diff --git a/xbmc/music/Song.cpp b/xbmc/music/Song.cpp
index 8698759968..44a2261f7f 100644
--- a/xbmc/music/Song.cpp
+++ b/xbmc/music/Song.cpp
@@ -72,6 +72,19 @@ CSong::CSong()
Clear();
}
+void CSong::MergeScrapedSong(const CSong& source, bool override)
+{
+ if ((override && !source.strTitle.empty()) || strTitle.empty())
+ strTitle = source.strTitle;
+ if ((override && source.iTrack != 0) || iTrack == 0)
+ iTrack = source.iTrack;
+ // artist = source.artist; // artist is read-only from the database
+ if (override)
+ artistCredits = source.artistCredits;
+ else if (source.artistCredits.size() > artistCredits.size())
+ artistCredits.insert(artistCredits.end(), source.artistCredits.begin()+artistCredits.size(), source.artistCredits.end());
+}
+
void CSong::Serialize(CVariant& value) const
{
value["filename"] = strFileName;
diff --git a/xbmc/music/Song.h b/xbmc/music/Song.h
index eac0e2ca03..4c7e6e2a1d 100644
--- a/xbmc/music/Song.h
+++ b/xbmc/music/Song.h
@@ -58,6 +58,7 @@ public:
CSong(CFileItem& item);
virtual ~CSong(){};
void Clear() ;
+ void MergeScrapedSong(const CSong& source, bool override);
virtual void Serialize(CVariant& value) const;
bool operator<(const CSong &song) const