mirror of
https://github.com/SuperBFG7/ympd
synced 2024-06-16 10:09:56 +00:00
Feat: add getsticker function
This commit is contained in:
parent
0f31cbea48
commit
8ca90d02d6
|
@ -579,6 +579,27 @@ void mympd_poll(struct mg_mgr *s, int timeout) {
|
|||
}
|
||||
}
|
||||
|
||||
void mympd_get_sticker(const char *uri, t_sticker *sticker) {
|
||||
struct mpd_pair *pair;
|
||||
sticker->playCount = 0;
|
||||
sticker->skipCount = 0;
|
||||
sticker->lastPlayed = 0;
|
||||
sticker->like = 1;
|
||||
if (mpd_send_sticker_list(mpd.conn, "song", uri)) {
|
||||
while ((pair = mpd_recv_sticker(mpd.conn)) != NULL) {
|
||||
if (strcmp(pair->name, "playCount") == 0)
|
||||
sticker->playCount = atoi(pair->value);
|
||||
else if (strcmp(pair->name, "skipCount") == 0)
|
||||
sticker->skipCount = atoi(pair->value);
|
||||
else if (strcmp(pair->name, "lastPlayed") == 0)
|
||||
sticker->lastPlayed = atoi(pair->value);
|
||||
else if (strcmp(pair->name, "like") == 0)
|
||||
sticker->like = atoi(pair->value);
|
||||
mpd_return_sticker(mpd.conn, pair);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char* mympd_get_song_uri_from_song_id(int song_id) {
|
||||
char *str;
|
||||
struct mpd_song *song;
|
||||
|
@ -618,8 +639,10 @@ void mympd_count_song_uri(const char *uri, char *name, int value) {
|
|||
|
||||
void mympd_like_song_uri(const char *uri, int value) {
|
||||
char v[3];
|
||||
if (value > 0)
|
||||
value = 1;
|
||||
if (value > 2)
|
||||
value = 2;
|
||||
else if (value < 0)
|
||||
value = 0;
|
||||
snprintf(v, 2, "%d", value);
|
||||
mpd_run_sticker_set(mpd.conn, "song", uri, "like", v);
|
||||
}
|
||||
|
@ -715,9 +738,7 @@ int mympd_put_state(char *buffer, int *current_song_id, int *next_song_id, unsig
|
|||
mpd.conn_state = MPD_FAILURE;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
audioformat = mpd_status_get_audio_format(status);
|
||||
}
|
||||
|
||||
len = json_printf(&out,"{type: update_state, data: {"
|
||||
"state:%d, volume:%d, songPos: %d, elapsedTime: %d, "
|
||||
|
@ -880,6 +901,7 @@ int mympd_get_cover(const char *uri, char *cover, int cover_len) {
|
|||
|
||||
int mympd_put_current_song(char *buffer) {
|
||||
struct mpd_song *song;
|
||||
t_sticker *sticker = (t_sticker *) malloc(sizeof(t_sticker));
|
||||
int len;
|
||||
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
|
||||
char cover[500];
|
||||
|
@ -891,10 +913,11 @@ int mympd_put_current_song(char *buffer) {
|
|||
}
|
||||
|
||||
mympd_get_cover(mpd_song_get_uri(song), cover, 500);
|
||||
mympd_get_sticker(mpd_song_get_uri(song), sticker);
|
||||
|
||||
len = json_printf(&out,"{type: song_change, data: { pos: %d, title: %Q, "
|
||||
"artist: %Q, album: %Q, uri: %Q, currentSongId: %d, albumartist: %Q, "
|
||||
"duration: %d, cover: %Q}}",
|
||||
"duration: %d, cover: %Q, playCount: %d, skipCount: %d, like: %d, lastPlayed: %d}}",
|
||||
mpd_song_get_pos(song),
|
||||
mympd_get_tag(song, MPD_TAG_TITLE),
|
||||
mympd_get_tag(song, MPD_TAG_ARTIST),
|
||||
|
@ -903,11 +926,16 @@ int mympd_put_current_song(char *buffer) {
|
|||
mpd.song_id,
|
||||
mympd_get_tag(song, MPD_TAG_ALBUM_ARTIST),
|
||||
mpd_song_get_duration(song),
|
||||
cover
|
||||
cover,
|
||||
sticker->playCount,
|
||||
sticker->skipCount,
|
||||
sticker->like,
|
||||
sticker->lastPlayed
|
||||
);
|
||||
|
||||
mpd_song_free(song);
|
||||
mpd_response_finish(mpd.conn);
|
||||
free(sticker);
|
||||
|
||||
if (len > MAX_SIZE)
|
||||
fprintf(stderr, "Buffer truncated\n");
|
||||
|
@ -920,13 +948,16 @@ int mympd_put_songdetails(char *buffer, char *uri) {
|
|||
int len;
|
||||
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
|
||||
char cover[500];
|
||||
t_sticker *sticker = (t_sticker *) malloc(sizeof(t_sticker));
|
||||
|
||||
len = json_printf(&out, "{type: song_details, data: {");
|
||||
mpd_send_list_all_meta(mpd.conn, uri);
|
||||
while ((entity = mpd_recv_entity(mpd.conn)) != NULL) {
|
||||
if ((entity = mpd_recv_entity(mpd.conn)) != NULL) {
|
||||
song = mpd_entity_get_song(entity);
|
||||
mympd_get_cover(mpd_song_get_uri(song),cover,500);
|
||||
len += json_printf(&out, "duration: %d, artist: %Q, album: %Q, title: %Q, albumartist: %Q, cover: %Q, uri: %Q, genre: %Q, track: %Q, date: %Q",
|
||||
|
||||
mympd_get_cover(uri, cover, 500);
|
||||
len += json_printf(&out, "duration: %d, artist: %Q, album: %Q, title: %Q, albumartist: %Q, cover: %Q, uri: %Q, "
|
||||
"genre: %Q, track: %Q, date: %Q",
|
||||
mpd_song_get_duration(song),
|
||||
mympd_get_tag(song, MPD_TAG_ARTIST),
|
||||
mympd_get_tag(song, MPD_TAG_ALBUM),
|
||||
|
@ -940,6 +971,16 @@ int mympd_put_songdetails(char *buffer, char *uri) {
|
|||
);
|
||||
mpd_entity_free(entity);
|
||||
}
|
||||
mpd_response_finish(mpd.conn);
|
||||
|
||||
mympd_get_sticker(uri, sticker);
|
||||
len += json_printf(&out, ", playCount: %d, skipCount: %d, like: %d, lastPlayed: %d",
|
||||
sticker->playCount,
|
||||
sticker->skipCount,
|
||||
sticker->like,
|
||||
sticker->lastPlayed
|
||||
);
|
||||
free(sticker);
|
||||
len += json_printf(&out, "}}");
|
||||
|
||||
if (len > MAX_SIZE)
|
||||
|
|
|
@ -135,9 +135,16 @@ typedef struct {
|
|||
int streamport;
|
||||
const char* coverimage;
|
||||
const char* statefile;
|
||||
} configuration;
|
||||
} t_config;
|
||||
|
||||
configuration config;
|
||||
t_config config;
|
||||
|
||||
typedef struct {
|
||||
int playCount;
|
||||
int skipCount;
|
||||
int lastPlayed;
|
||||
int like;
|
||||
} t_sticker;
|
||||
|
||||
static int is_websocket(const struct mg_connection *nc) {
|
||||
return nc->flags & MG_F_IS_WEBSOCKET;
|
||||
|
@ -152,6 +159,7 @@ 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);
|
||||
void mympd_get_sticker(const char *uri, t_sticker *sticker);
|
||||
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);
|
||||
|
|
|
@ -107,7 +107,7 @@ static void ev_handler_http(struct mg_connection *nc_http, int ev, void *ev_data
|
|||
}
|
||||
|
||||
static int inihandler(void* user, const char* section, const char* name, const char* value) {
|
||||
configuration* p_config = (configuration*)user;
|
||||
t_config* p_config = (t_config*)user;
|
||||
|
||||
#define MATCH(n) strcmp(name, n) == 0
|
||||
if (MATCH("mpdhost"))
|
||||
|
|
Loading…
Reference in New Issue
Block a user