Skip to content

Commit

Permalink
added "exiting" player status (cmus#648)
Browse files Browse the repository at this point in the history
  • Loading branch information
jolange authored and flyingmutant committed Feb 8, 2019
1 parent 275df4b commit 4e12f15
Showing 1 changed file with 63 additions and 50 deletions.
113 changes: 63 additions & 50 deletions ui_curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -1794,67 +1794,74 @@ static void clear_error(void)

/* screen updates }}} */

static void spawn_status_program(void)
static int fill_status_program_track_info_args(char **argv, int i, struct track_info *ti)
{
enum player_status status;
/* returns first free argument index */

const char *stream_title = NULL;
char *argv[32];
int i;
if (player_info.status == PLAYER_STATUS_PLAYING && is_http_url(ti->filename))
stream_title = get_stream_title();

static const char *keys[] = {
"artist", "albumartist", "album", "discnumber", "tracknumber", "title",
"date", "musicbrainz_trackid", NULL
};
int j;

if (is_http_url(ti->filename)) {
argv[i++] = xstrdup("url");
} else {
argv[i++] = xstrdup("file");
}
argv[i++] = xstrdup(ti->filename);

if (track_info_has_tag(ti)) {
for (j = 0; keys[j]; j++) {
const char *key = keys[j];
const char *val;

if (strcmp(key, "title") == 0 && stream_title)
/*
* StreamTitle overrides radio station name
*/
val = stream_title;
else
val = keyvals_get_val(ti->comments, key);

if (val) {
argv[i++] = xstrdup(key);
argv[i++] = xstrdup(val);
}
}
if (ti->duration > 0) {
char buf[32];
snprintf(buf, sizeof(buf), "%d", ti->duration);
argv[i++] = xstrdup("duration");
argv[i++] = xstrdup(buf);
}
} else if (stream_title) {
argv[i++] = xstrdup("title");
argv[i++] = xstrdup(stream_title);
}

return i;
}

static void spawn_status_program_inner(const char *status_text, struct track_info *ti)
{
if (status_display_program == NULL || status_display_program[0] == 0)
return;

status = player_info.status;
if (status == PLAYER_STATUS_PLAYING && player_info.ti && is_http_url(player_info.ti->filename))
stream_title = get_stream_title();
char *argv[32];
int i = 0;

i = 0;
argv[i++] = xstrdup(status_display_program);

argv[i++] = xstrdup("status");
argv[i++] = xstrdup(player_status_names[status]);
if (player_info.ti) {
static const char *keys[] = {
"artist", "albumartist", "album", "discnumber", "tracknumber", "title",
"date", "musicbrainz_trackid", NULL
};
int j;
argv[i++] = xstrdup(status_text);

if (is_http_url(player_info.ti->filename)) {
argv[i++] = xstrdup("url");
} else {
argv[i++] = xstrdup("file");
}
argv[i++] = xstrdup(player_info.ti->filename);

if (track_info_has_tag(player_info.ti)) {
for (j = 0; keys[j]; j++) {
const char *key = keys[j];
const char *val;

if (strcmp(key, "title") == 0 && stream_title)
/*
* StreamTitle overrides radio station name
*/
val = stream_title;
else
val = keyvals_get_val(player_info.ti->comments, key);

if (val) {
argv[i++] = xstrdup(key);
argv[i++] = xstrdup(val);
}
}
if (player_info.ti->duration > 0) {
char buf[32];
snprintf(buf, sizeof(buf), "%d", player_info.ti->duration);
argv[i++] = xstrdup("duration");
argv[i++] = xstrdup(buf);
}
} else if (stream_title) {
argv[i++] = xstrdup("title");
argv[i++] = xstrdup(stream_title);
}
if (ti) {
i = fill_status_program_track_info_args(argv, i, ti);
}
argv[i++] = NULL;

Expand All @@ -1864,6 +1871,11 @@ static void spawn_status_program(void)
free(argv[i]);
}

static void spawn_status_program(void)
{
spawn_status_program_inner(player_status_names[player_info.status], player_info.ti);
}

static volatile sig_atomic_t ctrl_c_pressed = 0;

static void sig_int(int sig)
Expand Down Expand Up @@ -2533,5 +2545,6 @@ int main(int argc, char *argv[])
init_all();
main_loop();
exit_all();
spawn_status_program_inner("exiting", NULL);
return 0;
}

0 comments on commit 4e12f15

Please sign in to comment.