mirror of
https://github.com/SuperBFG7/ympd
synced 2025-09-11 06:46:00 +00:00
Feat: advanced search support for sorting and grouping
This commit is contained in:
@@ -2178,7 +2178,7 @@ int mympd_search(char *buffer, char *searchstr, char *filter, char *plist, unsig
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mympd_search_v21(char *buffer, char *searchstr, char *filter, char *plist, unsigned int offset) {
|
int mympd_search_adv(char *buffer, char *expression, char *sort, bool sortdesc, char *grouptag, char *plist, unsigned int offset) {
|
||||||
struct mpd_song *song;
|
struct mpd_song *song;
|
||||||
unsigned long entity_count = 0;
|
unsigned long entity_count = 0;
|
||||||
unsigned long entities_returned = 0;
|
unsigned long entities_returned = 0;
|
||||||
@@ -2199,19 +2199,17 @@ int mympd_search_v21(char *buffer, char *searchstr, char *filter, char *plist, u
|
|||||||
RETURN_ERROR_AND_RECOVER("mpd_search_add_db_songs_to_playlist");
|
RETURN_ERROR_AND_RECOVER("mpd_search_add_db_songs_to_playlist");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(filter, "any") == 0) {
|
if (mpd_search_add_expression(mpd.conn, expression) == false)
|
||||||
if (mpd_search_add_any_tag_constraint(mpd.conn, MPD_OPERATOR_DEFAULT, searchstr) == false)
|
RETURN_ERROR_AND_RECOVER("mpd_search_add_expression");
|
||||||
RETURN_ERROR_AND_RECOVER("mpd_search_add_any_tag_constraint");
|
|
||||||
|
if (sort != NULL && strcmp(plist, "") == 0) {
|
||||||
|
if (mpd_search_add_sort_name(mpd.conn, sort, sortdesc) == false)
|
||||||
|
RETURN_ERROR_AND_RECOVER("mpd_search_add_sort_name");
|
||||||
}
|
}
|
||||||
else if (strcmp(filter, "modified-since") == 0) {
|
|
||||||
char *crap;
|
if (grouptag != NULL && strcmp(plist, "") == 0) {
|
||||||
long timestamp = strtol(searchstr, &crap, 10);
|
if (mpd_search_add_group_tag(mpd.conn, mpd_tag_name_parse(grouptag)) == false)
|
||||||
if (mpd_search_add_modified_since_constraint(mpd.conn, MPD_OPERATOR_DEFAULT, timestamp) == false)
|
RETURN_ERROR_AND_RECOVER("mpd_search_add_group_tag");
|
||||||
RETURN_ERROR_AND_RECOVER("mpd_search_add_tag_constraint");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (mpd_search_add_tag_constraint(mpd.conn, MPD_OPERATOR_DEFAULT, mpd_tag_name_parse(filter), searchstr) == false)
|
|
||||||
RETURN_ERROR_AND_RECOVER("mpd_search_add_tag_constraint");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mpd_search_commit(mpd.conn) == false)
|
if (mpd_search_commit(mpd.conn) == false)
|
||||||
@@ -2237,11 +2235,15 @@ int mympd_search_v21(char *buffer, char *searchstr, char *filter, char *plist, u
|
|||||||
mpd_response_finish(mpd.conn);
|
mpd_response_finish(mpd.conn);
|
||||||
|
|
||||||
if (strcmp(plist, "") == 0) {
|
if (strcmp(plist, "") == 0) {
|
||||||
len += json_printf(&out, "], totalEntities: %d, offset: %d, returnedEntities: %d, searchstr: %Q}",
|
len += json_printf(&out, "], totalEntities: %d, offset: %d, returnedEntities: %d, expression: %Q, "
|
||||||
|
"sort: %Q, sortdesc: %B, grouptag: %Q}",
|
||||||
entity_count,
|
entity_count,
|
||||||
offset,
|
offset,
|
||||||
entities_returned,
|
entities_returned,
|
||||||
searchstr
|
expression,
|
||||||
|
sort,
|
||||||
|
sortdesc,
|
||||||
|
grouptag
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -2607,7 +2609,7 @@ int mympd_smartpls_update(char *playlist, char *sticker, int maxentries) {
|
|||||||
|
|
||||||
int mympd_smartpls_update_newest(char *playlist, int timerange) {
|
int mympd_smartpls_update_newest(char *playlist, int timerange) {
|
||||||
unsigned long value_max = 0;
|
unsigned long value_max = 0;
|
||||||
char searchstr[20];
|
char searchstr[50];
|
||||||
|
|
||||||
struct mpd_stats *stats = mpd_run_stats(mpd.conn);
|
struct mpd_stats *stats = mpd_run_stats(mpd.conn);
|
||||||
if (stats != NULL) {
|
if (stats != NULL) {
|
||||||
@@ -2622,8 +2624,14 @@ int mympd_smartpls_update_newest(char *playlist, int timerange) {
|
|||||||
mympd_smartpls_clear(playlist);
|
mympd_smartpls_clear(playlist);
|
||||||
value_max -= timerange;
|
value_max -= timerange;
|
||||||
if (value_max > 0) {
|
if (value_max > 0) {
|
||||||
|
if (mpd.feat_advsearch == true) {
|
||||||
|
snprintf(searchstr, 50, "(modified-since '%lu')", value_max);
|
||||||
|
mympd_search_adv(mpd.buf, searchstr, NULL, true, NULL, playlist, 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
snprintf(searchstr, 20, "%lu", value_max);
|
snprintf(searchstr, 20, "%lu", value_max);
|
||||||
mympd_search(mpd.buf, searchstr, "modified-since", playlist, 0);
|
mympd_search(mpd.buf, searchstr, "modified-since", playlist, 0);
|
||||||
|
}
|
||||||
printf("Updated %s\n", playlist);
|
printf("Updated %s\n", playlist);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -266,7 +266,7 @@ int mympd_put_current_song(char *buffer);
|
|||||||
int mympd_put_queue(char *buffer, unsigned int offset, unsigned *queue_version, unsigned *queue_length);
|
int mympd_put_queue(char *buffer, unsigned int offset, unsigned *queue_version, unsigned *queue_length);
|
||||||
int mympd_put_browse(char *buffer, char *path, unsigned int offset, char *filter);
|
int mympd_put_browse(char *buffer, char *path, unsigned int offset, char *filter);
|
||||||
int mympd_search(char *buffer, char *searchstr, char *filter, char *plist, unsigned int offset);
|
int mympd_search(char *buffer, char *searchstr, char *filter, char *plist, unsigned int offset);
|
||||||
int mympd_search_v21(char *buffer, char *searchstr, char *filter, char *plist, unsigned int offset);
|
int mympd_search_adv(char *buffer, char *expression, char *sort, bool sortdesc, char *grouptag, char *plist, unsigned int offset);
|
||||||
int mympd_search_queue(char *buffer, char *mpdtagtype, unsigned int offset, char *searchstr);
|
int mympd_search_queue(char *buffer, char *mpdtagtype, unsigned int offset, char *searchstr);
|
||||||
int mympd_put_welcome(char *buffer);
|
int mympd_put_welcome(char *buffer);
|
||||||
int mympd_put_volume(char *buffer);
|
int mympd_put_volume(char *buffer);
|
||||||
|
Reference in New Issue
Block a user