Skip to content

Commit

Permalink
Feat: Show user defined stickers in lists #1368
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorporation committed Nov 3, 2024
1 parent ef812b8 commit ded57c4
Show file tree
Hide file tree
Showing 22 changed files with 142 additions and 111 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This is a small maintenance release.
- Feat: Support "stickernamestypes" command (MPD 0.24) #1092
- Feat: Support "tagtypes reset" command (MPD 0.24) #1367
- Feat: Generate smart playlists by user defined song stickers #1345
- Feat: Show user defined stickers in lists #1368
- Upd: libmympdclient 1.0.32
- Fix: Support "contains" and "starts_with" sticker operators

Expand Down
28 changes: 14 additions & 14 deletions docs/_includes/translating_status.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
- bg-BG: 1089 missing phrases
- es-AR: fully translated
- es-ES: 956 missing phrases
- es-VE: 944 missing phrases
- fi-FI: 941 missing phrases
- fr-FR: fully translated
- it-IT: 1 missing phrases
- ja-JP: 6 missing phrases
- ko-KR: fully translated
- nl-NL: fully translated
- pl-PL: 89 missing phrases
- ru-RU: 6 missing phrases
- zh-Hans: fully translated
- zh-Hant: 123 missing phrases
- bg-BG: 1090 missing phrases
- es-AR: 1 missing phrases
- es-ES: 957 missing phrases
- es-VE: 945 missing phrases
- fi-FI: 942 missing phrases
- fr-FR: 1 missing phrases
- it-IT: 2 missing phrases
- ja-JP: 7 missing phrases
- ko-KR: 1 missing phrases
- nl-NL: 1 missing phrases
- pl-PL: 90 missing phrases
- ru-RU: 7 missing phrases
- zh-Hans: 1 missing phrases
- zh-Hant: 124 missing phrases
20 changes: 19 additions & 1 deletion htdocs/js/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ function getDisplayTitle(name, title) {
* @returns {Node} the created node
*/
function printValue(key, value, userData) {
if (isEmptyTag(value) === true) {
if (isEmptyTag(value) === true &&
key !== 'userDefinedSticker')
{
return document.createTextNode('');
}
switch(key) {
Expand Down Expand Up @@ -389,6 +391,22 @@ function printValue(key, value, userData) {
}
return progressEl;
}
case "userDefinedSticker": {
if (userData.sticker === undefined) {
return document.createTextNode('no');
}
const div = elCreateEmpty('div', {});
for (const sticker in userData.sticker) {
div.appendChild(
elCreateNodes('span', {}, [
elCreateText('small', {}, sticker + ': '),
document.createTextNode(userData.sticker[sticker]),
elCreateEmpty('br', {})
])
);
}
return div;
}
case 'Artist':
case 'ArtistSort':
case 'AlbumArtist':
Expand Down
3 changes: 3 additions & 0 deletions htdocs/js/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,9 @@ function setFieldsStickers(tags, stickers) {
}
tags.push(sticker);
}
if (features.featStickerAdv === true) {
tags.push('userDefinedSticker');
}
}

/**
Expand Down
4 changes: 3 additions & 1 deletion htdocs/js/viewsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ function createListBody(body, data, list) {
)
);
}
else if (isEmptyTag(data[tag]) === false) {
else if (isEmptyTag(data[tag]) === false ||
tag === 'userDefinedSticker')
{
body.appendChild(
elCreateNodes('div', {"class": ["row"]}, [
elCreateTextTn('small', {"class": ["col-3"]}, tag),
Expand Down
1 change: 1 addition & 0 deletions src/i18n/extra_phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,4 @@ Last skipped
Play count
Rating
Skip count
userDefinedSticker
3 changes: 2 additions & 1 deletion src/i18n/json/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -1235,5 +1235,6 @@
"tags": "Tags",
"url_resolved": "URL",
"votes": "Stimmen",
"wasapi": "Windows Audio Session API"
"wasapi": "Windows Audio Session API",
"userDefinedSticker": "Benutzerdefinierte Sticker"
}
3 changes: 2 additions & 1 deletion src/i18n/json/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,6 @@
"snapcast": "Snapcast",
"sndio": "SNDIO",
"solaris": "Solaris",
"wasapi": "Windows Audio Session API"
"wasapi": "Windows Audio Session API",
"userDefinedSticker": "User defined stickers"
}
18 changes: 9 additions & 9 deletions src/i18n/json/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"default": {"desc":"Browser default", "missingPhrases": 0},
"de-DE": {"desc":"Deutsch (de-DE)", "missingPhrases": 0},
"en-US": {"desc":"English (en-US)", "missingPhrases": 0},
"es-AR": {"desc":"Español (es-AR)", "missingPhrases": 0},
"fr-FR": {"desc":"Français (fr-FR)", "missingPhrases": 0},
"it-IT": {"desc":"Italiano (it-IT)", "missingPhrases": 1},
"ja-JP": {"desc":"日本語 (ja-JP)", "missingPhrases": 6},
"ko-KR": {"desc":"한국어 (ko-KR)", "missingPhrases": 0},
"nl-NL": {"desc":"Nederlands (nl-NL)", "missingPhrases": 0},
"pl-PL": {"desc":"Polish (pl-PL)", "missingPhrases": 89},
"ru-RU": {"desc":"Russian (ru-RU)", "missingPhrases": 6},
"zh-Hans": {"desc":"简体中文 (zh-Hans)", "missingPhrases": 0}
"es-AR": {"desc":"Español (es-AR)", "missingPhrases": 1},
"fr-FR": {"desc":"Français (fr-FR)", "missingPhrases": 1},
"it-IT": {"desc":"Italiano (it-IT)", "missingPhrases": 2},
"ja-JP": {"desc":"日本語 (ja-JP)", "missingPhrases": 7},
"ko-KR": {"desc":"한국어 (ko-KR)", "missingPhrases": 1},
"nl-NL": {"desc":"Nederlands (nl-NL)", "missingPhrases": 1},
"pl-PL": {"desc":"Polish (pl-PL)", "missingPhrases": 90},
"ru-RU": {"desc":"Russian (ru-RU)", "missingPhrases": 7},
"zh-Hans": {"desc":"简体中文 (zh-Hans)", "missingPhrases": 1}
}
1 change: 1 addition & 0 deletions src/i18n/json/phrases.json
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,7 @@
{"term":"stop only"},
{"term":"tags"},
{"term":"url_resolved"},
{"term":"userDefinedSticker"},
{"term":"votes"},
{"term":"wasapi"}
]
8 changes: 6 additions & 2 deletions src/lib/jsonrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1240,13 +1240,13 @@ static const char *jsonrpc_event_name(enum jsonrpc_events event) {
}

/**
* Iteration callback to populate a t_tags struct
* Iteration callback to populate a t_fields struct
* @param path json path
* @param key not used
* @param value value to parse as mpd tag
* @param vtype mjson value type
* @param vcb not used - we validate directly
* @param userdata void pointer to t_tags struct
* @param userdata void pointer to t_fields struct
* @param error pointer to t_jsonrpc_parse_error
* @return true on success else false
*/
Expand All @@ -1267,6 +1267,10 @@ static bool icb_json_get_field(const char *path, sds key, sds value, int vtype,
enum mympd_sticker_names sticker = sticker_name_parse(value);
if (sticker != STICKER_UNKNOWN) {
fields->stickers.stickers[fields->stickers.len++] = sticker;
return true;
}
if (strcmp(value, "userDefinedSticker") == 0) {
fields->stickers.user_defined = true;
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static const char *mympd_fields[]={
"Name", "Pos", "Duration", "Type", "Priority", "LastPlayed", "Filename", "Filetype",
"AudioFormat", "Last-Modified", "Lyrics", "Added", "Thumbnail",
// Columns for stickers
"playCount", "skipCount", "lastPlayed", "lastSkipped", "like", "rating", "elapsed",
"playCount", "skipCount", "lastPlayed", "lastSkipped", "like", "rating", "elapsed", "userDefinedSticker",
// Columns for webradiodb
"Country", "Region", "Description", "Genres", "Homepage", "Languages", "Name", "StreamUri",
"Codec", "Bitrate",
Expand Down
15 changes: 15 additions & 0 deletions src/mpd_client/stickerdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,21 @@ bool stickerdb_remove(struct t_stickerdb_state *stickerdb, enum mympd_sticker_ty
return rc;
}

/**
* Checks if stickers should be fetched
* @param featSticker Flag indicating enabled sticker support
* @param stickers Pointer to t_stickers struct
* @return bool true if stickers should be fetched, else false
*/
bool check_get_sticker(bool featSticker, const struct t_stickers *stickers) {
if (featSticker == false ||
(stickers->len == 0 && stickers->user_defined == false))
{
return false;
}
return true;
}

// Private functions

/**
Expand Down
1 change: 1 addition & 0 deletions src/mpd_client/stickerdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ bool stickerdb_set_rating(struct t_stickerdb_state *stickerdb, enum mympd_sticke
bool stickerdb_remove(struct t_stickerdb_state *stickerdb, enum mympd_sticker_type type, const char *uri, const char *name);

bool stickerdb_get_names(struct t_stickerdb_state *stickerdb, enum mympd_sticker_type type, struct t_list *sticker_names);
bool check_get_sticker(bool featSticker, const struct t_stickers *stickers);

#endif
19 changes: 7 additions & 12 deletions src/mympd_api/browse.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,15 @@ sds mympd_api_browse_album_detail(struct t_mympd_state *mympd_state, struct t_pa
album_cache_set_disc_count(mpd_album, 0);
album_cache_set_song_count(mpd_album, 0);
}
bool print_stickers = check_get_sticker(partition_state->mpd_state->feat.stickers, &tagcols->stickers);
if (print_stickers == true) {
stickerdb_exit_idle(mympd_state->stickerdb);
}
if (mpd_search_commit(partition_state->conn)) {
buffer = jsonrpc_respond_start(buffer, cmd_id, request_id);
buffer = sdscat(buffer, "\"data\":[");

struct mpd_song *song;
if (partition_state->mpd_state->feat.stickers == true &&
tagcols->stickers.len > 0)
{
stickerdb_exit_idle(mympd_state->stickerdb);
}
while ((song = mpd_recv_song(partition_state->conn)) != NULL) {
if (entities_returned++) {
buffer = sdscatlen(buffer, ",", 1);
Expand All @@ -111,9 +110,7 @@ sds mympd_api_browse_album_detail(struct t_mympd_state *mympd_state, struct t_pa
}
buffer = sdscat(buffer, "{\"Type\": \"song\",");
buffer = print_song_tags(buffer, partition_state->mpd_state, &tagcols->mpd_tags, song);
if (partition_state->mpd_state->feat.stickers == true &&
tagcols->stickers.len > 0)
{
if (print_stickers == true) {
struct t_sticker sticker;
stickerdb_get_all_batch(mympd_state->stickerdb, STICKER_TYPE_SONG, mpd_song_get_uri(song), &sticker, false);
buffer = mympd_api_sticker_print(buffer, &sticker, &tagcols->stickers);
Expand All @@ -137,9 +134,7 @@ sds mympd_api_browse_album_detail(struct t_mympd_state *mympd_state, struct t_pa
}
}
mpd_response_finish(partition_state->conn);
if (partition_state->mpd_state->feat.stickers == true &&
tagcols->stickers.len > 0)
{
if (print_stickers == true) {
stickerdb_enter_idle(mympd_state->stickerdb);
}
if (mympd_check_error_and_recover_respond(partition_state, &buffer, cmd_id, request_id, "mpd_search_commit") == false) {
Expand Down Expand Up @@ -263,7 +258,7 @@ sds mympd_api_browse_album_list(struct t_mympd_state *mympd_state, struct t_part
FREE_SDS(key);

//print album list
bool print_stickers = partition_state->mpd_state->feat.stickers == true && tagcols->stickers.len > 0;
bool print_stickers = check_get_sticker(partition_state->mpd_state->feat.stickers, &tagcols->stickers);
if (print_stickers == true) {
stickerdb_exit_idle(mympd_state->stickerdb);
}
Expand Down
13 changes: 4 additions & 9 deletions src/mympd_api/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,8 @@ sds mympd_api_browse_filesystem(struct t_mympd_state *mympd_state, struct t_part
raxIterator iter;
raxStart(&iter, entity_list);
raxSeek(&iter, "^", NULL, 0);
if (partition_state->mpd_state->feat.stickers == true &&
tagcols->stickers.len > 0)
{
bool print_stickers = check_get_sticker(partition_state->mpd_state->feat.stickers, &tagcols->stickers);
if (print_stickers == true) {
stickerdb_exit_idle(mympd_state->stickerdb);
}
while (raxNext(&iter)) {
Expand All @@ -157,9 +156,7 @@ sds mympd_api_browse_filesystem(struct t_mympd_state *mympd_state, struct t_part
basename_uri(filename);
buffer = tojson_sds(buffer, "Filename", filename, false);
FREE_SDS(filename);
if (partition_state->mpd_state->feat.stickers == true &&
tagcols->stickers.len > 0)
{
if (print_stickers == true) {
buffer = mympd_api_sticker_get_print_batch(buffer, mympd_state->stickerdb, STICKER_TYPE_SONG, mpd_song_get_uri(song), &tagcols->stickers);
}
buffer = sdscatlen(buffer, "}", 1);
Expand Down Expand Up @@ -194,9 +191,7 @@ sds mympd_api_browse_filesystem(struct t_mympd_state *mympd_state, struct t_part
entity_count++;
}
raxStop(&iter);
if (partition_state->mpd_state->feat.stickers == true &&
tagcols->stickers.len > 0)
{
if (print_stickers == true) {
stickerdb_enter_idle(mympd_state->stickerdb);
}
buffer = sdscatlen(buffer, "],", 2);
Expand Down
30 changes: 17 additions & 13 deletions src/mympd_api/jukebox.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

#include "src/lib/jsonrpc.h"
#include "src/lib/log.h"
#include "src/lib/sds_extras.h"
#include "src/lib/search.h"
#include "src/mpd_client/errorhandler.h"
#include "src/mpd_client/jukebox.h"
#include "src/mpd_client/search.h"
#include "src/mpd_client/stickerdb.h"
#include "src/mpd_client/tags.h"
#include "src/mympd_api/sticker.h"
Expand Down Expand Up @@ -123,15 +125,14 @@ sds mympd_api_jukebox_list(struct t_partition_state *partition_state, struct t_s
struct t_list *expr_list = parse_search_expression_to_list(expression, SEARCH_TYPE_SONG);
buffer = jsonrpc_respond_start(buffer, cmd_id, request_id);
buffer = sdscat(buffer, "\"data\":[");
bool print_stickers = check_get_sticker(partition_state->mpd_state->feat.stickers, &tagcols->stickers);
if (print_stickers == true) {
stickerdb_exit_idle(stickerdb);
}
if (partition_state->jukebox.mode == JUKEBOX_ADD_SONG ||
partition_state->jukebox.mode == JUKEBOX_SCRIPT)
{
struct t_list_node *current = partition_state->jukebox.queue->head;
if (partition_state->mpd_state->feat.stickers == true &&
tagcols->stickers.len > 0)
{
stickerdb_exit_idle(stickerdb);
}
while (current != NULL) {
if (mpd_send_list_meta(partition_state->conn, current->key)) {
struct mpd_song *song;
Expand All @@ -146,9 +147,7 @@ sds mympd_api_jukebox_list(struct t_partition_state *partition_state, struct t_s
buffer = sdscat(buffer, "{\"Type\": \"song\",");
buffer = tojson_uint(buffer, "Pos", entity_count, true);
buffer = print_song_tags(buffer, partition_state->mpd_state, &tagcols->mpd_tags, song);
if (partition_state->mpd_state->feat.stickers == true &&
tagcols->stickers.len > 0)
{
if (print_stickers == true) {
buffer = mympd_api_sticker_get_print_batch(buffer, stickerdb, STICKER_TYPE_SONG, mpd_song_get_uri(song), &tagcols->stickers);
}
buffer = sdscatlen(buffer, "}", 1);
Expand All @@ -163,14 +162,10 @@ sds mympd_api_jukebox_list(struct t_partition_state *partition_state, struct t_s
mympd_check_error_and_recover(partition_state, NULL, "mpd_send_list_meta");
current = current->next;
}
if (partition_state->mpd_state->feat.stickers == true &&
tagcols->stickers.len > 0)
{
stickerdb_enter_idle(stickerdb);
}
}
else if (partition_state->jukebox.mode == JUKEBOX_ADD_ALBUM) {
struct t_list_node *current = partition_state->jukebox.queue->head;
sds album_exp = sdsempty();
while (current != NULL) {
struct mpd_song *album = (struct mpd_song *)current->user_data;
if (search_expression_song(album, expr_list, &tagcols->mpd_tags) == true) {
Expand All @@ -183,13 +178,22 @@ sds mympd_api_jukebox_list(struct t_partition_state *partition_state, struct t_s
buffer = sdscat(buffer, "{\"Type\": \"album\",");
buffer = tojson_uint(buffer, "Pos", entity_count, true);
buffer = print_album_tags(buffer, partition_state->mpd_state, &partition_state->mpd_state->tags_album, album);
if (print_stickers == true) {
buffer = sdscatlen(buffer, ",", 1);
album_exp = get_search_expression_album(album_exp, partition_state->mpd_state->tag_albumartist, album, &partition_state->config->albums);
buffer = mympd_api_sticker_get_print_batch(buffer, stickerdb, STICKER_TYPE_FILTER, album_exp, &tagcols->stickers);
}
buffer = sdscatlen(buffer, "}", 1);
}
entities_found++;
}
entity_count++;
current = current->next;
}
FREE_SDS(album_exp);
}
if (print_stickers == true) {
stickerdb_enter_idle(stickerdb);
}
free_search_expression_list(expr_list);
buffer = sdscatlen(buffer, "],", 2);
Expand Down
Loading

0 comments on commit ded57c4

Please sign in to comment.