aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormontellese <montellese@xbmc.org>2012-07-16 14:36:41 +0200
committermontellese <montellese@xbmc.org>2012-08-06 13:23:46 +0200
commit1662ad56ff817853dd36531978283638fea913de (patch)
tree5d37058afebf7314026238ff5f24513a0634bbb7
parentea2ec8c4724a68bf7413e9438783f1a6bd630093 (diff)
jsonrpc: add "filter" parameter to AudioLibrary.GetArtists
-rw-r--r--xbmc/dialogs/GUIDialogSmartPlaylistRule.cpp2
-rw-r--r--xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeArtist.cpp2
-rw-r--r--xbmc/interfaces/json-rpc/AudioLibrary.cpp17
-rw-r--r--xbmc/interfaces/json-rpc/ServiceDescription.h12
-rw-r--r--xbmc/interfaces/json-rpc/methods.json12
-rw-r--r--xbmc/music/MusicDatabase.cpp72
-rw-r--r--xbmc/music/MusicDatabase.h2
-rw-r--r--xbmc/music/infoscanner/MusicInfoScanner.cpp2
8 files changed, 88 insertions, 33 deletions
diff --git a/xbmc/dialogs/GUIDialogSmartPlaylistRule.cpp b/xbmc/dialogs/GUIDialogSmartPlaylistRule.cpp
index 0d76025e68..1f88afcef0 100644
--- a/xbmc/dialogs/GUIDialogSmartPlaylistRule.cpp
+++ b/xbmc/dialogs/GUIDialogSmartPlaylistRule.cpp
@@ -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://2/",items,-1,m_rule.m_field == FieldAlbumArtist);
+ database.GetArtistsNav("musicdb://2/", items, m_rule.m_field == FieldAlbumArtist, -1);
if (m_type.Equals("musicvideos") || m_type.Equals("mixed"))
{
CFileItemList items2;
diff --git a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeArtist.cpp b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeArtist.cpp
index 4f0f11bce8..b5cfc53c1b 100644
--- a/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeArtist.cpp
+++ b/xbmc/filesystem/MusicDatabaseDirectory/DirectoryNodeArtist.cpp
@@ -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, !g_guiSettings.GetBool("musiclibrary.showcompilationartists"), params.GetGenreId());
musicdatabase.Close();
diff --git a/xbmc/interfaces/json-rpc/AudioLibrary.cpp b/xbmc/interfaces/json-rpc/AudioLibrary.cpp
index caee3705db..06bd60d505 100644
--- a/xbmc/interfaces/json-rpc/AudioLibrary.cpp
+++ b/xbmc/interfaces/json-rpc/AudioLibrary.cpp
@@ -44,7 +44,20 @@ JSONRPC_STATUS CAudioLibrary::GetArtists(const CStdString &method, ITransportLay
if (!musicdatabase.Open())
return InternalError;
- int genreID = (int)parameterObject["genreid"].asInteger();
+ CMusicDbUrl musicUrl;
+ musicUrl.FromString("musicdb://2/");
+ int genreID = -1, albumID = -1, songID = -1;
+ const CVariant &filter = parameterObject["filter"];
+ if (filter.isMember("genreid"))
+ genreID = (int)filter["genreid"].asInteger();
+ if (filter.isMember("genre"))
+ musicUrl.AddOption("genre", filter["genre"].asString());
+ if (filter.isMember("albumid"))
+ albumID = (int)filter["albumid"].asInteger();
+ if (filter.isMember("album"))
+ musicUrl.AddOption("album", filter["album"].asString());
+ if (filter.isMember("songid"))
+ songID = (int)filter["songid"].asInteger();
// Add "artist" to "properties" array by default
CVariant param = parameterObject;
@@ -57,7 +70,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(musicUrl.ToString(), items, albumArtistsOnly, genreID, albumID, songID))
return InternalError;
HandleFileItemList("artistid", false, "artists", items, param, result);
diff --git a/xbmc/interfaces/json-rpc/ServiceDescription.h b/xbmc/interfaces/json-rpc/ServiceDescription.h
index 39d0454c2c..b5a5f17706 100644
--- a/xbmc/interfaces/json-rpc/ServiceDescription.h
+++ b/xbmc/interfaces/json-rpc/ServiceDescription.h
@@ -1455,10 +1455,18 @@ 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\": \"properties\", \"$ref\": \"Audio.Fields.Artist\" },"
"{ \"name\": \"limits\", \"$ref\": \"List.Limits\" },"
- "{ \"name\": \"sort\", \"$ref\": \"List.Sort\" }"
+ "{ \"name\": \"sort\", \"$ref\": \"List.Sort\" },"
+ "{ \"name\": \"filter\","
+ "\"type\": ["
+ "{ \"type\": \"object\", \"properties\": { \"genreid\": { \"$ref\": \"Library.Id\", \"required\": true } }, \"additionalProperties\": false },"
+ "{ \"type\": \"object\", \"properties\": { \"genre\": { \"type\": \"string\", \"minLength\": 1, \"required\": true } }, \"additionalProperties\": false },"
+ "{ \"type\": \"object\", \"properties\": { \"albumid\": { \"$ref\": \"Library.Id\", \"required\": true } }, \"additionalProperties\": false },"
+ "{ \"type\": \"object\", \"properties\": { \"album\": { \"type\": \"string\", \"minLength\": 1, \"required\": true } }, \"additionalProperties\": false },"
+ "{ \"type\": \"object\", \"properties\": { \"songid\": { \"$ref\": \"Library.Id\", \"required\": true } }, \"additionalProperties\": false }"
+ "]"
+ "}"
"],"
"\"returns\": {"
"\"type\": \"object\","
diff --git a/xbmc/interfaces/json-rpc/methods.json b/xbmc/interfaces/json-rpc/methods.json
index 9e90918de2..1047349ecd 100644
--- a/xbmc/interfaces/json-rpc/methods.json
+++ b/xbmc/interfaces/json-rpc/methods.json
@@ -588,10 +588,18 @@
"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": "properties", "$ref": "Audio.Fields.Artist" },
{ "name": "limits", "$ref": "List.Limits" },
- { "name": "sort", "$ref": "List.Sort" }
+ { "name": "sort", "$ref": "List.Sort" },
+ { "name": "filter",
+ "type": [
+ { "type": "object", "properties": { "genreid": { "$ref": "Library.Id", "required": true } }, "additionalProperties": false },
+ { "type": "object", "properties": { "genre": { "type": "string", "minLength": 1, "required": true } }, "additionalProperties": false },
+ { "type": "object", "properties": { "albumid": { "$ref": "Library.Id", "required": true } }, "additionalProperties": false },
+ { "type": "object", "properties": { "album": { "type": "string", "minLength": 1, "required": true } }, "additionalProperties": false },
+ { "type": "object", "properties": { "songid": { "$ref": "Library.Id", "required": true } }, "additionalProperties": false }
+ ]
+ }
],
"returns": {
"type": "object",
diff --git a/xbmc/music/MusicDatabase.cpp b/xbmc/music/MusicDatabase.cpp
index c8c9df320c..e58e2bd211 100644
--- a/xbmc/music/MusicDatabase.cpp
+++ b/xbmc/music/MusicDatabase.cpp
@@ -2747,7 +2747,7 @@ bool CMusicDatabase::GetAlbumsByYear(const CStdString& strBaseDir, CFileItemList
return GetAlbumsByWhere(musicUrl.ToString(), filter, items);
}
-bool CMusicDatabase::GetArtistsNav(const CStdString& strBaseDir, CFileItemList& items, int idGenre, bool albumArtistsOnly)
+bool CMusicDatabase::GetArtistsNav(const CStdString& strBaseDir, CFileItemList& items, bool albumArtistsOnly /* = false */, int idGenre /* = -1 */, int idAlbum /* = -1 */, int idSong /* = -1 */)
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
@@ -2761,6 +2761,10 @@ bool CMusicDatabase::GetArtistsNav(const CStdString& strBaseDir, CFileItemList&
if (idGenre > 0)
musicUrl.AddOption("genreid", idGenre);
+ else if (idAlbum > 0)
+ musicUrl.AddOption("albumid", idAlbum);
+ else if (idSong > 0)
+ musicUrl.AddOption("songid", idSong);
musicUrl.AddOption("albumartistsonly", albumArtistsOnly);
@@ -5032,12 +5036,32 @@ bool CMusicDatabase::GetFilter(const CMusicDbUrl &musicUrl, Filter &filter)
if (type == "artists")
{
- int idGenre = -1;
+ int idGenre = -1, idAlbum = -1, idSong = -1;
bool albumArtistsOnly = false;
option = options.find("genreid");
if (option != options.end())
idGenre = (int)option->second.asInteger();
+ else
+ {
+ option = options.find("genre");
+ if (option != options.end())
+ idGenre = GetGenreByName(option->second.asString());
+ }
+
+ option = options.find("albumid");
+ if (option != options.end())
+ idAlbum = (int)option->second.asInteger();
+ else
+ {
+ option = options.find("album");
+ if (option != options.end())
+ idAlbum = GetAlbumByName(option->second.asString());
+ }
+
+ option = options.find("songid");
+ if (option != options.end())
+ idSong = (int)option->second.asInteger();
option = options.find("albumartistsonly");
if (option != options.end())
@@ -5045,36 +5069,38 @@ bool CMusicDatabase::GetFilter(const CMusicDbUrl &musicUrl, Filter &filter)
CStdString strSQL = "(idArtist IN ";
- if (idGenre <= 0)
+ if (idAlbum > 0)
+ strSQL += PrepareSQL("(SELECT album_artist.idArtist FROM album_artist WHERE album_artist.idAlbum = %i)", idAlbum);
+ 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 below, 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);
+ // 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);
+ }
+ else
{
if (!albumArtistsOnly) // show all artists in this case (ie those linked to a song)
- strSQL += "(SELECT song_artist.idArtist FROM song_artist) "
- "or idArtist IN ";
+ strSQL += "(SELECT song_artist.idArtist FROM song_artist)"
+ " 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
+ 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 += ")"
- ") ";
- }
- else
- { // 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);
- // 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);
+ strSQL += ")";
}
// remove the null string
- strSQL += " and strArtist != ''";
+ strSQL += ") and strArtist != ''";
// and the various artist entry if applicable
if (!albumArtistsOnly)
diff --git a/xbmc/music/MusicDatabase.h b/xbmc/music/MusicDatabase.h
index d678d68d5f..84a768ff39 100644
--- a/xbmc/music/MusicDatabase.h
+++ b/xbmc/music/MusicDatabase.h
@@ -152,7 +152,7 @@ public:
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, bool albumArtistsOnly = false, int idGenre = -1, int idAlbum = -1, int idSong = -1);
bool GetAlbumsNav(const CStdString& strBaseDir, CFileItemList& items, int idGenre = -1, int idArtist = -1, 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());
diff --git a/xbmc/music/infoscanner/MusicInfoScanner.cpp b/xbmc/music/infoscanner/MusicInfoScanner.cpp
index 7d16f05fdb..1f6dcc01b2 100644
--- a/xbmc/music/infoscanner/MusicInfoScanner.cpp
+++ b/xbmc/music/infoscanner/MusicInfoScanner.cpp
@@ -289,7 +289,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, false, -1);
m_musicDatabase.Close();
}
else