Simplify print_status by using mpd_run calls.

This commit is contained in:
Matt Low 2019-10-16 21:32:41 +04:00
parent 49c1a3b904
commit ec4be8d9dc

View File

@ -25,7 +25,7 @@ current_timestamp() {
} }
static void static void
scroll_text(const char *text_to_scroll, const int text_len, char *buffer, scroll_text(const char *text_to_scroll, const size_t text_len, char *buffer,
int *index, const int max_length) { int *index, const int max_length) {
if (*index - text_len > 0) *index %= text_len; if (*index - text_len > 0) *index %= text_len;
@ -64,15 +64,8 @@ get_tag(struct mpd_song *song, char *tag, enum mpd_tag_type type)
static int static int
print_status(struct mpd_connection *conn, struct worker_meta *meta) print_status(struct mpd_connection *conn, struct worker_meta *meta)
{ {
struct mpd_status *status; struct mpd_status *status = mpd_run_status(conn);
struct mpd_song *song;
mpd_command_list_begin(conn, true);
mpd_send_status(conn);
mpd_send_current_song(conn);
mpd_command_list_end(conn);
status = mpd_recv_status(conn);
if (status == NULL) if (status == NULL)
return handle_error(conn); return handle_error(conn);
@ -81,6 +74,7 @@ print_status(struct mpd_connection *conn, struct worker_meta *meta)
if (state == MPD_STATE_STOP || state == MPD_STATE_UNKNOWN) { if (state == MPD_STATE_STOP || state == MPD_STATE_UNKNOWN) {
// Early exit // Early exit
printf("\n"); printf("\n");
mpd_status_free(status);
fflush(stdout); fflush(stdout);
return 0; return 0;
} }
@ -99,21 +93,17 @@ print_status(struct mpd_connection *conn, struct worker_meta *meta)
if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS)
return handle_error(conn); return handle_error(conn);
mpd_response_next(conn);
char artist[256]; char artist[256];
char album[256]; char album[256];
char title[256]; char title[256];
while ((song = mpd_recv_song(conn)) != NULL) { struct mpd_song *song = mpd_run_current_song(conn);
get_tag(song, artist, MPD_TAG_ARTIST); get_tag(song, artist, MPD_TAG_ARTIST);
get_tag(song, album, MPD_TAG_ALBUM); get_tag(song, album, MPD_TAG_ALBUM);
get_tag(song, title, MPD_TAG_TITLE); get_tag(song, title, MPD_TAG_TITLE);
mpd_song_free(song);
}
if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS || mpd_song_free(song);
!mpd_response_finish(conn)) if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS)
return handle_error(conn); return handle_error(conn);
char *play_icon; char *play_icon;