thedmd/pianobar-windows

Support for event_command

nlowe opened this issue · 4 comments

On Linux and macOS I use event_command to scrobble to Last.FM. However, on the windows fork, the implementation is commented out:

pianobar-windows/src/ui.c

Lines 721 to 828 in 191128a

/* Excute external event handler
* @param settings containing the cmdline
* @param event type
* @param current station
* @param current song
* @param piano error-code (PIANO_RET_OK if not applicable)
*/
void BarUiStartEventCmd (const BarSettings_t *settings, const char *type,
const PianoStation_t *curStation, const PianoSong_t *curSong,
const player2_t * const player, PianoStation_t *stations,
PianoReturn_t pRet) {
//pid_t chld;
//int pipeFd[2];
//if (settings->eventCmd == NULL) {
/* nothing to do... */
return;
//}
//if (pipe (pipeFd) == -1) {
// BarUiMsg (settings, MSG_ERR, "Cannot create eventcmd pipe. (%s)\n", strerror (errno));
// return;
//}
//chld = fork ();
//if (chld == 0) {
// /* child */
// close (pipeFd[1]);
// dup2 (pipeFd[0], fileno (stdin));
// execl (settings->eventCmd, settings->eventCmd, type, (char *) NULL);
// BarUiMsg (settings, MSG_ERR, "Cannot start eventcmd. (%s)\n", strerror (errno));
// close (pipeFd[0]);
// exit (1);
//} else if (chld == -1) {
// BarUiMsg (settings, MSG_ERR, "Cannot fork eventcmd. (%s)\n", strerror (errno));
//} else {
// /* parent */
// int status;
// PianoStation_t *songStation = NULL;
// FILE *pipeWriteFd;
// close (pipeFd[0]);
// pipeWriteFd = fdopen (pipeFd[1], "w");
// if (curSong != NULL && stations != NULL && curStation != NULL &&
// curStation->isQuickMix) {
// songStation = PianoFindStationById (stations, curSong->stationId);
// }
// fprintf (pipeWriteFd,
// "artist=%s\n"
// "title=%s\n"
// "album=%s\n"
// "coverArt=%s\n"
// "stationName=%s\n"
// "songStationName=%s\n"
// "pRet=%i\n"
// "pRetStr=%s\n"
// "wRet=%i\n"
// "wRetStr=%s\n"
// "songDuration=%u\n"
// "songPlayed=%u\n"
// "rating=%i\n"
// "detailUrl=%s\n",
// curSong == NULL ? "" : curSong->artist,
// curSong == NULL ? "" : curSong->title,
// curSong == NULL ? "" : curSong->album,
// curSong == NULL ? "" : curSong->coverArt,
// curStation == NULL ? "" : curStation->name,
// songStation == NULL ? "" : songStation->name,
// pRet,
// PianoErrorToStr (pRet),
// wRet,
// curl_easy_strerror (wRet),
// player->songDuration,
// player->songPlayed,
// curSong == NULL ? PIANO_RATE_NONE : curSong->rating,
// curSong == NULL ? "" : curSong->detailUrl
// );
// if (stations != NULL) {
// /* send station list */
// PianoStation_t **sortedStations = NULL;
// size_t stationCount;
// sortedStations = BarSortedStations (stations, &stationCount,
// settings->sortOrder);
// assert (sortedStations != NULL);
// fprintf (pipeWriteFd, "stationCount=%zd\n", stationCount);
// for (size_t i = 0; i < stationCount; i++) {
// const PianoStation_t *currStation = sortedStations[i];
// fprintf (pipeWriteFd, "station%zd=%s\n", i,
// currStation->name);
// }
// free (sortedStations);
// } else {
// const char * const msg = "stationCount=0\n";
// fwrite (msg, sizeof (*msg), strlen (msg), pipeWriteFd);
// }
//
// /* closes pipeFd[1] as well */
// fclose (pipeWriteFd);
// /* wait to get rid of the zombie */
// waitpid (chld, &status, 0);
//}
}

@nlowe

When porting indeed commented out that part due to use of fork() and at a time not clear understanding how I could implement that.

I will look into that next time I get back to pianobar.

+1 for this feature. I was looking into combining this with https://github.com/stuartleeks/wsl-notify-send such that you can have a notification of what the next song in the notification center.

I'm taking a stab at this. fork() doesn't exist for windows, I think the CreateProcess call is what we will want to use. If I get anything working, I'll submit a PR.

I implemented this functionality using the CreateProcess as I described above.

Until it get merged into the main branch, you can utilize this function from my forked release: https://github.com/jonmchan/pianobar-windows/releases

@nlowe If you still need this, I would appreciate if you can test this out and let me know if it works for more than just me. Thanks.