mirror of
https://github.com/SuperBFG7/ympd
synced 2025-04-26 12:43:14 +00:00
Feat: add backend code for manage searches as smart playlists #38
This commit is contained in:
parent
043904f888
commit
44dd0e2985
@ -191,6 +191,24 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg) {
|
|||||||
else
|
else
|
||||||
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"error\", \"data\": \"Smart Playlists update failed\"}");
|
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"error\", \"data\": \"Smart Playlists update failed\"}");
|
||||||
break;
|
break;
|
||||||
|
case MPD_API_SMARTPLS_SAVE:
|
||||||
|
je = json_scanf(msg.p, msg.len, "{data: {playlist: %Q, tag: %Q, searchstr: %Q}}", &p_charbuf1, &p_charbuf2, &p_charbuf3);
|
||||||
|
if (je == 3) {
|
||||||
|
mympd_smartpls_save(p_charbuf1, p_charbuf2, p_charbuf3);
|
||||||
|
free(p_charbuf1);
|
||||||
|
free(p_charbuf2);
|
||||||
|
free(p_charbuf3);
|
||||||
|
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MPD_API_SMARTPLS_RM:
|
||||||
|
je = json_scanf(msg.p, msg.len, "{data: {playlist: %Q}}", &p_charbuf1);
|
||||||
|
if (je == 3) {
|
||||||
|
mympd_smartpls_rm(p_charbuf1);
|
||||||
|
free(p_charbuf1);
|
||||||
|
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}");
|
||||||
|
}
|
||||||
|
break;
|
||||||
case MPD_API_PLAYER_PAUSE:
|
case MPD_API_PLAYER_PAUSE:
|
||||||
mpd_run_toggle_pause(mpd.conn);
|
mpd_run_toggle_pause(mpd.conn);
|
||||||
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}");
|
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}");
|
||||||
@ -1882,13 +1900,32 @@ void mympd_disconnect() {
|
|||||||
mympd_idle(NULL, 0);
|
mympd_idle(NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int mympd_smartpls_save(char *playlist, char *tag, char *searchstr) {
|
||||||
|
char tmp_file[400];
|
||||||
|
char pl_file[400];
|
||||||
|
snprintf(tmp_file, 400, "/var/lib/mympd/tmp/%s", playlist);
|
||||||
|
snprintf(pl_file, 400, "/var/lib/mympd/smartpls/%s", playlist);
|
||||||
|
json_fprintf(tmp_file, "{type: search, tag: %Q, searchstr: %Q}", tag, searchstr);
|
||||||
|
rename(tmp_file, pl_file);
|
||||||
|
mympd_smartpls_update_search(playlist, tag, searchstr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mympd_smartpls_rm(char *playlist) {
|
||||||
|
char pl_file[400];
|
||||||
|
snprintf(pl_file, 400, "/var/lib/mympd/smartpls/%s", playlist);
|
||||||
|
unlink(pl_file);
|
||||||
|
mpd_run_rm(mpd.conn, playlist);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int mympd_smartpls_update_all() {
|
int mympd_smartpls_update_all() {
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *ent;
|
struct dirent *ent;
|
||||||
char *smartpltype;
|
char *smartpltype;
|
||||||
char filename[400];
|
char filename[400];
|
||||||
int je;
|
int je;
|
||||||
char *p_charbuf1;
|
char *p_charbuf1, *p_charbuf2;
|
||||||
int int_buf1, int_buf2;
|
int int_buf1, int_buf2;
|
||||||
|
|
||||||
if (!config.smartpls)
|
if (!config.smartpls)
|
||||||
@ -1896,7 +1933,7 @@ int mympd_smartpls_update_all() {
|
|||||||
|
|
||||||
if ((dir = opendir ("/var/lib/mympd/smartpls")) != NULL) {
|
if ((dir = opendir ("/var/lib/mympd/smartpls")) != NULL) {
|
||||||
while ((ent = readdir(dir)) != NULL) {
|
while ((ent = readdir(dir)) != NULL) {
|
||||||
if (strncmp (ent->d_name, ".", 1) == 0)
|
if (strncmp(ent->d_name, ".", 1) == 0)
|
||||||
continue;
|
continue;
|
||||||
snprintf(filename, 400, "/var/lib/mympd/smartpls/%s", ent->d_name);
|
snprintf(filename, 400, "/var/lib/mympd/smartpls/%s", ent->d_name);
|
||||||
char *content = json_fread(filename);
|
char *content = json_fread(filename);
|
||||||
@ -1921,7 +1958,14 @@ int mympd_smartpls_update_all() {
|
|||||||
printf("Can't parse file %s\n", filename);
|
printf("Can't parse file %s\n", filename);
|
||||||
}
|
}
|
||||||
else if (strcmp(smartpltype, "search") == 0) {
|
else if (strcmp(smartpltype, "search") == 0) {
|
||||||
//to be implemented
|
je = json_scanf(content, strlen(content), "{tag: %Q, searchstr: %Q}", &p_charbuf1, &p_charbuf2);
|
||||||
|
if (je == 2) {
|
||||||
|
mympd_smartpls_update_search(ent->d_name, p_charbuf1, p_charbuf2);
|
||||||
|
free(p_charbuf1);
|
||||||
|
free(p_charbuf2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
printf("Can't parse file %s\n", filename);
|
||||||
}
|
}
|
||||||
free(smartpltype);
|
free(smartpltype);
|
||||||
}
|
}
|
||||||
@ -1960,6 +2004,13 @@ int mympd_smartpls_clear(char *playlist) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int mympd_smartpls_update_search(char *playlist, char *tag, char *searchstr) {
|
||||||
|
mympd_smartpls_clear(playlist);
|
||||||
|
mympd_search(mpd.buf, searchstr, tag, playlist, 0);
|
||||||
|
printf("Updated %s\n", playlist);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int mympd_smartpls_update(char *sticker, char *playlist, int maxentries) {
|
int mympd_smartpls_update(char *sticker, char *playlist, int maxentries) {
|
||||||
struct mpd_pair *pair;
|
struct mpd_pair *pair;
|
||||||
char *uri = NULL;
|
char *uri = NULL;
|
||||||
|
@ -73,6 +73,8 @@
|
|||||||
X(MPD_API_PLAYLIST_LIST) \
|
X(MPD_API_PLAYLIST_LIST) \
|
||||||
X(MPD_API_PLAYLIST_CONTENT_LIST) \
|
X(MPD_API_PLAYLIST_CONTENT_LIST) \
|
||||||
X(MPD_API_SMARTPLS_UPDATE) \
|
X(MPD_API_SMARTPLS_UPDATE) \
|
||||||
|
X(MPD_API_SMARTPLS_SAVE) \
|
||||||
|
X(MPD_API_SMARTPLS_RM) \
|
||||||
X(MPD_API_DATABASE_SEARCH) \
|
X(MPD_API_DATABASE_SEARCH) \
|
||||||
X(MPD_API_DATABASE_UPDATE) \
|
X(MPD_API_DATABASE_UPDATE) \
|
||||||
X(MPD_API_DATABASE_RESCAN) \
|
X(MPD_API_DATABASE_RESCAN) \
|
||||||
@ -198,10 +200,13 @@ void mympd_last_played_song_uri(const char *uri);
|
|||||||
void mympd_last_played_song_id(int song_id);
|
void mympd_last_played_song_id(int song_id);
|
||||||
void mympd_get_sticker(const char *uri, t_sticker *sticker);
|
void mympd_get_sticker(const char *uri, t_sticker *sticker);
|
||||||
void mympd_jukebox();
|
void mympd_jukebox();
|
||||||
|
int mympd_smartpls_save(char *playlist, char *tag, char *searchstr);
|
||||||
|
int mympd_smartpls_rm(char *playlist);
|
||||||
int mympd_smartpls_update_all();
|
int mympd_smartpls_update_all();
|
||||||
int mympd_smartpls_clear(char *playlist);
|
int mympd_smartpls_clear(char *playlist);
|
||||||
int mympd_smartpls_update(char *sticker, char *playlist, int maxentries);
|
int mympd_smartpls_update(char *sticker, char *playlist, int maxentries);
|
||||||
int mympd_smartpls_update_newest(char *playlist, int timerange, int maxentries);
|
int mympd_smartpls_update_newest(char *playlist, int timerange, int maxentries);
|
||||||
|
int mympd_smartpls_update_search(char *playlist, char *tag, char *searchstr);
|
||||||
int mympd_get_updatedb_state(char *buffer);
|
int mympd_get_updatedb_state(char *buffer);
|
||||||
int mympd_put_state(char *buffer, int *current_song_id, int *next_song_id, int *last_song_id, unsigned *queue_version, unsigned *queue_length);
|
int mympd_put_state(char *buffer, int *current_song_id, int *next_song_id, int *last_song_id, unsigned *queue_version, unsigned *queue_length);
|
||||||
int mympd_put_outputs(char *buffer);
|
int mympd_put_outputs(char *buffer);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user