summaryrefslogtreecommitdiff
path: root/libpiano/src
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@lavabit.com>2009-01-27 16:47:05 +0100
committerLars-Dominik Braun <PromyLOPh@lavabit.com>2009-01-27 16:47:05 +0100
commit560f4599c5238b98515bd0358d0333e4dc190b80 (patch)
tree5654cfd3e52a418411b38cea392525e4215f93db /libpiano/src
parentd52ebc8e84b24ccc9b8537c37bfa20ff810e01ca (diff)
downloadpianobar-windows-560f4599c5238b98515bd0358d0333e4dc190b80.tar.gz
pianobar-windows-560f4599c5238b98515bd0358d0333e4dc190b80.tar.bz2
pianobar-windows-560f4599c5238b98515bd0358d0333e4dc190b80.zip
piano: mp3 support
Breaks api
Diffstat (limited to 'libpiano/src')
-rw-r--r--libpiano/src/main.c34
-rw-r--r--libpiano/src/piano.h8
-rw-r--r--libpiano/src/xml.c8
3 files changed, 43 insertions, 7 deletions
diff --git a/libpiano/src/main.c b/libpiano/src/main.c
index 219aad5..6cb6bad 100644
--- a/libpiano/src/main.c
+++ b/libpiano/src/main.c
@@ -44,6 +44,7 @@ THE SOFTWARE.
/* prototypes */
PianoReturn_t PianoAddFeedback (PianoHandle_t *, const char *, const char *,
const char *, const char *, const char *, PianoSongRating_t);
+const char *PianoAudioFormatToString (PianoAudioFormat_t);
/* more "secure" free version; only use this function, not original free ()
* in this library
@@ -271,7 +272,8 @@ PianoReturn_t PianoGetStations (PianoHandle_t *ph) {
* @param piano handle
* @param station id
*/
-PianoReturn_t PianoGetPlaylist (PianoHandle_t *ph, const char *stationId) {
+PianoReturn_t PianoGetPlaylist (PianoHandle_t *ph, const char *stationId,
+ PianoAudioFormat_t format) {
char xmlSendBuf[PIANO_SEND_BUFFER_SIZE], url[PIANO_URL_BUFFER_SIZE];
char *requestStr, *retStr;
PianoReturn_t ret;
@@ -286,14 +288,15 @@ PianoReturn_t PianoGetPlaylist (PianoHandle_t *ph, const char *stationId) {
"<param><value><string>0</string></value></param>"
"<param><value><string></string></value></param>"
"<param><value><string></string></value></param>"
- "<param><value><string>aacplus</string></value></param>"
+ "<param><value><string>%s</string></value></param>"
"</params></methodCall>", time (NULL), ph->user.authToken,
- stationId);
+ stationId, PianoAudioFormatToString (format));
requestStr = PianoEncryptString (xmlSendBuf);
snprintf (url, sizeof (url), PIANO_RPC_URL
"rid=%s&lid=%s&method=getFragment&arg1=%s&arg2=0"
- "&arg3=0&arg4=&arg5=&arg6=aacplus", ph->routeId,
- ph->user.listenerId, stationId);
+ "&arg3=0&arg4=&arg5=&arg6=%s", ph->routeId,
+ ph->user.listenerId, stationId,
+ PianoAudioFormatToString (format));
if ((ret = PianoHttpPost (ph->curlHandle, url, requestStr, &retStr)) ==
PIANO_RET_OK) {
@@ -882,3 +885,24 @@ const char *PianoErrorToStr (PianoReturn_t ret) {
break;
}
}
+
+/* convert audio format id to string that can be used in xml requests
+ * @param format id
+ * @return constant string
+ */
+const char *PianoAudioFormatToString (PianoAudioFormat_t format) {
+ switch (format) {
+ case PIANO_AF_AACPLUS:
+ return "aacplus";
+ break;
+
+ case PIANO_AF_MP3:
+ return "mp3";
+ break;
+
+ default:
+ return NULL;
+ break;
+ }
+}
+
diff --git a/libpiano/src/piano.h b/libpiano/src/piano.h
index f540d8b..cc92c38 100644
--- a/libpiano/src/piano.h
+++ b/libpiano/src/piano.h
@@ -73,6 +73,10 @@ typedef struct PianoStation PianoStation_t;
enum PianoSongRating {PIANO_RATE_BAN, PIANO_RATE_LOVE, PIANO_RATE_NONE};
typedef enum PianoSongRating PianoSongRating_t;
+/* UNKNOWN should be 0, because memset sets audio format to 0 */
+typedef enum {PIANO_AF_UNKNOWN = 0, PIANO_AF_AACPLUS, PIANO_AF_MP3}
+ PianoAudioFormat_t;
+
struct PianoSong {
char *artist;
//char **genre;
@@ -105,6 +109,7 @@ struct PianoSong {
char *focusTraitId;
char *identity;
//int score; /* only used for search results */
+ PianoAudioFormat_t audioFormat;
struct PianoSong *next;
};
@@ -165,7 +170,8 @@ PianoReturn_t PianoConnect (PianoHandle_t *ph, const char *user,
const char *password, char secureLogin);
PianoReturn_t PianoGetStations (PianoHandle_t *ph);
-PianoReturn_t PianoGetPlaylist (PianoHandle_t *ph, const char *stationId);
+PianoReturn_t PianoGetPlaylist (PianoHandle_t *ph, const char *stationId,
+ PianoAudioFormat_t);
PianoReturn_t PianoRateTrack (PianoHandle_t *ph, PianoSong_t *song,
PianoSongRating_t rating);
diff --git a/libpiano/src/xml.c b/libpiano/src/xml.c
index 71b6bb1..847bc49 100644
--- a/libpiano/src/xml.c
+++ b/libpiano/src/xml.c
@@ -290,7 +290,13 @@ void PianoXmlParsePlaylistCb (const char *key, const xmlNode *value,
song->album = strdup (valueStr);
} else if (strcmp ("fileGain", key) == 0) {
song->fileGain = atof (valueStr);
- }
+ } else if (strcmp ("audioEncoding", key) == 0) {
+ if (strcmp (valueStr, "aacplus") == 0) {
+ song->audioFormat = PIANO_AF_AACPLUS;
+ } else if (strcmp (valueStr, "mp3") == 0) {
+ song->audioFormat = PIANO_AF_MP3;
+ }
+ }
}
/* parses userinfos sent by pandora as login response