diff options
author | Jonathan Marshall <jmarshall@xbmc.org> | 2013-12-03 12:17:28 +1300 |
---|---|---|
committer | Jonathan Marshall <jmarshall@xbmc.org> | 2013-12-24 13:48:56 +1300 |
commit | 7ccc6a2d2f5ad33dfb27bf0b908a4cda994a2e35 (patch) | |
tree | 8b5a88352523499d6232b0d79fb25f0d16d4fdc7 | |
parent | f5ffcd2b8af54006b1f2baf19b28ab86856d46db (diff) |
[musicdb] adds UpdateArtist() as a replacement for SetArtistInfo()
-rw-r--r-- | xbmc/interfaces/json-rpc/AudioLibrary.cpp | 2 | ||||
-rw-r--r-- | xbmc/music/MusicDatabase.cpp | 157 | ||||
-rw-r--r-- | xbmc/music/MusicDatabase.h | 22 | ||||
-rw-r--r-- | xbmc/music/infoscanner/MusicInfoScanner.cpp | 38 |
4 files changed, 124 insertions, 95 deletions
diff --git a/xbmc/interfaces/json-rpc/AudioLibrary.cpp b/xbmc/interfaces/json-rpc/AudioLibrary.cpp index 9475ef3d39..3c030f0666 100644 --- a/xbmc/interfaces/json-rpc/AudioLibrary.cpp +++ b/xbmc/interfaces/json-rpc/AudioLibrary.cpp @@ -423,7 +423,7 @@ JSONRPC_STATUS CAudioLibrary::SetArtistDetails(const CStdString &method, ITransp if (ParameterNotNull(parameterObject, "yearsactive")) CopyStringArray(parameterObject["yearsactive"], artist.yearsActive); - if (musicdatabase.SetArtistInfo(id, artist) <= 0) + if (musicdatabase.UpdateArtist(artist) <= 0) return InternalError; CJSONRPCUtils::NotifyItemUpdated(); diff --git a/xbmc/music/MusicDatabase.cpp b/xbmc/music/MusicDatabase.cpp index 15515e7a85..10a54c77b2 100644 --- a/xbmc/music/MusicDatabase.cpp +++ b/xbmc/music/MusicDatabase.cpp @@ -1022,6 +1022,32 @@ int CMusicDatabase::AddGenre(const CStdString& strGenre1) return -1; } +bool CMusicDatabase::UpdateArtist(const CArtist& artist) +{ + UpdateArtist(artist.idArtist, + artist.strArtist, artist.strMusicBrainzArtistID, + artist.strBorn, artist.strFormed, + StringUtils::Join(artist.genre, g_advancedSettings.m_musicItemSeparator), + StringUtils::Join(artist.moods, g_advancedSettings.m_musicItemSeparator), + StringUtils::Join(artist.styles, g_advancedSettings.m_musicItemSeparator), + StringUtils::Join(artist.instruments, g_advancedSettings.m_musicItemSeparator), + artist.strBiography, artist.strDied, + artist.strDisbanded, + StringUtils::Join(artist.yearsActive, g_advancedSettings.m_musicItemSeparator).c_str(), + artist.thumbURL.m_xml.c_str(), + artist.fanart.m_xml.c_str()); + + DeleteArtistDiscography(artist.idArtist); + for (std::vector<std::pair<CStdString,CStdString> >::const_iterator disc = artist.discography.begin(); + disc != artist.discography.end(); + ++disc) + { + AddArtistDiscography(artist.idArtist, disc->first, disc->second); + } + + return true; +} + int CMusicDatabase::AddArtist(const CStdString& strArtist, const CStdString& strMusicBrainzArtistID) { CStdString strSQL; @@ -1103,6 +1129,48 @@ int CMusicDatabase::AddArtist(const CStdString& strArtist, const CStdString& str return -1; } +int CMusicDatabase::UpdateArtist(int idArtist, + const CStdString& strArtist, const CStdString& strMusicBrainzArtistID, + const CStdString& strBorn, const CStdString& strFormed, + const CStdString& strGenres, const CStdString& strMoods, + const CStdString& strStyles, const CStdString& strInstruments, + const CStdString& strBiography, const CStdString& strDied, + const CStdString& strDisbanded, const CStdString& strYearsActive, + const CStdString& strImage, const CStdString& strFanart) +{ + CScraperUrl thumbURL; + CFanart fanart; + std::vector<std::pair<CStdString,CStdString> > discography; + if (idArtist < 0) + return -1; + + CStdString strSQL; + strSQL = PrepareSQL("UPDATE artist SET " + " strArtist = '%s', " + " strBorn = '%s', strFormed = '%s', strGenres = '%s', " + " strMoods = '%s', strStyles = '%s', strInstruments = '%s', " + " strBiography = '%s', strDied = '%s', strDisbanded = '%s', " + " strYearsActive = '%s', strImage = '%s', strFanart = '%s', " + " lastScraped = '%s'", + strArtist.c_str(), /* strMusicBrainzArtistID.c_str(), */ + strBorn.c_str(), strFormed.c_str(), strGenres.c_str(), + strMoods.c_str(), strStyles.c_str(), strInstruments.c_str(), + strBiography.c_str(), strDied.c_str(), strDisbanded.c_str(), + strYearsActive.c_str(), strImage.c_str(), strFanart.c_str(), + CDateTime::GetCurrentDateTime().GetAsDBDateTime().c_str()); + if (strMusicBrainzArtistID.empty()) + strSQL += PrepareSQL(", strMusicBrainzArtistID = NULL"); + else + strSQL += PrepareSQL(", strMusicBrainzArtistID = '%s'", strMusicBrainzArtistID.c_str()); + + strSQL += PrepareSQL(" WHERE idArtist = %i", idArtist); + + bool status = ExecuteQuery(strSQL); + if (status) + AnnounceUpdate("artist", idArtist); + return idArtist; +} + bool CMusicDatabase::GetArtist(int idArtist, CArtist &artist, bool fetchAll /* = false */) { try @@ -1163,6 +1231,21 @@ bool CMusicDatabase::ClearArtistLastScrapedTime(int idArtist) return ExecuteQuery(strSQL); } +int CMusicDatabase::AddArtistDiscography(int idArtist, const CStdString& strAlbum, const CStdString& strYear) +{ + CStdString strSQL=PrepareSQL("INSERT INTO discography (idArtist, strAlbum, strYear) values(%i, '%s', '%s')", + idArtist, + strAlbum.c_str(), + strYear.c_str()); + return ExecuteQuery(strSQL); +} + +bool CMusicDatabase::DeleteArtistDiscography(int idArtist) +{ + CStdString strSQL = PrepareSQL("DELETE FROM discography WHERE idArtist = %i", idArtist); + return ExecuteQuery(strSQL); +} + bool CMusicDatabase::AddSongArtist(int idArtist, int idSong, std::string joinPhrase, bool featured, int iOrder) { CStdString strSQL; @@ -2213,65 +2296,6 @@ bool CMusicDatabase::SearchAlbums(const CStdString& search, CFileItemList &album return false; } -int CMusicDatabase::SetArtistInfo(int idArtist, const CArtist& artist) -{ - CStdString strSQL; - try - { - if (NULL == m_pDB.get()) return -1; - if (NULL == m_pDS.get()) return -1; - - // delete the discography info - strSQL=PrepareSQL("delete from discography where idArtist=%i", idArtist); - m_pDS->exec(strSQL.c_str()); - - // update our data - strSQL=PrepareSQL("UPDATE artist SET" - " strBorn = '%s'," - " strFormed = '%s'," - " strGenres = '%s'," - " strMoods = '%s'," - " strStyles = '%s'," - " strInstruments = '%s'," - " strBiography = '%s'," - " strDied = '%s'," - " strDisbanded = '%s'," - " strYearsActive = '%s'," - " strImage = '%s'," - " strFanart = '%s'," - " lastScraped = '%s' WHERE idArtist=%d", - artist.strBorn.c_str(), - artist.strFormed.c_str(), - StringUtils::Join(artist.genre, g_advancedSettings.m_musicItemSeparator).c_str(), - StringUtils::Join(artist.moods, g_advancedSettings.m_musicItemSeparator).c_str(), - StringUtils::Join(artist.styles, g_advancedSettings.m_musicItemSeparator).c_str(), - StringUtils::Join(artist.instruments, g_advancedSettings.m_musicItemSeparator).c_str(), - artist.strBiography.c_str(), - artist.strDied.c_str(), - artist.strDisbanded.c_str(), - StringUtils::Join(artist.yearsActive, g_advancedSettings.m_musicItemSeparator).c_str(), - artist.thumbURL.m_xml.c_str(), - artist.fanart.m_xml.c_str(), - CDateTime::GetCurrentDateTime().GetAsDBDateTime().c_str(), - idArtist); - m_pDS->exec(strSQL.c_str()); - for (unsigned int i=0;i<artist.discography.size();++i) - { - strSQL=PrepareSQL("insert into discography (idArtist,strAlbum,strYear) values (%i,'%s','%s')",idArtist,artist.discography[i].first.c_str(),artist.discography[i].second.c_str()); - m_pDS->exec(strSQL.c_str()); - } - - return idArtist; - } - catch (...) - { - CLog::Log(LOGERROR, "%s - failed with query (%s)", __FUNCTION__, strSQL.c_str()); - } - - - return -1; -} - bool CMusicDatabase::CleanupSongsByIds(const CStdString &strSongIds) { try @@ -5063,12 +5087,17 @@ void CMusicDatabase::ImportFromXML(const CStdString &xmlFile) CStdString strTitle; if (strnicmp(entry->Value(), "artist", 6) == 0) { - CArtist artist; - artist.Load(entry); - strTitle = artist.strArtist; - int idArtist = GetArtistByName(artist.strArtist); + CArtist importedArtist; + importedArtist.Load(entry); + strTitle = importedArtist.strArtist; + int idArtist = GetArtistByName(importedArtist.strArtist); if (idArtist > -1) - SetArtistInfo(idArtist,artist); + { + CArtist artist; + GetArtist(idArtist, artist); + artist.MergeScrapedArtist(importedArtist, true); + UpdateArtist(artist); + } current++; } diff --git a/xbmc/music/MusicDatabase.h b/xbmc/music/MusicDatabase.h index 5048202a37..cf17dd0985 100644 --- a/xbmc/music/MusicDatabase.h +++ b/xbmc/music/MusicDatabase.h @@ -243,12 +243,23 @@ public: ///////////////////////////////////////////////// // Artist CRUD ///////////////////////////////////////////////// + bool UpdateArtist(const CArtist& artist); + int AddArtist(const CStdString& strArtist, const CStdString& strMusicBrainzArtistID); bool GetArtist(int idArtist, CArtist& artist, bool fetchAll = true); - int UpdateArtist(int idArtist, const CArtist& artist); + int UpdateArtist(int idArtist, + const CStdString& strArtist, const CStdString& strMusicBrainzArtistID, + const CStdString& strBorn, const CStdString& strFormed, + const CStdString& strGenres, const CStdString& strMoods, + const CStdString& strStyles, const CStdString& strInstruments, + const CStdString& strBiography, const CStdString& strDied, + const CStdString& strDisbanded, const CStdString& strYearsActive, + const CStdString& strImage, const CStdString& strFanart); bool DeleteArtist(int idArtist); bool HasArtistBeenScraped(int idArtist); bool ClearArtistLastScrapedTime(int idArtist); + int AddArtistDiscography(int idArtist, const CStdString& strAlbum, const CStdString& strYear); + bool DeleteArtistDiscography(int idArtist); CStdString GetArtistById(int id); int GetArtistByName(const CStdString& strArtist); @@ -272,15 +283,6 @@ public: int GetGenreByName(const CStdString& strGenre); ///////////////////////////////////////////////// - // ArtistInfo - ///////////////////////////////////////////////// - /*! \brief Check if an artist entity has additional metadata (scraped) - \param idArtist the id of the Artist to check - \return true or false - whether the artist has metadata - */ - int SetArtistInfo(int idArtist, const CArtist& artist); - - ///////////////////////////////////////////////// // Link tables ///////////////////////////////////////////////// bool AddAlbumArtist(int idArtist, int idAlbum, std::string joinPhrase, bool featured, int iOrder); diff --git a/xbmc/music/infoscanner/MusicInfoScanner.cpp b/xbmc/music/infoscanner/MusicInfoScanner.cpp index a982751bf9..71b0cc4193 100644 --- a/xbmc/music/infoscanner/MusicInfoScanner.cpp +++ b/xbmc/music/infoscanner/MusicInfoScanner.cpp @@ -771,16 +771,14 @@ int CMusicInfoScanner::RetrieveMusicInfo(const CStdString& strDirectory, CFileIt if (artistDownloadStatus == INFO_ADDED || artistDownloadStatus == INFO_HAVE_ALREADY) { CArtist &downloadedArtist = artistInfo.GetArtist(); - downloadedArtist.idArtist = m_musicDatabase.AddArtist(downloadedArtist.strArtist, - downloadedArtist.strMusicBrainzArtistID); - m_musicDatabase.SetArtistInfo(downloadedArtist.idArtist, - downloadedArtist); - + artistTmp.MergeScrapedArtist(downloadedArtist); + artistTmp.idArtist = m_musicDatabase.AddArtist(artistTmp.strArtist, artistTmp.strMusicBrainzArtistID); + m_musicDatabase.UpdateArtist(artistTmp); URIUtils::GetParentPath(album->strPath, downloadedArtist.strPath); map<string, string> artwork = GetArtistArtwork(downloadedArtist); // check thumb stuff - m_musicDatabase.SetArtForItem(downloadedArtist.idArtist, "artist", artwork); - m_artistCache.insert(make_pair(*artistCredit, downloadedArtist)); + m_musicDatabase.SetArtForItem(artistTmp.idArtist, "artist", artwork); + m_artistCache.insert(make_pair(*artistCredit, artistTmp)); } else if (artistDownloadStatus == INFO_CANCELLED) break; @@ -842,15 +840,15 @@ int CMusicInfoScanner::RetrieveMusicInfo(const CStdString& strDirectory, CFileIt if (artistDownloadStatus == INFO_ADDED || artistDownloadStatus == INFO_HAVE_ALREADY) { CArtist &downloadedArtist = artistInfo.GetArtist(); - downloadedArtist.idArtist = m_musicDatabase.AddArtist(downloadedArtist.strArtist, - downloadedArtist.strMusicBrainzArtistID); - m_musicDatabase.SetArtistInfo(downloadedArtist.idArtist, - downloadedArtist); + artistTmp.MergeScrapedArtist(downloadedArtist); + artistTmp.idArtist = m_musicDatabase.AddArtist(artistTmp.strArtist, + artistTmp.strMusicBrainzArtistID); + m_musicDatabase.UpdateArtist(artistTmp); // check thumb stuff - URIUtils::GetParentPath(album->strPath, downloadedArtist.strPath); - map<string, string> artwork = GetArtistArtwork(downloadedArtist); - m_musicDatabase.SetArtForItem(downloadedArtist.idArtist, "artist", artwork); - m_artistCache.insert(make_pair(*artistCredit, downloadedArtist)); + URIUtils::GetParentPath(album->strPath, artistTmp.strPath); + map<string, string> artwork = GetArtistArtwork(artistTmp); + m_musicDatabase.SetArtForItem(artistTmp.idArtist, "artist", artwork); + m_artistCache.insert(make_pair(*artistCredit, artistTmp)); } else if (artistDownloadStatus == INFO_CANCELLED) break; @@ -1075,13 +1073,13 @@ loop: } else if (artistDownloadStatus == INFO_ADDED) { + artist.MergeScrapedArtist(artistInfo.GetArtist()); m_musicDatabase.Open(); - m_musicDatabase.SetArtistInfo(params.GetArtistId(), artistInfo.GetArtist()); - m_musicDatabase.GetArtistPath(params.GetArtistId(), artist.strPath); - map<string, string> artwork = GetArtistArtwork(artist); - m_musicDatabase.SetArtForItem(params.GetArtistId(), "artist", artwork); - artistInfo.SetLoaded(); + m_musicDatabase.UpdateArtist(artist); + m_musicDatabase.GetArtistPath(artist.idArtist, artist.strPath); + m_musicDatabase.SetArtForItem(artist.idArtist, "artist", GetArtistArtwork(artist)); m_musicDatabase.Close(); + artistInfo.SetLoaded(); } return artistDownloadStatus; } |