Skip to content

Instantly share code, notes, and snippets.

Created January 19, 2014 14:31
Show Gist options
  • Save anonymous/8505697 to your computer and use it in GitHub Desktop.
Save anonymous/8505697 to your computer and use it in GitHub Desktop.
diff --git a/src/libpiano/piano.h b/src/libpiano/piano.h
index ce66171..faa1e47 100644
--- a/src/libpiano/piano.h
+++ b/src/libpiano/piano.h
@@ -169,6 +169,7 @@ typedef enum {
PIANO_REQUEST_GET_STATION_INFO = 20,
PIANO_REQUEST_DELETE_FEEDBACK = 21,
PIANO_REQUEST_DELETE_SEED = 22,
+ PIANO_REQUEST_GET_AD_METADATA = 23,
} PianoRequestType_t;
typedef struct PianoRequest {
@@ -244,6 +245,10 @@ typedef struct {
PianoStation_t *station;
} PianoRequestDataDeleteSeed_t;
+typedef struct {
+ char *token;
+} PianoRequestDataGetAdMetadata_t;
+
/* pandora error code offset */
#define PIANO_RET_OFFSET 1024
typedef enum {
diff --git a/src/libpiano/request.c b/src/libpiano/request.c
index 82bf350..8a424df 100644
--- a/src/libpiano/request.c
+++ b/src/libpiano/request.c
@@ -80,6 +80,10 @@ PianoReturn_t PianoRequest (PianoHandle_t *ph, PianoRequest_t *req,
json_object_new_string ("5"));
json_object_object_add (j, "includeUrls",
json_object_new_boolean (true));
+ json_object_object_add (j, "returnDeviceType",
+ json_object_new_boolean (true));
+ json_object_object_add (j, "returnUpdatePromptVersions",
+ json_object_new_boolean (true));
snprintf (req->urlPath, sizeof (req->urlPath),
PIANO_RPC_PATH "method=auth.partnerLogin");
break;
@@ -133,6 +137,22 @@ PianoReturn_t PianoRequest (PianoHandle_t *ph, PianoRequest_t *req,
json_object_object_add (j, "stationToken",
json_object_new_string (reqData->station->id));
+ json_object_object_add (j, "includeTrackLength",
+ json_object_new_boolean (true));
+ json_object_object_add (j, "includeAudioToken",
+ json_object_new_boolean (true));
+ json_object_object_add (j, "xplatformAdCapable",
+ json_object_new_boolean (true));
+ json_object_object_add (j, "includeAudioReceiptUrl",
+ json_object_new_boolean (true));
+ json_object_object_add (j, "includeCompetitiveSepIndicator",
+ json_object_new_boolean (true));
+ json_object_object_add (j, "includeCompletePlaylist",
+ json_object_new_boolean (true));
+ json_object_object_add (j, "includeTrackOptions",
+ json_object_new_boolean (true));
+ json_object_object_add (j, "audioAdPodCapable",
+ json_object_new_boolean (true));
method = "station.getPlaylist";
break;
@@ -398,6 +418,27 @@ PianoReturn_t PianoRequest (PianoHandle_t *ph, PianoRequest_t *req,
break;
}
+ case PIANO_REQUEST_GET_AD_METADATA: {
+ PianoRequestDataGetAdMetadata_t *reqData = req->data;
+
+ assert (reqData != NULL);
+ assert (reqData->token != NULL);
+
+ json_object_object_add (j, "adToken",
+ json_object_new_string (reqData->token));
+ json_object_object_add (j, "returnAdTrackingTokens",
+ json_object_new_boolean (true));
+ json_object_object_add (j, "supportAudioAds",
+ json_object_new_boolean (true));
+ json_object_object_add (j, "includeBannerAd",
+ json_object_new_boolean (true));
+ json_object_object_add (j, "includeListeningHours",
+ json_object_new_boolean (true));
+
+ method = "ad.getAdMetadata";
+ break;
+ }
+
/* "high-level" wrapper */
case PIANO_REQUEST_RATE_SONG: {
/* love/ban song */
diff --git a/src/libpiano/response.c b/src/libpiano/response.c
index 41bbfd3..c63d185 100644
--- a/src/libpiano/response.c
+++ b/src/libpiano/response.c
@@ -26,6 +26,7 @@ THE SOFTWARE.
#define _DARWIN_C_SOURCE /* strdup() on OS X */
#endif
+#include <stdio.h>
#include <json.h>
#include <string.h>
#include <assert.h>
@@ -232,6 +233,12 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) {
return PIANO_RET_OUT_OF_MEMORY;
}
+ if (json_object_object_get (s, "adToken") != NULL) {
+ printf ("song has ad token: %s\n", json_object_get_string (json_object_object_get (s, "adToken")));
+ free (song);
+ continue;
+ }
+
if (json_object_object_get (s, "artistName") == NULL) {
free (song);
continue;
@@ -591,6 +598,11 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) {
}
break;
}
+
+ case PIANO_REQUEST_GET_AD_METADATA: {
+ printf ("ad.getAdMetadata returned: %s\n", req->responseData);
+ break;
+ }
}
cleanup:
diff --git a/src/libwaitress/waitress.c b/src/libwaitress/waitress.c
index af3cc1a..1e6247d 100644
--- a/src/libwaitress/waitress.c
+++ b/src/libwaitress/waitress.c
@@ -923,7 +923,7 @@ static WaitressReturn_t WaitressSendRequest (WaitressHandle_t *waith) {
WRITE_RET (buf, strlen (buf));
snprintf (buf, WAITRESS_BUFFER_SIZE,
- "Host: %s\r\nUser-Agent: " PACKAGE "\r\nConnection: Close\r\n",
+ "Host: %s\r\nUser-Agent: Pandora/1.2.3 Android/4.4.1 12345\r\nConnection: Close\r\n",
waith->url.host);
WRITE_RET (buf, strlen (buf));
diff --git a/src/main.c b/src/main.c
index 4cca654..4850a87 100644
--- a/src/main.c
+++ b/src/main.c
@@ -224,6 +224,7 @@ static void BarMainGetPlaylist (BarApp_t *app) {
PianoReturn_t pRet;
WaitressReturn_t wRet;
PianoRequestDataGetPlaylist_t reqData;
+
reqData.station = app->curStation;
reqData.quality = app->settings.audioQuality;
@@ -246,6 +247,18 @@ static void BarMainGetPlaylist (BarApp_t *app) {
/* start new player thread
*/
static void BarMainStartPlayback (BarApp_t *app, pthread_t *playerThread) {
+ PianoReturn_t pRet;
+ WaitressReturn_t wRet;
+ PianoRequestDataGetAdMetadata_t adReqData;
+ char token[100];
+ snprintf (token, sizeof (token)-1, "%s-pod:1/1/0", app->curStation->id);
+
+ adReqData.token = strdup (token);
+ BarUiMsg (&app->settings, MSG_INFO, "Fetching ads with token %s... ", token);
+ BarUiPianoCall (app, PIANO_REQUEST_GET_AD_METADATA,
+ &adReqData, &pRet, &wRet);
+ free (adReqData.token);
+
BarUiPrintSong (&app->settings, app->playlist, app->curStation->isQuickMix ?
PianoFindStationById (app->ph.stations,
app->playlist->stationId) : NULL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment