aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjmarshallnz <jcmarsha@gmail.com>2014-02-18 08:00:25 +1300
committerjmarshallnz <jcmarsha@gmail.com>2014-02-18 08:00:25 +1300
commitabc79106756516d3c75da3bcee0df18cd2fa1c3a (patch)
tree5c5cef350c8b8c224e6961efa1fdbcb2b0a33804
parent457d597697334d9f38e9f8edb85928b260f0324d (diff)
parent144ef4734ba1156fe0f51699f12b57199dda15b0 (diff)
Merge pull request #4213 from jmarshallnz/mbid_to_artist
[musicdb] If MBIDs exist, try to match the best corresponding artist name
-rw-r--r--xbmc/music/Album.cpp46
-rw-r--r--xbmc/music/Song.cpp36
2 files changed, 64 insertions, 18 deletions
diff --git a/xbmc/music/Album.cpp b/xbmc/music/Album.cpp
index 66d1b2524e..e5ceccc385 100644
--- a/xbmc/music/Album.cpp
+++ b/xbmc/music/Album.cpp
@@ -38,15 +38,43 @@ CAlbum::CAlbum(const CFileItem& item)
strMusicBrainzAlbumID = tag.GetMusicBrainzAlbumID();
genre = tag.GetGenre();
artist = tag.GetAlbumArtist();
- bool hasMusicBrainzAlbumArtist = !tag.GetMusicBrainzAlbumArtistID().empty();
- const vector<string>& artists = hasMusicBrainzAlbumArtist ? tag.GetMusicBrainzAlbumArtistID() : tag.GetAlbumArtist();
- for (vector<string>::const_iterator it = artists.begin(); it != artists.end(); ++it)
- {
- CStdString artistName = hasMusicBrainzAlbumArtist && !artist.empty() ? artist[0] : *it;
- CStdString artistId = hasMusicBrainzAlbumArtist ? *it : StringUtils::EmptyString;
- CStdString strJoinPhrase = (it == --artists.end() ? "" : g_advancedSettings.m_musicItemSeparator);
- CArtistCredit artistCredit(artistName, artistId, strJoinPhrase);
- artistCredits.push_back(artistCredit);
+ if (!tag.GetMusicBrainzAlbumArtistID().empty())
+ { // have musicbrainz artist info, so use it
+ for (size_t i = 0; i < tag.GetMusicBrainzAlbumArtistID().size(); i++)
+ {
+ CStdString artistId = tag.GetMusicBrainzAlbumArtistID()[i];
+ CStdString artistName;
+ /*
+ We try and get the corresponding artist name from the album artist tag.
+ We match on the same index, and if that fails just use the first name we have.
+ If no albumartist exists, try matching on artist if the MBArtistID matches.
+ */
+ if (!artist.empty())
+ artistName = (i < artist.size()) ? artist[i] : artist[0];
+ else if (!tag.GetMusicBrainzArtistID().empty() && !tag.GetArtist().empty())
+ {
+ vector<string>::const_iterator j = std::find(tag.GetMusicBrainzArtistID().begin(), tag.GetMusicBrainzArtistID().end(), artistId);
+ if (j != tag.GetMusicBrainzArtistID().end())
+ { // find corresponding artist
+ size_t d = std::distance(j,tag.GetMusicBrainzArtistID().begin());
+ artistName = (d < tag.GetArtist().size()) ? tag.GetArtist()[d] : tag.GetArtist()[0];
+ }
+ }
+ if (artistName.empty())
+ artistName = artistId;
+ CStdString strJoinPhrase = (i == tag.GetMusicBrainzAlbumArtistID().size()-1) ? "" : g_advancedSettings.m_musicItemSeparator;
+ CArtistCredit artistCredit(artistName, tag.GetMusicBrainzAlbumArtistID()[i], strJoinPhrase);
+ artistCredits.push_back(artistCredit);
+ }
+ }
+ else
+ { // no musicbrainz info, so fill in directly
+ for (vector<string>::const_iterator it = tag.GetAlbumArtist().begin(); it != tag.GetAlbumArtist().end(); ++it)
+ {
+ CStdString strJoinPhrase = (it == --tag.GetAlbumArtist().end() ? "" : g_advancedSettings.m_musicItemSeparator);
+ CArtistCredit artistCredit(*it, "", strJoinPhrase);
+ artistCredits.push_back(artistCredit);
+ }
}
iYear = stTime.wYear;
bCompilation = tag.GetCompilation();
diff --git a/xbmc/music/Song.cpp b/xbmc/music/Song.cpp
index 44a2261f7f..2886ab6092 100644
--- a/xbmc/music/Song.cpp
+++ b/xbmc/music/Song.cpp
@@ -36,15 +36,33 @@ CSong::CSong(CFileItem& item)
strTitle = tag.GetTitle();
genre = tag.GetGenre();
artist = tag.GetArtist();
- bool hasMusicBrainzArtist = !tag.GetMusicBrainzArtistID().empty();
- const vector<string>& artists = hasMusicBrainzArtist ? tag.GetMusicBrainzArtistID() : tag.GetArtist();
- for (vector<string>::const_iterator it = artists.begin(); it != artists.end(); ++it)
- {
- CStdString artistName = hasMusicBrainzArtist && !artist.empty() ? artist[0] : *it;
- CStdString artistId = hasMusicBrainzArtist ? *it : StringUtils::EmptyString;
- CStdString strJoinPhrase = (it == --artists.end() ? "" : g_advancedSettings.m_musicItemSeparator);
- CArtistCredit artistCredit(artistName, artistId, strJoinPhrase);
- artistCredits.push_back(artistCredit);
+ if (!tag.GetMusicBrainzArtistID().empty())
+ { // have musicbrainz artist info, so use it
+ for (size_t i = 0; i < tag.GetMusicBrainzArtistID().size(); i++)
+ {
+ CStdString artistId = tag.GetMusicBrainzArtistID()[i];
+ CStdString artistName;
+ /*
+ We try and get the corresponding artist name from the album artist tag.
+ We match on the same index, and if that fails just use the first name we have.
+ */
+ if (!artist.empty())
+ artistName = (i < artist.size()) ? artist[i] : artist[0];
+ if (artistName.empty())
+ artistName = artistId;
+ CStdString strJoinPhrase = (i == tag.GetMusicBrainzArtistID().size()-1) ? "" : g_advancedSettings.m_musicItemSeparator;
+ CArtistCredit artistCredit(artistName, artistId, strJoinPhrase);
+ artistCredits.push_back(artistCredit);
+ }
+ }
+ else
+ { // no musicbrainz info, so fill in directly
+ for (vector<string>::const_iterator it = tag.GetArtist().begin(); it != tag.GetArtist().end(); ++it)
+ {
+ CStdString strJoinPhrase = (it == --tag.GetArtist().end() ? "" : g_advancedSettings.m_musicItemSeparator);
+ CArtistCredit artistCredit(*it, "", strJoinPhrase);
+ artistCredits.push_back(artistCredit);
+ }
}
strAlbum = tag.GetAlbum();
albumArtist = tag.GetAlbumArtist();