138
138
static WaitressReturn_t BarPianoHttpRequest (WaitressHandle_t *waith,
139
139
PianoRequest_t *req) {
140
waith->extraHeaders = "Content-Type: text/xml\r\n";
140
waith->extraHeaders = "Content-Type: text/plain\r\n";
141
141
waith->postData = req->postData;
142
142
waith->method = WAITRESS_METHOD_POST;
143
143
waith->url.path = req->urlPath;
185
185
*pRet = PianoResponse (&app->ph, &req);
186
186
if (*pRet != PIANO_RET_CONTINUE_REQUEST) {
187
187
/* checking for request type avoids infinite loops */
188
if (*pRet == PIANO_RET_AUTH_TOKEN_INVALID &&
188
if (*pRet == PIANO_RET_P_INVALID_AUTH_TOKEN &&
189
189
type != PIANO_REQUEST_LOGIN) {
190
190
/* reauthenticate */
191
191
PianoReturn_t authpRet;
331
331
/* let user pick one station
332
332
* @param app handle
333
* @param stations that should be listed
333
334
* @param prompt string
334
335
* @param called if input was not a number
336
* @param auto-select if only one station remains after filtering
335
337
* @return pointer to selected station or NULL
337
339
PianoStation_t *BarUiSelectStation (BarApp_t *app, PianoStation_t *stations,
338
const char *prompt, BarUiSelectStationCallback_t callback) {
340
const char *prompt, BarUiSelectStationCallback_t callback,
339
342
PianoStation_t **sortedStations = NULL, *retStation = NULL;
340
size_t stationCount, i;
343
size_t stationCount, i, lastDisplayed, displayCount;
343
346
if (stations == NULL) {
361
365
currStation->isQuickMix ? 'Q' : ' ',
362
366
!currStation->isCreator ? 'S' : ' ',
363
367
currStation->name);
367
373
BarUiMsg (&app->settings, MSG_QUESTION, prompt);
368
if (BarReadlineStr (buf, sizeof (buf), &app->input,
369
BAR_RL_DEFAULT) == 0) {
370
free (sortedStations);
374
if (isnumeric (buf)) {
375
unsigned long selected = strtoul (buf, NULL, 0);
376
if (selected < stationCount) {
377
retStation = sortedStations[selected];
381
/* hand over buffer to external function if it was not a station number */
382
if (retStation == NULL && callback != NULL) {
374
if (autoselect && displayCount == 1 && stationCount != 1) {
375
/* auto-select last remaining station */
376
BarUiMsg (&app->settings, MSG_NONE, "%i\n", lastDisplayed);
377
retStation = sortedStations[lastDisplayed];
379
if (BarReadlineStr (buf, sizeof (buf), &app->input,
380
BAR_RL_DEFAULT) == 0) {
384
if (isnumeric (buf)) {
385
unsigned long selected = strtoul (buf, NULL, 0);
386
if (selected < stationCount) {
387
retStation = sortedStations[selected];
391
/* hand over buffer to external function if it was not a station number */
392
if (retStation == NULL && callback != NULL) {
385
396
} while (retStation == NULL);
473
484
* @return musicId or NULL on abort/error
475
486
char *BarUiSelectMusicId (BarApp_t *app, PianoStation_t *station,
476
PianoSong_t *similarSong, const char *msg) {
477
488
char *musicId = NULL;
478
489
char lineBuf[100], selectBuf[2];
479
490
PianoSearchResult_t searchResult;
483
494
BarUiMsg (&app->settings, MSG_QUESTION, msg);
484
495
if (BarReadlineStr (lineBuf, sizeof (lineBuf), &app->input,
485
496
BAR_RL_DEFAULT) > 0) {
486
if (strcmp ("?", lineBuf) == 0 && station != NULL &&
487
similarSong != NULL) {
489
WaitressReturn_t wRet;
490
PianoRequestDataGetSeedSuggestions_t reqData;
492
reqData.station = station;
493
reqData.musicId = similarSong->musicId;
496
BarUiMsg (&app->settings, MSG_INFO, "Receiving suggestions... ");
497
if (!BarUiPianoCall (app, PIANO_REQUEST_GET_SEED_SUGGESTIONS,
498
&reqData, &pRet, &wRet)) {
501
memcpy (&searchResult, &reqData.searchResult, sizeof (searchResult));
504
WaitressReturn_t wRet;
505
PianoRequestDataSearch_t reqData;
507
reqData.searchStr = lineBuf;
509
BarUiMsg (&app->settings, MSG_INFO, "Searching... ");
510
if (!BarUiPianoCall (app, PIANO_REQUEST_SEARCH, &reqData, &pRet,
514
memcpy (&searchResult, &reqData.searchResult, sizeof (searchResult));
498
WaitressReturn_t wRet;
499
PianoRequestDataSearch_t reqData;
501
reqData.searchStr = lineBuf;
503
BarUiMsg (&app->settings, MSG_INFO, "Searching... ");
504
if (!BarUiPianoCall (app, PIANO_REQUEST_SEARCH, &reqData, &pRet,
508
memcpy (&searchResult, &reqData.searchResult, sizeof (searchResult));
516
510
BarUiMsg (&app->settings, MSG_NONE, "\r");
517
511
if (searchResult.songs != NULL &&
518
512
searchResult.artists != NULL) {
709
703
BarUiCustomFormat (outstr, sizeof (outstr), settings->npStationFormat,
711
705
BarUiAppendNewline (outstr, sizeof (outstr));
712
BarUiMsg (settings, MSG_PLAYING, outstr);
706
BarUiMsg (settings, MSG_PLAYING, "%s", outstr);
715
709
/* Print song infos (artist, title, album, loved)
729
723
BarUiCustomFormat (outstr, sizeof (outstr), settings->npSongFormat,
730
724
"talr@su", vals);
731
725
BarUiAppendNewline (outstr, sizeof (outstr));
732
BarUiMsg (settings, MSG_PLAYING, outstr);
726
BarUiMsg (settings, MSG_PLAYING, "%s", outstr);
735
729
/* Print list of songs
756
750
BarUiCustomFormat (outstr, sizeof (outstr), settings->listSongFormat,
758
752
BarUiAppendNewline (outstr, sizeof (outstr));
759
BarUiMsg (settings, MSG_LIST, outstr);
753
BarUiMsg (settings, MSG_LIST, "%s", outstr);
762
756
song = song->next;