diff options
author | geneticdrift <geneticdrift@iotide.com> | 2012-06-27 09:26:03 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2012-06-27 09:49:17 +0200 |
commit | 799843cc9703bd764425b77a1cdd231c3cd9e9ac (patch) | |
tree | 6f1bf6178099b84f727917d9de07bd728af6cdaf /src | |
parent | 16e91baa799e579aa0bad78d7f4291aec8ab7a05 (diff) | |
download | mpd-799843cc9703bd764425b77a1cdd231c3cd9e9ac.tar.gz mpd-799843cc9703bd764425b77a1cdd231c3cd9e9ac.tar.xz mpd-799843cc9703bd764425b77a1cdd231c3cd9e9ac.zip |
New command searchaddpl
Search and add search result to a stored playlist.
Diffstat (limited to '')
-rw-r--r-- | src/command.c | 28 | ||||
-rw-r--r-- | src/dbUtils.c | 43 | ||||
-rw-r--r-- | src/dbUtils.h | 6 |
3 files changed, 77 insertions, 0 deletions
diff --git a/src/command.c b/src/command.c index b5671412a..23f679fdf 100644 --- a/src/command.c +++ b/src/command.c @@ -879,6 +879,33 @@ handle_searchadd(struct client *client, int argc, char *argv[]) } static enum command_return +handle_searchaddpl(struct client *client, int argc, char *argv[]) +{ + const char *playlist = argv[1]; + + struct locate_item_list *list = + locate_item_list_parse(argv + 2, argc - 2); + + if (list == NULL || list->length == 0) { + if (list != NULL) + locate_item_list_free(list); + + command_error(client, ACK_ERROR_ARG, "incorrect arguments"); + return COMMAND_RETURN_ERROR; + } + + GError *error = NULL; + enum command_return ret = + search_add_to_playlist("", playlist, list, &error) + ? COMMAND_RETURN_OK + : print_error(client, error); + + locate_item_list_free(list); + + return ret; +} + +static enum command_return handle_count(struct client *client, int argc, char *argv[]) { struct locate_item_list *list = @@ -2028,6 +2055,7 @@ static const struct command commands[] = { { "save", PERMISSION_CONTROL, 1, 1, handle_save }, { "search", PERMISSION_READ, 2, -1, handle_search }, { "searchadd", PERMISSION_READ, 2, -1, handle_searchadd }, + { "searchaddpl", PERMISSION_READ, 3, -1, handle_searchaddpl }, { "seek", PERMISSION_CONTROL, 2, 2, handle_seek }, { "seekcur", PERMISSION_CONTROL, 1, 1, handle_seekcur }, { "seekid", PERMISSION_CONTROL, 2, 2, handle_seekid }, diff --git a/src/dbUtils.c b/src/dbUtils.c index 5a30c14be..c212d9f9c 100644 --- a/src/dbUtils.c +++ b/src/dbUtils.c @@ -164,3 +164,46 @@ search_add_songs(struct player_control *pc, const char *uri, return success; } + +struct search_add_playlist_data { + const char *playlist; + const struct locate_item_list *criteria; +}; + +static bool +searchaddpl_visitor_song(struct song *song, void *_data, + G_GNUC_UNUSED GError **error_r) +{ + struct search_add_playlist_data *data = _data; + + if (!locate_song_search(song, data->criteria)) + return true; + + if (!spl_append_song(data->playlist, song, error_r)) + return false; + + return true; +} + +static const struct db_visitor searchaddpl_visitor = { + .song = searchaddpl_visitor_song, +}; + +bool +search_add_to_playlist(const char *uri, const char *path_utf8, + const struct locate_item_list *criteria, + GError **error_r) +{ + struct locate_item_list *new_list + = locate_item_list_casefold(criteria); + struct search_add_playlist_data data = { + .playlist = path_utf8, + .criteria = new_list, + }; + + bool success = db_walk(uri, &searchaddpl_visitor, &data, error_r); + + locate_item_list_free(new_list); + + return success; +} diff --git a/src/dbUtils.h b/src/dbUtils.h index 94a096f66..706c807fd 100644 --- a/src/dbUtils.h +++ b/src/dbUtils.h @@ -47,4 +47,10 @@ bool search_add_songs(struct player_control *pc, const char *uri, const struct locate_item_list *criteria, GError **error_r); +gcc_nonnull(1,2,3) +bool +search_add_to_playlist(const char *uri, const char *path_utf8, + const struct locate_item_list *criteria, + GError **error_r); + #endif |