Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for event_command #40

Open
nlowe opened this issue Dec 1, 2023 · 4 comments
Open

Support for event_command #40

nlowe opened this issue Dec 1, 2023 · 4 comments

Comments

@nlowe
Copy link

nlowe commented Dec 1, 2023

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);
//}
}

@thedmd
Copy link
Owner

thedmd commented Dec 27, 2023

@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.

@jonmchan
Copy link

+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.

@jonmchan
Copy link

jonmchan commented Jul 5, 2024

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.

@jonmchan
Copy link

jonmchan commented Jul 5, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants