summaryrefslogtreecommitdiff
path: root/libpiano/src
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@gmail.com>2008-07-19 12:11:12 +0200
committerLars-Dominik Braun <PromyLOPh@gmail.com>2008-07-19 12:11:12 +0200
commit00cfc5e626abc51df4b728a064697616cf7aae02 (patch)
tree1ca714e58e7bc8b479b7c08e163c1e26917492c4 /libpiano/src
parent98813251e60234aac43ef41090980f2771ce2360 (diff)
downloadpianobar-00cfc5e626abc51df4b728a064697616cf7aae02.tar.gz
pianobar-00cfc5e626abc51df4b728a064697616cf7aae02.tar.bz2
pianobar-00cfc5e626abc51df4b728a064697616cf7aae02.zip
Rate "shared stations" correctly by transforming them to private stations
Diffstat (limited to 'libpiano/src')
-rw-r--r--libpiano/src/main.c41
-rw-r--r--libpiano/src/piano.h4
-rw-r--r--libpiano/src/xml.c20
-rw-r--r--libpiano/src/xml.h1
4 files changed, 65 insertions, 1 deletions
diff --git a/libpiano/src/main.c b/libpiano/src/main.c
index d5fa0e7..a4beefd 100644
--- a/libpiano/src/main.c
+++ b/libpiano/src/main.c
@@ -734,3 +734,44 @@ PianoReturn_t PianoGetGenreStations (PianoHandle_t *ph) {
return ret;
}
+
+/* make shared stations private, needed to rate songs played on shared
+ * stations
+ * @param piano handle
+ * @param station to transform
+ * @return _OK or error
+ */
+PianoReturn_t PianoTransformShared (PianoHandle_t *ph,
+ PianoStation_t *station) {
+ char xmlSendBuf[PIANO_SEND_BUFFER_SIZE], url[PIANO_URL_BUFFER_SIZE];
+ char *requestStr, *retStr;
+ PianoReturn_t ret;
+
+ snprintf (xmlSendBuf, sizeof (xmlSendBuf), "<?xml version=\"1.0\"?>"
+ "<methodCall><methodName>station.transformShared</methodName>"
+ "<params><param><value><int>%li</int></value></param>"
+ "<param><value><string>%s</string></value></param>"
+ "<param><value><string>%s</string></value></param>"
+ "</params></methodCall>", time (NULL), ph->user.authToken,
+ station->id);
+ requestStr = PianoEncryptString (xmlSendBuf);
+
+ snprintf (url, sizeof (url), PIANO_RPC_URL "rid=%s&lid=%s&"
+ "method=transformShared&arg1=%s", ph->routeId, ph->user.listenerId,
+ station->id);
+
+ if ((ret = PianoHttpPost (ph->curlHandle, url, requestStr, &retStr)) ==
+ PIANO_RET_OK) {
+ ret = PianoXmlParseTranformStation (retStr);
+ /* though this call returns a bunch of "new" data only this one is
+ * changed and important (at the moment) */
+ if (ret == PIANO_RET_OK) {
+ station->isCreator = 1;
+ }
+ PianoFree (retStr, 0);
+ }
+
+ PianoFree (requestStr, 0);
+
+ return ret;
+}
diff --git a/libpiano/src/piano.h b/libpiano/src/piano.h
index 07b9791..172c13d 100644
--- a/libpiano/src/piano.h
+++ b/libpiano/src/piano.h
@@ -53,7 +53,7 @@ struct PianoUserInfo {
typedef struct PianoUserInfo PianoUserInfo_t;
struct PianoStation {
- //char isCreator;
+ char isCreator;
/* disabled: originalStationId */
//char **genre;
//unsigned int originalCreatorId;
@@ -183,5 +183,7 @@ PianoReturn_t PianoSetQuickmix (PianoHandle_t *ph);
PianoStation_t *PianoFindStationById (PianoStation_t *stations,
char *searchStation);
PianoReturn_t PianoGetGenreStations (PianoHandle_t *ph);
+PianoReturn_t PianoTransformShared (PianoHandle_t *ph,
+ PianoStation_t *station);
#endif /* _PIANO_H */
diff --git a/libpiano/src/xml.c b/libpiano/src/xml.c
index 91bb120..d0faca6 100644
--- a/libpiano/src/xml.c
+++ b/libpiano/src/xml.c
@@ -212,6 +212,8 @@ void PianoXmlParseStationsCb (char *key, xmlNode *value, void *data) {
station->id = strdup (valueStr);
} else if (strcmp ("isQuickMix", key) == 0) {
station->isQuickMix = (strcmp (valueStr, "1") == 0);
+ } else if (strcmp ("isCreator", key) == 0) {
+ station->isCreator = (strcmp (valueStr, "1") == 0);
}
}
@@ -659,3 +661,21 @@ PianoReturn_t PianoXmlParseGenreExplorer (PianoHandle_t *ph,
return PIANO_RET_OK;
}
+
+/* dummy function, only checks for errors
+ * @param xml doc
+ * @return _OK or error
+ */
+PianoReturn_t PianoXmlParseTranformStation (char *searchXml) {
+ xmlNode *docRoot;
+ xmlDocPtr doc;
+ PianoReturn_t ret;
+
+ if ((ret = PianoXmlInitDoc (searchXml, &doc, &docRoot)) != PIANO_RET_OK) {
+ return ret;
+ }
+
+ xmlFreeDoc (doc);
+
+ return PIANO_RET_OK;
+}
diff --git a/libpiano/src/xml.h b/libpiano/src/xml.h
index 8a4e613..95d9d93 100644
--- a/libpiano/src/xml.h
+++ b/libpiano/src/xml.h
@@ -36,6 +36,7 @@ PianoReturn_t PianoXmlParseAddSeed (PianoHandle_t *ph, char *xml,
PianoStation_t *station);
PianoReturn_t PianoXmlParseGenreExplorer (PianoHandle_t *ph,
char *xmlContent);
+PianoReturn_t PianoXmlParseTranformStation (char *searchXml);
char *PianoXmlEncodeString (const char *s);