Use song ID to check if song changed, not the title/album/artist.
No longer have to retrieve song information each update.
This commit is contained in:
parent
9ceaa0045e
commit
d899c6815c
@ -68,9 +68,7 @@ static struct argp argp = { options, parse_opt, args_doc, doc, 0, 0, 0 };
|
|||||||
|
|
||||||
struct worker_state {
|
struct worker_state {
|
||||||
int scroll_index;
|
int scroll_index;
|
||||||
char* artist;
|
int song_id;
|
||||||
char* album;
|
|
||||||
char* title;
|
|
||||||
char* full_label;
|
char* full_label;
|
||||||
size_t full_label_length;
|
size_t full_label_length;
|
||||||
char* padded_label;
|
char* padded_label;
|
||||||
@ -150,6 +148,7 @@ print_status(struct mpd_connection *conn, struct worker_state *state)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
state->scroll_index = 0;
|
state->scroll_index = 0;
|
||||||
|
state->song_id = -1;
|
||||||
printf("\n");
|
printf("\n");
|
||||||
mpd_status_free(status);
|
mpd_status_free(status);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@ -172,30 +171,26 @@ print_status(struct mpd_connection *conn, struct worker_state *state)
|
|||||||
const unsigned remaining = mpd_status_get_total_time(status) - elapsed;
|
const unsigned remaining = mpd_status_get_total_time(status) - elapsed;
|
||||||
const unsigned remaining_mins = remaining / 60;
|
const unsigned remaining_mins = remaining / 60;
|
||||||
const unsigned remaining_secs = remaining % 60;
|
const unsigned remaining_secs = remaining % 60;
|
||||||
|
const int song_id = mpd_status_get_song_id(status);
|
||||||
|
|
||||||
mpd_status_free(status);
|
mpd_status_free(status);
|
||||||
if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS)
|
if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS)
|
||||||
return handle_error(conn, false);
|
return handle_error(conn, false);
|
||||||
|
|
||||||
char artist[256];
|
if (song_id != state->song_id) {
|
||||||
char album[256];
|
state->song_id = song_id;
|
||||||
char title[256];
|
|
||||||
|
|
||||||
struct mpd_song *song = mpd_run_current_song(conn);
|
char artist[256];
|
||||||
get_tag(song, artist, MPD_TAG_ARTIST);
|
char album[256];
|
||||||
get_tag(song, album, MPD_TAG_ALBUM);
|
char title[256];
|
||||||
get_tag(song, title, MPD_TAG_TITLE);
|
|
||||||
|
|
||||||
mpd_song_free(song);
|
struct mpd_song *song = mpd_run_current_song(conn);
|
||||||
if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS)
|
get_tag(song, artist, MPD_TAG_ARTIST);
|
||||||
return handle_error(conn, false);
|
get_tag(song, album, MPD_TAG_ALBUM);
|
||||||
|
get_tag(song, title, MPD_TAG_TITLE);
|
||||||
if (strcmp(state->title, title) != 0
|
mpd_song_free(song);
|
||||||
|| strcmp(state->album, album) != 0
|
if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS)
|
||||||
|| strcmp(state->artist, artist) != 0) {
|
return handle_error(conn, false);
|
||||||
strcpy(state->title, title);
|
|
||||||
strcpy(state->album, album);
|
|
||||||
strcpy(state->artist, artist);
|
|
||||||
|
|
||||||
// The song changed, so let's update the full label...
|
// The song changed, so let's update the full label...
|
||||||
sprintf(state->full_label, "%s - %s", title, artist);
|
sprintf(state->full_label, "%s - %s", title, artist);
|
||||||
@ -300,8 +295,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
argp_parse(&argp, argc, argv, 0, 0, &arguments);
|
argp_parse(&argp, argc, argv, 0, 0, &arguments);
|
||||||
|
|
||||||
struct worker_state state = {0, malloc(256), malloc(256), malloc(256),
|
struct worker_state state = {0, -1, malloc(1024), 0, malloc(1024), 0};
|
||||||
malloc(1024), 0, malloc(1024), 0};
|
|
||||||
|
|
||||||
struct sigaction new_actn, old_actn;
|
struct sigaction new_actn, old_actn;
|
||||||
new_actn.sa_handler = SIG_IGN;
|
new_actn.sa_handler = SIG_IGN;
|
||||||
|
Loading…
Reference in New Issue
Block a user