From bf6191b00825c4631312cf2446fd7b181abb7e1f Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Mon, 6 May 2013 17:27:27 +0200 Subject: Permit multiple HTTP errors in a row MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1) Make sure that multiple bad playlists in a row don’t result in a temporary ban 2) Ignore songs skipped because the playlist timed out after pausing for too long --- contrib/pianobar.1 | 4 ++++ src/main.c | 11 +++++++++-- src/main.h | 1 + src/player.c | 9 ++++----- src/player.h | 2 +- src/settings.c | 3 +++ src/settings.h | 2 +- 7 files changed, 23 insertions(+), 9 deletions(-) diff --git a/contrib/pianobar.1 b/contrib/pianobar.1 index d5f1ad7..5efaca1 100644 --- a/contrib/pianobar.1 +++ b/contrib/pianobar.1 @@ -294,6 +294,10 @@ Keep a history of the last n songs (5, by default). You can rate these songs. .B love_icon = <3 Icon for loved songs. +.TP +.B max_player_errors = 5 +Amount of song download errors in a row after pianobar stops playback. + .TP .B partner_password = AC7IBG09A3DTSYM4R41UJWL07VLN8JI7 diff --git a/src/main.c b/src/main.c index b16eb97..c8bf5c6 100644 --- a/src/main.c +++ b/src/main.c @@ -300,8 +300,15 @@ static void BarMainPlayerCleanup (BarApp_t *app, pthread_t *playerThread) { pthread_cond_destroy (&app->player.pauseCond); pthread_mutex_destroy (&app->player.pauseMutex); - /* don't continue playback if thread reports error */ - if (threadRet != (void *) PLAYER_RET_OK) { + if (threadRet == (void *) PLAYER_RET_OK) { + app->playerErrors = 0; + } else if (threadRet == (void *) PLAYER_RET_SOFTFAIL) { + ++app->playerErrors; + if (app->playerErrors >= app->settings.maxPlayerErrors) { + /* don't continue playback if thread reports too many error */ + app->curStation = NULL; + } + } else { app->curStation = NULL; } diff --git a/src/main.h b/src/main.h index 14d1368..04f5203 100644 --- a/src/main.h +++ b/src/main.h @@ -42,6 +42,7 @@ typedef struct { PianoStation_t *curStation; char doQuit; BarReadlineFds_t input; + unsigned int playerErrors; } BarApp_t; #endif /* _MAIN_H */ diff --git a/src/player.c b/src/player.c index 16c94dc..939b326 100644 --- a/src/player.c +++ b/src/player.c @@ -489,7 +489,7 @@ void *BarPlayerThread (void *data) { default: BarUiMsg (player->settings, MSG_ERR, "Unsupported audio format!\n"); - ret = (void *) PLAYER_RET_ERR; + ret = (void *) PLAYER_RET_HARDFAIL; goto cleanup; break; } @@ -528,15 +528,14 @@ void *BarPlayerThread (void *data) { } if (player->aoError) { - ret = (void *) PLAYER_RET_ERR; + ret = (void *) PLAYER_RET_HARDFAIL; } /* Pandora sends broken audio url’s sometimes (“bad request”). ignore them. */ - if (wRet != WAITRESS_RET_OK && wRet != WAITRESS_RET_CB_ABORT && - wRet != WAITRESS_RET_BAD_REQUEST) { + if (wRet != WAITRESS_RET_OK && wRet != WAITRESS_RET_CB_ABORT) { BarUiMsg (player->settings, MSG_ERR, "Cannot access audio file: %s\n", WaitressErrorToStr (wRet)); - ret = (void *) PLAYER_RET_ERR; + ret = (void *) PLAYER_RET_SOFTFAIL; } cleanup: diff --git a/src/player.h b/src/player.h index d0eac22..d107e41 100644 --- a/src/player.h +++ b/src/player.h @@ -107,7 +107,7 @@ struct audioPlayer { WaitressHandle_t waith; }; -enum {PLAYER_RET_OK = 0, PLAYER_RET_ERR = 1}; +enum {PLAYER_RET_OK = 0, PLAYER_RET_HARDFAIL = 1, PLAYER_RET_SOFTFAIL = 2}; void *BarPlayerThread (void *data); unsigned int BarPlayerCalcScale (float); diff --git a/src/settings.c b/src/settings.c index e801de8..d90a7d7 100644 --- a/src/settings.c +++ b/src/settings.c @@ -125,6 +125,7 @@ void BarSettingsRead (BarSettings_t *settings) { settings->autoselect = true; settings->history = 5; settings->volume = 0; + settings->maxPlayerErrors = 5; settings->sortOrder = BAR_SORT_NAME_AZ; settings->loveIcon = strdup (" <3"); settings->banIcon = strdup (" eventCmd = strdup (val); } else if (streq ("history", key)) { settings->history = atoi (val); + } else if (streq ("max_player_errors", key)) { + settings->maxPlayerErrors = atoi (val); } else if (streq ("sort", key)) { size_t i; static const char *mapping[] = {"name_az", diff --git a/src/settings.h b/src/settings.h index 392ea58..819f8cb 100644 --- a/src/settings.h +++ b/src/settings.h @@ -84,7 +84,7 @@ typedef struct { typedef struct { bool autoselect; - unsigned int history; + unsigned int history, maxPlayerErrors; int volume; BarStationSorting_t sortOrder; PianoAudioQuality_t audioQuality; -- cgit v1.2.3