Permalink
Browse files

[jsonrpc] Make all artist data available via the JSON-RPC API, throug…

…h AudioLibrary.GetArtists with new params: songid, albumid.
  • Loading branch information...
1 parent a50e2e9 commit f28cf13e69e786184f58158bf3dbf9af698d359f @night199uk committed Jul 4, 2012
@@ -135,7 +135,7 @@ void CGUIDialogSmartPlaylistRule::OnBrowse()
else if (m_rule.m_field == FieldArtist || m_rule.m_field == FieldAlbumArtist)
{
if (m_type.Equals("songs") || m_type.Equals("mixed") || m_type.Equals("albums"))
- database.GetArtistsNav("musicdb://5/",items,-1,m_rule.m_field == FieldAlbumArtist);
+ database.GetArtistsNav("musicdb://5/",items,-1,-1,-1,m_rule.m_field == FieldAlbumArtist);
if (m_type.Equals("musicvideos") || m_type.Equals("mixed"))
{
CFileItemList items2;
@@ -56,7 +56,7 @@ bool CDirectoryNodeArtist::GetContent(CFileItemList& items) const
CQueryParams params;
CollectQueryParams(params);
- bool bSuccess = musicdatabase.GetArtistsNav(BuildPath(), items, params.GetGenreId(), !g_guiSettings.GetBool("musiclibrary.showcompilationartists"));
+ bool bSuccess = musicdatabase.GetArtistsNav(BuildPath(), items, params.GetGenreId(), -1, -1, !g_guiSettings.GetBool("musiclibrary.showcompilationartists"));
musicdatabase.Close();
@@ -45,6 +45,8 @@ JSONRPC_STATUS CAudioLibrary::GetArtists(const CStdString &method, ITransportLay
return InternalError;
int genreID = (int)parameterObject["genreid"].asInteger();
+ int songID = (int)parameterObject["songid"].asInteger();
+ int albumID = (int)parameterObject["albumid"].asInteger();
// Add "artist" to "properties" array by default
CVariant param = parameterObject;
@@ -57,7 +59,7 @@ JSONRPC_STATUS CAudioLibrary::GetArtists(const CStdString &method, ITransportLay
albumArtistsOnly = parameterObject["albumartistsonly"].asBoolean();
CFileItemList items;
- if (!musicdatabase.GetArtistsNav("musicdb://2/", items, genreID, albumArtistsOnly))
+ if (!musicdatabase.GetArtistsNav("musicdb://2/", items, genreID, songID, albumID, albumArtistsOnly))
return InternalError;
HandleFileItemList("artistid", false, "artists", items, param, result);
@@ -1453,7 +1453,9 @@ namespace JSONRPC
"\"permission\": \"ReadData\","
"\"params\": ["
"{ \"name\": \"albumartistsonly\", \"$ref\": \"Optional.Boolean\", \"description\": \"Whether or not to include artists only appearing in compilations. If the parameter is not passed or is passed as null the GUI setting will be used\" },"
- "{ \"name\": \"genreid\", \"$ref\": \"Library.Id\" },"
+ "{ \"name\": \"genreid\", \"$ref\": \"Library.Id\", \"description\" : \"If specified, just artists that performed in the genre specified by ID\" },"
+ "{ \"name\": \"songid\", \"$ref\": \"Library.Id\", \"description\" : \"If specified, just artists that performed on the song with ID\" },"
+ "{ \"name\": \"albumid\", \"$ref\": \"Library.Id\", \"description\" : \"If specified, just artists that performed on the album with ID\" },"
"{ \"name\": \"properties\", \"$ref\": \"Audio.Fields.Artist\" },"
"{ \"name\": \"limits\", \"$ref\": \"List.Limits\" },"
"{ \"name\": \"sort\", \"$ref\": \"List.Sort\" }"
@@ -588,7 +588,9 @@
"permission": "ReadData",
"params": [
{ "name": "albumartistsonly", "$ref": "Optional.Boolean", "description": "Whether or not to include artists only appearing in compilations. If the parameter is not passed or is passed as null the GUI setting will be used" },
- { "name": "genreid", "$ref": "Library.Id" },
+ { "name": "genreid", "$ref": "Library.Id", "description" : "If specified, just artists that performed in the genre specified by ID" },
+ { "name": "songid", "$ref": "Library.Id", "description" : "If specified, just artists that performed on the song with ID" },
+ { "name": "albumid", "$ref": "Library.Id", "description" : "If specified, just artists that performed on the album with ID" },
{ "name": "properties", "$ref": "Audio.Fields.Artist" },
{ "name": "limits", "$ref": "List.Limits" },
{ "name": "sort", "$ref": "List.Sort" }
@@ -2760,7 +2760,7 @@ bool CMusicDatabase::GetAlbumsByYear(const CStdString& strBaseDir, CFileItemList
return GetAlbumsByWhere(strBaseDir, where, "", items);
}
-bool CMusicDatabase::GetArtistsNav(const CStdString& strBaseDir, CFileItemList& items, int idGenre, bool albumArtistsOnly)
+bool CMusicDatabase::GetArtistsNav(const CStdString& strBaseDir, CFileItemList& items, int idGenre, int idAlbum, int idSong , bool albumArtistsOnly)
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
@@ -2770,40 +2770,57 @@ bool CMusicDatabase::GetArtistsNav(const CStdString& strBaseDir, CFileItemList&
CStdString strSQL = "(idArtist IN ";
- if (idGenre==-1)
+ if (idAlbum > 0)
@jmarshallnz

jmarshallnz Jul 4, 2012

Can the idAlbum be 0 and still be valid?

@night199uk

night199uk via email Jul 5, 2012

Owner
{
- if (!albumArtistsOnly) // show all artists in this case (ie those linked to a song)
- strSQL += "("
- "SELECT song_artist.idArtist FROM song_artist" // All artists linked to a song
- ") "
- "or idArtist IN ";
-
- // and always show any artists linked to an album (may be different from above due to album artist tag)
- strSQL += "("
- "SELECT album_artist.idArtist from album_artist "; // All artists linked to an album
- if (albumArtistsOnly)
- strSQL += "WHERE album_artist.boolFeatured = 0"; // then exclude those that have no extra artists
- strSQL += ")"
- ") ";
+ strSQL+=PrepareSQL("("
+ "SELECT album_artist.idArtist from album_artist "
+ " WHERE album_artist.idAlbum = %i"
+ ")"
+ ")", idAlbum);
+
}
- else
+ else if (idSong > 0)
+ {
+ strSQL += PrepareSQL("("
+ "SELECT song_artist.idArtist from song_artist "
+ " WHERE song_artist.idSong = %i"
+ ")"
+ ")", idSong);
+ }
+ else if (idGenre > 0)
{ // same statements as above, but limit to the specified genre
// in this case we show the whole lot always - there is no limitation to just album artists
if (!albumArtistsOnly) // show all artists in this case (ie those linked to a song)
strSQL+=PrepareSQL("("
- "SELECT song_artist.idArtist FROM song_artist " // All artists linked to extra genres
- "JOIN song_genre ON song_artist.idSong = song_genre.idSong "
- "WHERE song_genre.idGenre=%i"
- ") "
- "or idArtist IN "
- , idGenre);
+ "SELECT song_artist.idArtist FROM song_artist " // All artists linked to extra genres
+ "JOIN song_genre ON song_artist.idSong = song_genre.idSong "
+ "WHERE song_genre.idGenre=%i"
+ ") "
+ "or idArtist IN "
+ , idGenre);
// and add any artists linked to an album (may be different from above due to album artist tag)
strSQL += PrepareSQL("("
- "SELECT album_artist.idArtist FROM album_artist " // All album artists linked to extra genres
- "JOIN album_genre ON album_artist.idAlbum = album_genre.idAlbum "
- "WHERE album_genre.idGenre=%i"
- ") "
- ")", idGenre);
+ "SELECT album_artist.idArtist FROM album_artist " // All album artists linked to extra genres
+ "JOIN album_genre ON album_artist.idAlbum = album_genre.idAlbum "
+ "WHERE album_genre.idGenre=%i"
+ ") "
+ ")", idGenre);
+ }
+ else
+ {
+ if (!albumArtistsOnly) // show all artists in this case (ie those linked to a song)
+ strSQL += "("
+ "SELECT song_artist.idArtist FROM song_artist" // All artists linked to a song
+ ") "
+ "or idArtist IN ";
+
+ // and always show any artists linked to an album (may be different from above due to album artist tag)
+ strSQL += "("
+ "SELECT album_artist.idArtist from album_artist "; // All artists linked to an album
+ if (albumArtistsOnly)
+ strSQL += "WHERE album_artist.boolFeatured = 0"; // then exclude those that have no extra artists
+ strSQL += ")"
+ ") ";
}
// remove the null string
@@ -171,7 +171,7 @@ class CMusicDatabase : public CDatabase
bool GetPathHash(const CStdString &path, CStdString &hash);
bool GetGenresNav(const CStdString& strBaseDir, CFileItemList& items);
bool GetYearsNav(const CStdString& strBaseDir, CFileItemList& items);
- bool GetArtistsNav(const CStdString& strBaseDir, CFileItemList& items, int idGenre, bool albumArtistsOnly);
+ bool GetArtistsNav(const CStdString& strBaseDir, CFileItemList& items, int idGenre, int idAlbum, int idSong, bool albumArtistsOnly);
bool GetAlbumsNav(const CStdString& strBaseDir, CFileItemList& items, int idGenre, int idArtist, int start, int end, const SortDescription &sortDescription = SortDescription());
bool GetAlbumsByYear(const CStdString &strBaseDir, CFileItemList& items, int year);
bool GetSongsNav(const CStdString& strBaseDir, CFileItemList& items, int idGenre, int idArtist,int idAlbum, const SortDescription &sortDescription = SortDescription());
@@ -293,7 +293,7 @@ void CMusicInfoScanner::FetchArtistInfo(const CStdString& strDirectory,
if (strDirectory.IsEmpty())
{
m_musicDatabase.Open();
- m_musicDatabase.GetArtistsNav("musicdb://2/",items,-1,false);
+ m_musicDatabase.GetArtistsNav("musicdb://2/",items,-1,-1,-1,false);
m_musicDatabase.Close();
}
else

0 comments on commit f28cf13

Please sign in to comment.