Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #190 from Montellese/jsonrpc_recentlyadded_audio

jsonrpc: added GetRecentlyAddedAlbums and GetRecentlyAddedSongs to AudioLibrary
  • Loading branch information...
commit 64ce09649e9cb656f9c746fa1802da063002203c 2 parents 5db9543 + 482cb54
@Montellese Montellese authored
View
62 xbmc/interfaces/json-rpc/AudioLibrary.cpp
@@ -123,10 +123,8 @@ JSON_STATUS CAudioLibrary::GetAlbumDetails(const CStdString &method, ITransportL
CStdString path;
musicdatabase.GetAlbumPath(albumID, path);
- CFileItemPtr m_albumItem( new CFileItem(path, album) );
- m_albumItem->SetLabel(album.strAlbum);
- CMusicDatabase::SetPropertiesFromAlbum(*m_albumItem, album);
- m_albumItem->SetMusicThumb();
+ CFileItemPtr m_albumItem;
+ FillAlbumItem(album, path, m_albumItem);
HandleFileItem("albumid", false, "albumdetails", m_albumItem, parameterObject, parameterObject["fields"], result, false);
musicdatabase.Close();
@@ -172,6 +170,56 @@ JSON_STATUS CAudioLibrary::GetSongDetails(const CStdString &method, ITransportLa
return OK;
}
+JSON_STATUS CAudioLibrary::GetRecentlyAddedAlbums(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ CMusicDatabase musicdatabase;
+ if (!musicdatabase.Open())
+ return InternalError;
+
+ int amount = (int)parameterObject["albums"].asInteger();
+ if (amount < 0)
+ amount = 0;
+
+ VECALBUMS albums;
+ if (musicdatabase.GetRecentlyAddedAlbums(albums, (unsigned int)amount))
+ {
+ CFileItemList items;
+
+ for (unsigned int index = 0; index < albums.size(); index++)
+ {
+ CStdString path;
+ path.Format("musicdb://6/%i/", albums[index].idAlbum);
+
+ CFileItemPtr item;
+ FillAlbumItem(albums[index], path, item);
+ items.Add(item);
+ }
+
+ HandleFileItemList("albumid", false, "albums", items, parameterObject, result);
+ }
+
+ musicdatabase.Close();
+ return OK;
+}
+
+JSON_STATUS CAudioLibrary::GetRecentlyAddedSongs(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ CMusicDatabase musicdatabase;
+ if (!musicdatabase.Open())
+ return InternalError;
+
+ int amount = (int)parameterObject["albums"].asInteger();
+ if (amount < 0)
+ amount = 0;
+
+ CFileItemList items;
+ if (musicdatabase.GetRecentlyAddedAlbumSongs("musicdb://", items, (unsigned int)amount))
+ HandleFileItemList("songid", true, "songs", items, parameterObject, result);
+
+ musicdatabase.Close();
+ return OK;
+}
+
JSON_STATUS CAudioLibrary::GetGenres(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
{
CMusicDatabase musicdatabase;
@@ -255,3 +303,9 @@ bool CAudioLibrary::FillFileItemList(const CVariant &parameterObject, CFileItemL
return success;
}
+
+void CAudioLibrary::FillAlbumItem(const CAlbum &album, const CStdString &path, CFileItemPtr &item)
+{
+ item = CFileItemPtr(new CFileItem(path, album));
+ item->SetMusicThumb();
+}
View
5 xbmc/interfaces/json-rpc/AudioLibrary.h
@@ -35,10 +35,15 @@ namespace JSONRPC
static JSON_STATUS GetAlbumDetails(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSON_STATUS GetSongs(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSON_STATUS GetSongDetails(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSON_STATUS GetRecentlyAddedAlbums(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSON_STATUS GetRecentlyAddedSongs(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSON_STATUS GetGenres(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSON_STATUS ScanForContent(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static bool FillFileItem(const CStdString &strFilename, CFileItem &item);
static bool FillFileItemList(const CVariant &parameterObject, CFileItemList &list);
+
+ private:
+ static void FillAlbumItem(const CAlbum &album, const CStdString &path, CFileItemPtr &item);
};
}
View
2  xbmc/interfaces/json-rpc/JSONServiceDescription.cpp
@@ -194,6 +194,8 @@ JsonRpcMethodMap CJSONServiceDescription::m_methodMaps[] = {
{ "AudioLibrary.GetAlbumDetails", CAudioLibrary::GetAlbumDetails },
{ "AudioLibrary.GetSongs", CAudioLibrary::GetSongs },
{ "AudioLibrary.GetSongDetails", CAudioLibrary::GetSongDetails },
+ { "AudioLibrary.GetRecentlyAddedAlbums", CAudioLibrary::GetRecentlyAddedAlbums },
+ { "AudioLibrary.GetRecentlyAddedSongs", CAudioLibrary::GetRecentlyAddedSongs },
{ "AudioLibrary.GetGenres", CAudioLibrary::GetGenres },
{ "AudioLibrary.ScanForContent", CAudioLibrary::ScanForContent },
View
47 xbmc/interfaces/json-rpc/ServiceDescription.h
@@ -499,6 +499,11 @@ namespace JSONRPC
"\"type\": \"string\","
"\"enum\": [ \"video\", \"music\", \"pictures\", \"files\", \"programs\" ]"
"}",
+ "\"List.Amount\": {"
+ "\"type\": \"integer\","
+ "\"default\": -1,"
+ "\"minimum\": 0"
+ "}",
"\"List.Limits\": {"
"\"type\": \"object\","
"\"properties\": {"
@@ -1666,6 +1671,48 @@ namespace JSONRPC
"}"
"}"
"}",
+ "\"AudioLibrary.GetRecentlyAddedAlbums\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Retrieve recently added albums\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ReadData\","
+ "\"params\": ["
+ "{ \"name\": \"albums\", \"$ref\": \"List.Amount\" },"
+ "{ \"name\": \"fields\", \"$ref\": \"Audio.Fields.Album\" },"
+ "{ \"name\": \"limits\", \"$ref\": \"List.Limits\" },"
+ "{ \"name\": \"sort\", \"$ref\": \"List.Sort\" }"
+ "],"
+ "\"returns\": {"
+ "\"type\": \"object\","
+ "\"properties\": {"
+ "\"limits\": { \"$ref\": \"List.LimitsReturned\", \"required\": true },"
+ "\"albums\": { \"type\": \"array\","
+ "\"items\": { \"$ref\": \"Audio.Details.Album\" }"
+ "}"
+ "}"
+ "}"
+ "}",
+ "\"AudioLibrary.GetRecentlyAddedSongs\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Retrieve recently added songs\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ReadData\","
+ "\"params\": ["
+ "{ \"name\": \"albums\", \"$ref\": \"List.Amount\", \"description\": \"The amount of recently added albums from which to return the songs\" },"
+ "{ \"name\": \"fields\", \"$ref\": \"Audio.Fields.Song\" },"
+ "{ \"name\": \"limits\", \"$ref\": \"List.Limits\" },"
+ "{ \"name\": \"sort\", \"$ref\": \"List.Sort\" }"
+ "],"
+ "\"returns\": {"
+ "\"type\": \"object\","
+ "\"properties\": {"
+ "\"limits\": { \"$ref\": \"List.LimitsReturned\", \"required\": true },"
+ "\"songs\": { \"type\": \"array\","
+ "\"items\": { \"$ref\": \"Audio.Details.Song\" }"
+ "}"
+ "}"
+ "}"
+ "}",
"\"AudioLibrary.GetGenres\": {"
"\"type\": \"method\","
"\"description\": \"Retrieve all genres\","
View
42 xbmc/interfaces/json-rpc/methods.json
@@ -914,6 +914,48 @@
}
}
},
+ "AudioLibrary.GetRecentlyAddedAlbums": {
+ "type": "method",
+ "description": "Retrieve recently added albums",
+ "transport": "Response",
+ "permission": "ReadData",
+ "params": [
+ { "name": "albums", "$ref": "List.Amount" },
+ { "name": "fields", "$ref": "Audio.Fields.Album" },
+ { "name": "limits", "$ref": "List.Limits" },
+ { "name": "sort", "$ref": "List.Sort" }
+ ],
+ "returns": {
+ "type": "object",
+ "properties": {
+ "limits": { "$ref": "List.LimitsReturned", "required": true },
+ "albums": { "type": "array",
+ "items": { "$ref": "Audio.Details.Album" }
+ }
+ }
+ }
+ },
+ "AudioLibrary.GetRecentlyAddedSongs": {
+ "type": "method",
+ "description": "Retrieve recently added songs",
+ "transport": "Response",
+ "permission": "ReadData",
+ "params": [
+ { "name": "albums", "$ref": "List.Amount", "description": "The amount of recently added albums from which to return the songs" },
+ { "name": "fields", "$ref": "Audio.Fields.Song" },
+ { "name": "limits", "$ref": "List.Limits" },
+ { "name": "sort", "$ref": "List.Sort" }
+ ],
+ "returns": {
+ "type": "object",
+ "properties": {
+ "limits": { "$ref": "List.LimitsReturned", "required": true },
+ "songs": { "type": "array",
+ "items": { "$ref": "Audio.Details.Song" }
+ }
+ }
+ }
+ },
"AudioLibrary.GetGenres": {
"type": "method",
"description": "Retrieve all genres",
View
5 xbmc/interfaces/json-rpc/types.json
@@ -471,6 +471,11 @@
"type": "string",
"enum": [ "video", "music", "pictures", "files", "programs" ]
},
+ "List.Amount": {
+ "type": "integer",
+ "default": -1,
+ "minimum": 0
+ },
"List.Limits": {
"type": "object",
"properties": {
Please sign in to comment.
Something went wrong with that request. Please try again.