Skip to content

Commit

Permalink
Merge pull request #2974 from night199uk/musicfixes
Browse files Browse the repository at this point in the history
[musicdb] Fixes for non-MusicBrainz albums
  • Loading branch information
night199uk committed Jul 19, 2013
2 parents 7aca6dd + e54553d commit 8193a53
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 193 deletions.
23 changes: 21 additions & 2 deletions xbmc/music/Album.cpp
Expand Up @@ -38,6 +38,16 @@ 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);
}
iYear = stTime.wYear;
bCompilation = tag.GetCompilation();
iTimesPlayed = 0;
Expand All @@ -55,8 +65,17 @@ CStdString CAlbum::GetGenreString() const

bool CAlbum::operator<(const CAlbum &a) const
{
if (strAlbum < a.strAlbum) return true;
if (strAlbum > a.strAlbum) return false;
if (strMusicBrainzAlbumID.IsEmpty() && a.strMusicBrainzAlbumID.IsEmpty())
{
if (strAlbum < a.strAlbum) return true;
if (strAlbum > a.strAlbum) return false;

// This will do an std::vector compare (i.e. item by item)
if (artist < a.artist) return true;
if (artist > a.artist) return false;
return false;
}

if (strMusicBrainzAlbumID < a.strMusicBrainzAlbumID) return true;
if (strMusicBrainzAlbumID > a.strMusicBrainzAlbumID) return false;
return false;
Expand Down
18 changes: 14 additions & 4 deletions xbmc/music/Artist.h
Expand Up @@ -36,8 +36,13 @@ class CArtist
long idArtist;
bool operator<(const CArtist& a) const
{
if (strArtist < a.strArtist) return true;
if (strArtist > a.strArtist) return false;
if (strMusicBrainzArtistID.IsEmpty() && a.strMusicBrainzArtistID.IsEmpty())
{
if (strArtist < a.strArtist) return true;
if (strArtist > a.strArtist) return false;
return false;
}

if (strMusicBrainzArtistID < a.strMusicBrainzArtistID) return true;
if (strMusicBrainzArtistID > a.strMusicBrainzArtistID) return false;
return false;
Expand Down Expand Up @@ -102,8 +107,13 @@ class CArtistCredit
: m_strArtist(strArtist), m_strMusicBrainzArtistID(strMusicBrainzArtistID), m_strJoinPhrase(strJoinPhrase), m_boolFeatured(false) { }
bool operator<(const CArtistCredit& a) const
{
if (m_strArtist < a.m_strArtist) return true;
if (m_strArtist > a.m_strArtist) return false;
if (m_strMusicBrainzArtistID.empty() && a.m_strMusicBrainzArtistID.empty())
{
if (m_strArtist < a.m_strArtist) return true;
if (m_strArtist > a.m_strArtist) return false;
return false;
}

if (m_strMusicBrainzArtistID < a.m_strMusicBrainzArtistID) return true;
if (m_strMusicBrainzArtistID > a.m_strMusicBrainzArtistID) return false;
return false;
Expand Down
36 changes: 23 additions & 13 deletions xbmc/music/MusicDatabase.cpp
Expand Up @@ -364,12 +364,15 @@ int CMusicDatabase::AddSong(const int idAlbum,
bHasKaraoke = CKaraokeLyricsFactory::HasLyrics(strPathAndFileName);
#endif

strSQL=PrepareSQL("SELECT * FROM song WHERE (idAlbum = %i AND strMusicBrainzTrackID = '%s') OR (idAlbum=%i AND dwFileNameCRC='%ul' AND strTitle='%s' AND strMusicBrainzTrackID IS NULL)",
idAlbum,
strMusicBrainzTrackID.c_str(),
idAlbum,
crc,
strTitle.c_str());
if (!strMusicBrainzTrackID.empty())
strSQL = PrepareSQL("SELECT * FROM song WHERE idAlbum = %i AND strMusicBrainzTrackID = '%s'",
idAlbum,
strMusicBrainzTrackID.c_str());
else
strSQL = PrepareSQL("SELECT * FROM song WHERE idAlbum=%i AND dwFileNameCRC='%ul' AND strTitle='%s' AND strMusicBrainzTrackID IS NULL",
idAlbum,
crc,
strTitle.c_str());

if (!m_pDS->query(strSQL.c_str()))
return -1;
Expand Down Expand Up @@ -497,10 +500,13 @@ int CMusicDatabase::AddAlbum(const CStdString& strAlbum, const CStdString& strMu
if (NULL == m_pDB.get()) return -1;
if (NULL == m_pDS.get()) return -1;

strSQL=PrepareSQL("SELECT * FROM album WHERE strMusicBrainzAlbumID = '%s' OR (strArtists = '%s' AND strAlbum like '%s' and strMusicBrainzAlbumID IS NULL)",
strMusicBrainzAlbumID.c_str(),
strArtist.c_str(),
strAlbum.c_str());
if (!strMusicBrainzAlbumID.empty())
strSQL = PrepareSQL("SELECT * FROM album WHERE strMusicBrainzAlbumID = '%s'",
strMusicBrainzAlbumID.c_str());
else
strSQL = PrepareSQL("SELECT * FROM album WHERE strArtists = '%s' AND strAlbum like '%s' and strMusicBrainzAlbumID IS NULL",
strArtist.c_str(),
strAlbum.c_str());
m_pDS->query(strSQL.c_str());

if (m_pDS->num_rows() == 0)
Expand Down Expand Up @@ -607,9 +613,13 @@ int CMusicDatabase::AddArtist(const CStdString& strArtist, const CStdString& str
if (NULL == m_pDB.get()) return -1;
if (NULL == m_pDS.get()) return -1;

strSQL = PrepareSQL("SELECT * FROM artist WHERE strMusicBrainzArtistID = '%s' OR (strArtist = '%s' AND strMusicBrainzArtistID IS NULL)",
strMusicBrainzArtistID.IsEmpty() ? "x" : strMusicBrainzArtistID.c_str(),
strArtist.c_str());
if (!strMusicBrainzArtistID.empty())
strSQL = PrepareSQL("SELECT * FROM artist WHERE strMusicBrainzArtistID = '%s'",
strMusicBrainzArtistID.c_str());
else
strSQL = PrepareSQL("SELECT * FROM artist WHERE strArtist = '%s' AND strMusicBrainzArtistID IS NULL",
strArtist.c_str());

m_pDS->query(strSQL.c_str());

if (m_pDS->num_rows() == 0)
Expand Down
10 changes: 10 additions & 0 deletions xbmc/music/Song.cpp
Expand Up @@ -36,6 +36,16 @@ 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);
}
strAlbum = tag.GetAlbum();
albumArtist = tag.GetAlbumArtist();
strMusicBrainzTrackID = tag.GetMusicBrainzTrackID();
Expand Down

0 comments on commit 8193a53

Please sign in to comment.