summaryrefslogtreecommitdiff
path: root/libpiano
diff options
context:
space:
mode:
Diffstat (limited to 'libpiano')
-rw-r--r--libpiano/src/main.c32
-rw-r--r--libpiano/src/piano.h2
-rw-r--r--libpiano/src/xml.c22
-rw-r--r--libpiano/src/xml.h1
4 files changed, 57 insertions, 0 deletions
diff --git a/libpiano/src/main.c b/libpiano/src/main.c
index b3bcab8..844d757 100644
--- a/libpiano/src/main.c
+++ b/libpiano/src/main.c
@@ -763,6 +763,38 @@ PianoReturn_t PianoExplain (PianoHandle_t *ph, const PianoSong_t *song,
return ret;
}
+/* Get seed suggestions by music id
+ * @param piano handle
+ * @param music id
+ * @param max results
+ * @param result buffer
+ */
+PianoReturn_t PianoSeedSuggestions (PianoHandle_t *ph, const char *musicId,
+ unsigned int max, PianoSearchResult_t *searchResult) {
+ char xmlSendBuf[PIANO_SEND_BUFFER_SIZE], retStr[PIANO_RECV_BUFFER];
+ PianoReturn_t ret;
+
+ snprintf (xmlSendBuf, sizeof (xmlSendBuf), "<?xml version=\"1.0\"?>"
+ "<methodCall><methodName>music.getSeedSuggestions</methodName>"
+ "<params><param><value><int>%li</int></value></param>"
+ "<param><value><string>%s</string></value></param>"
+ "<param><value><string>%s</string></value></param>"
+ "<param><value><int>%u</int></value></param>"
+ "</params></methodCall>", time (NULL), ph->user.authToken,
+ musicId, max);
+
+ snprintf (ph->waith.path, sizeof (ph->waith.path), PIANO_RPC_PATH
+ "rid=%s&lid=%s&method=method=getSeedSuggestions&arg1=%s&arg2=%u",
+ ph->routeId, ph->user.listenerId, musicId, max);
+
+ if ((ret = PianoHttpPost (&ph->waith, xmlSendBuf, retStr,
+ sizeof (retStr))) == PIANO_RET_OK) {
+ ret = PianoXmlParseSeedSuggestions (retStr, searchResult);
+ }
+
+ return ret;
+}
+
/* convert return value to human-readable string
* @param enum
* @return error string
diff --git a/libpiano/src/piano.h b/libpiano/src/piano.h
index 2910e99..7d7554a 100644
--- a/libpiano/src/piano.h
+++ b/libpiano/src/piano.h
@@ -136,5 +136,7 @@ PianoReturn_t PianoGetGenreStations (PianoHandle_t *);
PianoReturn_t PianoTransformShared (PianoHandle_t *, PianoStation_t *);
PianoReturn_t PianoExplain (PianoHandle_t *, const PianoSong_t *, char **);
const char *PianoErrorToStr (PianoReturn_t);
+PianoReturn_t PianoSeedSuggestions (PianoHandle_t *, const char *,
+ unsigned int, PianoSearchResult_t *);
#endif /* _PIANO_H */
diff --git a/libpiano/src/xml.c b/libpiano/src/xml.c
index 2cc519f..b02df5d 100644
--- a/libpiano/src/xml.c
+++ b/libpiano/src/xml.c
@@ -647,6 +647,28 @@ PianoReturn_t PianoXmlParseSearch (char *xml,
return PIANO_RET_OK;
}
+/* FIXME: copy&waste (PianoXmlParseSearch)
+ */
+PianoReturn_t PianoXmlParseSeedSuggestions (char *xml,
+ PianoSearchResult_t *searchResult) {
+ ezxml_t xmlDoc, dataNode;
+ PianoReturn_t ret;
+
+ if ((ret = PianoXmlInitDoc (xml, &xmlDoc)) != PIANO_RET_OK) {
+ return ret;
+ }
+
+ dataNode = ezxml_get (xmlDoc, "params", 0, "param", 0, "value", -1);
+ /* we need a "clean" search result (with null pointers) */
+ memset (searchResult, 0, sizeof (*searchResult));
+ /* reuse seach result parser; structure is nearly the same */
+ PianoXmlParseSearchCb ("artists", dataNode, searchResult);
+
+ ezxml_free (xmlDoc);
+
+ return PIANO_RET_OK;
+}
+
/* encode reserved xml chars
* TODO: remove and use ezxml_ampencode
* @param encode this
diff --git a/libpiano/src/xml.h b/libpiano/src/xml.h
index 525c8f3..5c0e5c2 100644
--- a/libpiano/src/xml.h
+++ b/libpiano/src/xml.h
@@ -40,6 +40,7 @@ PianoReturn_t PianoXmlParseGenreExplorer (PianoHandle_t *ph,
const char *xmlContent);
PianoReturn_t PianoXmlParseTranformStation (const char *searchXml);
PianoReturn_t PianoXmlParseNarrative (const char *xml, char **retNarrative);
+PianoReturn_t PianoXmlParseSeedSuggestions (char *, PianoSearchResult_t *);
char *PianoXmlEncodeString (const char *s);