Skip to content

Commit

Permalink
Upd: provide buffer for get_search_expression_album and get_search_ex…
Browse files Browse the repository at this point in the history
…pression_album_disc
  • Loading branch information
jcorporation committed Sep 17, 2024
1 parent 64145ad commit 09e84d5
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 25 deletions.
26 changes: 14 additions & 12 deletions src/mpd_client/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,14 @@ bool mpd_client_search_add_to_queue_window(struct t_partition_state *partition_s
* @param album_config album configuration
* @return newly allocated sds string
*/
sds get_search_expression_album(enum mpd_tag_type tag_albumartist, struct mpd_song *album,
sds get_search_expression_album(sds buffer, enum mpd_tag_type tag_albumartist, struct mpd_song *album,
const struct t_albums_config *album_config)
{
sds expression = sdsnewlen("(", 1);
expression = append_search_expression_album(tag_albumartist, album, album_config, expression);
expression = sdscatlen(expression, ")", 1);
return expression;
sdsclear(buffer);
buffer = sdscatlen(buffer, "(", 1);
buffer = append_search_expression_album(tag_albumartist, album, album_config, buffer);
buffer = sdscatlen(buffer, ")", 1);
return buffer;
}

/**
Expand All @@ -168,16 +169,17 @@ sds get_search_expression_album(enum mpd_tag_type tag_albumartist, struct mpd_so
* @param album_config album configuration
* @return newly allocated sds string
*/
sds get_search_expression_album_disc(enum mpd_tag_type tag_albumartist, struct mpd_song *album,
sds get_search_expression_album_disc(sds buffer, enum mpd_tag_type tag_albumartist, struct mpd_song *album,
const char *disc, const struct t_albums_config *album_config)
{
sds expression = sdsnewlen("(", 1);
expression = append_search_expression_album(tag_albumartist, album, album_config, expression);
sdsclear(buffer);
buffer = sdscatlen(buffer, "(", 1);
buffer = append_search_expression_album(tag_albumartist, album, album_config, buffer);
//and for cd
expression = sdscat(expression, " AND ");
expression = escape_mpd_search_expression(expression, "Disc", "==", disc);
expression = sdscatlen(expression, ")", 1);
return expression;
buffer = sdscat(buffer, " AND ");
buffer = escape_mpd_search_expression(buffer, "Disc", "==", disc);
buffer = sdscatlen(buffer, ")", 1);
return buffer;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/mpd_client/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ bool mpd_client_search_add_to_queue_window(struct t_partition_state *partition_s

bool mpd_client_add_search_sort_param(struct t_partition_state *partition_state, const char *sort, bool sortdesc, bool check_version);
bool mpd_client_add_search_group_param(struct mpd_connection *conn, enum mpd_tag_type tag);
sds get_search_expression_album(enum mpd_tag_type tag_albumartist, struct mpd_song *album,
sds get_search_expression_album(sds buffer, enum mpd_tag_type tag_albumartist, struct mpd_song *album,
const struct t_albums_config *album_config);
sds get_search_expression_album_disc(enum mpd_tag_type tag_albumartist, struct mpd_song *album,
sds get_search_expression_album_disc(sds buffer, enum mpd_tag_type tag_albumartist, struct mpd_song *album,
const char *disc, const struct t_albums_config *album_config);
sds escape_mpd_search_expression(sds buffer, const char *tag, const char *operator, const char *value);
#endif
2 changes: 1 addition & 1 deletion src/mpd_client/shortcuts.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ bool mpd_client_add_album_to_queue(struct t_partition_state *partition_state, st
*error = sdscat(*error, "Album not found");
return false;
}
sds expression = get_search_expression_album(partition_state->mpd_state->tag_albumartist,
sds expression = get_search_expression_album(sdsempty(), partition_state->mpd_state->tag_albumartist,
mpd_album, &partition_state->config->albums);
const char *sort = NULL;
bool sortdesc = false;
Expand Down
2 changes: 1 addition & 1 deletion src/mympd_api/albumart.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ sds mympd_api_albumart_getcover_by_album_id(struct t_partition_state *partition_
}

// search for one song in the album
sds expression = get_search_expression_album(partition_state->mpd_state->tag_albumartist,
sds expression = get_search_expression_album(sdsempty(), partition_state->mpd_state->tag_albumartist,
album, &partition_state->config->albums);

if (mpd_search_db_songs(partition_state->conn, false) == false ||
Expand Down
8 changes: 5 additions & 3 deletions src/mympd_api/browse.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ sds mympd_api_browse_album_detail(struct t_mympd_state *mympd_state, struct t_pa
JSONRPC_FACILITY_DATABASE, JSONRPC_SEVERITY_ERROR, "Album not found");
}

sds expression = get_search_expression_album(partition_state->mpd_state->tag_albumartist, mpd_album,
sds expression = get_search_expression_album(sdsempty(), partition_state->mpd_state->tag_albumartist, mpd_album,
&partition_state->config->albums);

if (mpd_search_db_songs(partition_state->conn, true) == false ||
Expand Down Expand Up @@ -279,6 +279,7 @@ sds mympd_api_browse_album_list(struct t_mympd_state *mympd_state, struct t_part
raxSeek(&iter, "$", NULL, 0);
iterator = &raxPrev;
}
sds album_exp = sdsempty();
while (iterator(&iter)) {
if (entity_count >= offset) {
if (entities_returned++) {
Expand All @@ -291,9 +292,9 @@ sds mympd_api_browse_album_list(struct t_mympd_state *mympd_state, struct t_part
buffer = tojson_char(buffer, "FirstSongUri", mpd_song_get_uri(album), false);
if (print_stickers == true) {
buffer = sdscatlen(buffer, ",", 1);
sds album_exp = get_search_expression_album(mympd_state->mpd_state->tag_albumartist, album, &mympd_state->config->albums);
album_exp = get_search_expression_album(album_exp, mympd_state->mpd_state->tag_albumartist, album, &mympd_state->config->albums);
buffer = mympd_api_sticker_get_print_batch(buffer, mympd_state->stickerdb, STICKER_TYPE_FILTER, album_exp, &tagcols->stickers);
FREE_SDS(album_exp);

}
buffer = sdscatlen(buffer, "}", 1);
}
Expand All @@ -303,6 +304,7 @@ sds mympd_api_browse_album_list(struct t_mympd_state *mympd_state, struct t_part
}
}
raxStop(&iter);
FREE_SDS(album_exp);
if (print_stickers == true) {
stickerdb_enter_idle(mympd_state->stickerdb);
}
Expand Down
7 changes: 4 additions & 3 deletions src/mympd_api/playlists.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,24 +356,25 @@ bool mympd_api_playlist_content_insert_albums(struct t_partition_state *partitio
}
struct t_list_node *current = albumids->head;
bool rc = true;
sds expression = sdsempty();
while (current != NULL) {
struct mpd_song *mpd_album = album_cache_get_album(album_cache, current->key);
if (mpd_album == NULL) {
rc = false;
*error = sdscat(*error, "Album not found");
break;
}
sds expression = get_search_expression_album(partition_state->mpd_state->tag_albumartist, mpd_album,
expression = get_search_expression_album(expression, partition_state->mpd_state->tag_albumartist, mpd_album,
&partition_state->config->albums);
const char *sort = NULL;
bool sortdesc = false;
rc = mpd_client_search_add_to_plist(partition_state, expression, plist, to, sort, sortdesc, error);
FREE_SDS(expression);
if (rc == false) {
break;
}
current = current->next;
}
FREE_SDS(expression);
return rc;
}

Expand Down Expand Up @@ -427,7 +428,7 @@ bool mympd_api_playlist_content_insert_album_disc(struct t_partition_state *part
*error = sdscat(*error, "Album not found");
return false;
}
sds expression = get_search_expression_album_disc(partition_state->mpd_state->tag_albumartist, mpd_album,
sds expression = get_search_expression_album_disc(sdsempty(), partition_state->mpd_state->tag_albumartist, mpd_album,
disc, &partition_state->config->albums);
const char *sort = NULL;
bool sortdesc = false;
Expand Down
4 changes: 2 additions & 2 deletions src/mympd_api/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ bool mympd_api_queue_insert_album_disc(struct t_partition_state *partition_state
*error = sdscat(*error, "Album not found");
return false;
}
sds expression = get_search_expression_album_disc(partition_state->mpd_state->tag_albumartist,
sds expression = get_search_expression_album_disc(sdsempty(), partition_state->mpd_state->tag_albumartist,
mpd_album, disc, &partition_state->config->albums);
const char *sort = NULL;
bool sortdesc = false;
Expand Down Expand Up @@ -568,7 +568,7 @@ bool mympd_api_queue_insert_album_range(struct t_partition_state *partition_stat
unsigned end_uint = end == -1
? UINT_MAX
: (unsigned)end;
sds expression = get_search_expression_album(partition_state->mpd_state->tag_albumartist,
sds expression = get_search_expression_album(sdsempty(), partition_state->mpd_state->tag_albumartist,
mpd_album, &partition_state->config->albums);
const char *sort = "Disc";
bool sortdesc = false;
Expand Down
2 changes: 1 addition & 1 deletion src/mympd_api/sticker.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ sds mympd_api_get_sticker_uri(struct t_mympd_state *mympd_state, sds uri, enum m
if (album != NULL) {
*type = STICKER_TYPE_FILTER;
FREE_SDS(uri);
return get_search_expression_album(mympd_state->mpd_state->tag_albumartist, album, &mympd_state->config->albums);
return get_search_expression_album(sdsempty(), mympd_state->mpd_state->tag_albumartist, album, &mympd_state->config->albums);
}
return uri;
}
Expand Down

0 comments on commit 09e84d5

Please sign in to comment.