1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-11-05 22:36:16 +00:00

Feat: add lastPlayed sticker to songs

This commit is contained in:
jcorporation 2018-08-15 18:06:12 +02:00
parent 85d75190d9
commit 0f31cbea48
2 changed files with 10 additions and 3 deletions

View File

@ -557,6 +557,7 @@ void mympd_poll(struct mg_mgr *s, int timeout) {
fprintf(stderr, "MPD connection failed.\n");
snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"disconnected\"}");
mympd_notify(s);
case MPD_DISCONNECT:
case MPD_RECONNECT:
if (mpd.conn != NULL)
@ -584,7 +585,7 @@ char* mympd_get_song_uri_from_song_id(int song_id) {
if (song_id > -1) {
song = mpd_run_get_queue_song_id(mpd.conn, song_id);
if (song) {
str = (char *)mpd_song_get_uri(song);
str = strdup(mpd_song_get_uri(song));
mpd_song_free(song);
}
}
@ -592,8 +593,7 @@ char* mympd_get_song_uri_from_song_id(int song_id) {
}
void mympd_count_song_id(int song_id, char *name, int value) {
char *uri = mympd_get_song_uri_from_song_id(song_id);
mympd_count_song_uri(uri, name, value);
mympd_count_song_uri(mympd_get_song_uri_from_song_id(song_id), name, value);
}
void mympd_count_song_uri(const char *uri, char *name, int value) {
@ -624,6 +624,10 @@ void mympd_like_song_uri(const char *uri, int value) {
mpd_run_sticker_set(mpd.conn, "song", uri, "like", v);
}
void mympd_last_played_song_id(int song_id) {
mympd_last_played_song_uri(mympd_get_song_uri_from_song_id(song_id));
}
void mympd_last_played_song_uri(const char *uri) {
char v[20];
snprintf(v, 19, "%lu", time(NULL));
@ -656,6 +660,7 @@ void mympd_parse_idle(struct mg_mgr *s) {
case MPD_IDLE_PLAYER:
len = mympd_put_state(mpd.buf, &mpd.song_id, &mpd.next_song_id, &mpd.queue_version);
mympd_count_song_id(mpd.song_id, "playCount", 1);
mympd_last_played_song_id(mpd.song_id);
break;
case MPD_IDLE_MIXER:
len = mympd_put_state(mpd.buf, &mpd.song_id, &mpd.next_song_id, &mpd.queue_version);

View File

@ -150,6 +150,8 @@ void mympd_notify(struct mg_mgr *s);
void mympd_count_song_id(int song_id, char *name, int value);
void mympd_count_song_uri(const char *uri, char *name, int value);
void mympd_like_song_uri(const char *uri, int value);
void mympd_last_played_song_uri(const char *uri);
void mympd_last_played_song_id(int song_id);
int mympd_put_state(char *buffer, int *current_song_id, int *next_song_id, unsigned *queue_version);
int mympd_put_outputs(char *buffer);
int mympd_put_current_song(char *buffer);