Skip to content

Commit

Permalink
jsonrpc: make sure to return artist details even if there's no entry …
Browse files Browse the repository at this point in the history
…for that artist in the artistinfo table
  • Loading branch information
Montellese committed May 19, 2012
1 parent 261fc93 commit 2e75130
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
13 changes: 5 additions & 8 deletions xbmc/interfaces/json-rpc/AudioLibrary.cpp
Expand Up @@ -72,19 +72,16 @@ JSONRPC_STATUS CAudioLibrary::GetArtistDetails(const CStdString &method, ITransp
if (!musicdatabase.Open())
return InternalError;

CArtist artist;
if (!musicdatabase.GetArtistInfo(artistID, artist))
CFileItemList items;
CStdString where;
where.Format("idArtist = %d", artistID);
if (!musicdatabase.GetArtistsByWhere("musicdb://2/", where, items) || items.Size() != 1)
{
musicdatabase.Close();
return InvalidParams;
}

CFileItemPtr m_artistItem(new CFileItem(artist));
m_artistItem->GetMusicInfoTag()->SetArtist(m_artistItem->GetLabel());
m_artistItem->GetMusicInfoTag()->SetDatabaseId(artistID);
CMusicDatabase::SetPropertiesFromArtist(*m_artistItem, artist);
m_artistItem->SetCachedArtistThumb();
HandleFileItem("artistid", false, "artistdetails", m_artistItem, parameterObject, parameterObject["properties"], result, false);
HandleFileItem("artistid", false, "artistdetails", items[0], parameterObject, parameterObject["properties"], result, false);

musicdatabase.Close();
return OK;
Expand Down
30 changes: 25 additions & 5 deletions xbmc/music/MusicDatabase.cpp
Expand Up @@ -2767,12 +2767,9 @@ bool CMusicDatabase::GetArtistsNav(const CStdString& strBaseDir, CFileItemList&
if (NULL == m_pDS.get()) return false;
try
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;

unsigned int time = XbmcThreads::SystemClockMillis();

CStdString strSQL = "select * from artist where (idArtist IN ";
CStdString strSQL = "(idArtist IN ";

if (idGenre==-1)
{
Expand Down Expand Up @@ -2865,6 +2862,30 @@ bool CMusicDatabase::GetArtistsNav(const CStdString& strBaseDir, CFileItemList&
strSQL+=PrepareSQL(" and artist.idArtist<>%i", idVariousArtists);
}

bool result = GetArtistsByWhere(strBaseDir, strSQL, items);
CLog::Log(LOGDEBUG,"Time to retrieve artists from dataset = %i", XbmcThreads::SystemClockMillis() - time);

return result;
}
catch (...)
{
m_pDS->close();
CLog::Log(LOGERROR, "%s failed", __FUNCTION__);
}
return false;
}

bool CMusicDatabase::GetArtistsByWhere(const CStdString& strBaseDir, const CStdString &where, CFileItemList& items)
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;

try
{
CStdString strSQL = "select * from artist";
if (!where.empty())
strSQL += " WHERE " + where;

// run query
CLog::Log(LOGDEBUG, "%s query: %s", __FUNCTION__, strSQL.c_str());
if (!m_pDS->query(strSQL.c_str())) return false;
Expand Down Expand Up @@ -2900,7 +2921,6 @@ bool CMusicDatabase::GetArtistsNav(const CStdString& strBaseDir, CFileItemList&

m_pDS->next();
}
CLog::Log(LOGDEBUG,"Time to retrieve artists from dataset = %i", XbmcThreads::SystemClockMillis() - time);

// cleanup
m_pDS->close();
Expand Down
1 change: 1 addition & 0 deletions xbmc/music/MusicDatabase.h
Expand Up @@ -165,6 +165,7 @@ class CMusicDatabase : public CDatabase
bool GetSongsByYear(const CStdString& baseDir, CFileItemList& items, int year);
bool GetSongsByWhere(const CStdString &baseDir, const CStdString &whereClause, CFileItemList& items);
bool GetAlbumsByWhere(const CStdString &baseDir, const CStdString &where, const CStdString &order, CFileItemList &items);
bool GetArtistsByWhere(const CStdString& strBaseDir, const CStdString &where, CFileItemList& items);
bool GetRandomSong(CFileItem* item, int& idSong, const CStdString& strWhere);
int GetKaraokeSongsCount();
int GetSongsCount(const CStdString& strWhere = "");
Expand Down

0 comments on commit 2e75130

Please sign in to comment.