1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-12-27 03:10:26 +00:00

Feat: replace static tag list with dynamic list, this adds support of all mpd tags to myMPD

This commit is contained in:
jcorporation 2018-10-09 22:51:47 +01:00
parent 6d549853b4
commit b8d422e564
6 changed files with 55 additions and 102 deletions

View File

@ -1535,16 +1535,14 @@ function parseSongDetails(obj) {
modal.getElementsByTagName('h1')[0].innerText = obj.data.title;
var songDetails = '';
for (var key in settings.tags) {
if (settings.tags[key] == true) {
var value = obj.data[key.toLowerCase()];
if (key == 'duration') {
for (var i = 0; i < settings.tags.length; i++) {
var value = obj.data[settings.tags[i].toLowerCase()];
if (settings.tags[i] == 'duration') {
var minutes = Math.floor(value / 60);
var seconds = value - minutes * 60;
value = minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
}
songDetails += '<tr><th>' + key + '</th><td>' + value + '</td></tr>';
}
songDetails += '<tr><th>' + settings.tags[i] + '</th><td>' + value + '</td></tr>';
}
songDetails += '<tr><th>Uri</th><td><a class="text-success" href="/library/' + obj.data.uri + '">' + obj.data.uri + '</a></td></tr>';
@ -1676,9 +1674,9 @@ function parseSmartPlaylist(obj) {
document.getElementById('saveSmartPlaylistSticker').classList.add('hide');
document.getElementById('saveSmartPlaylistNewest').classList.add('hide');
var tagList = '<option value="any">Any Tag</option>';
for (var key in settings.tags) {
if (settings.tags[key] == true && key != 'Track') {
tagList += '<option value="' + key + '">' + key + '</option>';
for (var i = 0; i < settings.tags.length; i++) {
if (settings.tags[i] != 'Track') {
tagList += '<option value="' + settings.tags[i] + '">' + settings.tags[i] + '</option>';
}
}
document.getElementById('selectSaveSmartPlaylistTag').innerHTML = tagList;
@ -2398,9 +2396,9 @@ function addTagList(x, any) {
var tagList = '';
if (any == true)
tagList += '<button type="button" class="btn btn-secondary btn-sm btn-block" data-tag="any">Any Tag</button>';
for (var key in settings.tags) {
if (settings.tags[key] == true && key != 'Track') {
tagList += '<button type="button" class="btn btn-secondary btn-sm btn-block" data-tag="' + key + '">' + key + '</button>';
for (var i = 0; i < settings.tags.length; i++) {
if (settings.tags[i] != 'Track') {
tagList += '<button type="button" class="btn btn-secondary btn-sm btn-block" data-tag="' + settings.tags[i] + '">' + settings.tags[i] + '</button>';
}
}
var tagListEl = document.getElementById(x);

View File

@ -10,8 +10,20 @@ int list_init(struct list *l) {
return 0;
}
int list_get_value(const struct list *l, char *data) {
int value = 0;
struct node *current = l->list;
while (current != NULL) {
if (strcmp(current->data, data) == 0) {
value = current->value;
break;
}
current = current->next;
}
return value;
}
struct node *list_node_at(const struct list * l, unsigned index) {
struct node *list_node_at(const struct list *l, unsigned index) {
/* if there's no data in the list, fail */
if (l->list == NULL) { return NULL; }
struct node * current = l->list;

View File

@ -15,7 +15,7 @@ int list_init(struct list *l);
int list_push(struct list *l, char *data, int value);
int list_replace(struct list *l, int pos, char *data, int value);
int list_free(struct list *l);
int list_get_value(const struct list *l, char *data);
int list_shuffle(struct list *l);
int list_swap_item(struct node *n1, struct node *n2);
struct node *list_node_at(const struct list * l, unsigned index);

View File

@ -33,7 +33,6 @@
#include <mpd/client.h>
#include "mpd_client.h"
#include "list.h"
#include "config.h"
#include "../dist/src/frozen/frozen.h"
@ -681,15 +680,6 @@ void mympd_mpd_features() {
// Defaults
mpd.feat_sticker = false;
mpd.tag_artist = false;
mpd.tag_album = false;
mpd.tag_album_artist = false;
mpd.tag_title = false;
mpd.tag_track = false;
mpd.tag_genre = false;
mpd.tag_date = false;
mpd.tag_composer = false;
mpd.tag_performer = false;
mpd_send_allowed_commands(mpd.conn);
while ((pair = mpd_recv_command_pair(mpd.conn)) != NULL) {
@ -709,69 +699,22 @@ void mympd_mpd_features() {
}
printf("MPD supported tags: ");
list_free(&mpd_tags);
mpd_send_list_tag_types(mpd.conn);
while ((pair = mpd_recv_tag_type_pair(mpd.conn)) != NULL) {
printf("%s ", pair->value);
if (strcmp(pair->value, "Artist") == 0)
mpd.tag_artist = true;
else if (strcmp(pair->value, "Album") == 0)
mpd.tag_album = true;
else if (strcmp(pair->value, "AlbumArtist") == 0)
mpd.tag_album_artist = true;
else if (strcmp(pair->value, "Title") == 0)
mpd.tag_title = true;
else if (strcmp(pair->value, "Track") == 0)
mpd.tag_track = true;
else if (strcmp(pair->value, "Genre") == 0)
mpd.tag_genre = true;
else if (strcmp(pair->value, "Date") == 0)
mpd.tag_date = true;
else if (strcmp(pair->value, "Composer") == 0)
mpd.tag_composer = true;
else if (strcmp(pair->value, "Performer") == 0)
mpd.tag_performer = true;
list_push(&mpd_tags, pair->value, 1);
mpd_return_pair(mpd.conn, pair);
}
mpd_response_finish(mpd.conn);
printf("\nmyMPD enabled tags: ");
list_free(&mympd_tags);
token = strtok(str, s);
while (token != NULL) {
if (strcmp(token, "Artist") == 0) {
if (mpd.tag_artist == true) printf("%s ", token);
else mpd.tag_artist = false;
}
else if (strcmp(token, "Album") == 0) {
if (mpd.tag_album == true) printf("%s ", token);
else mpd.tag_album = false;
}
else if (strcmp(token, "AlbumArtist") == 0) {
if (mpd.tag_album_artist == true) printf("%s ", token);
else mpd.tag_album_artist = false;
}
else if (strcmp(token, "Title") == 0) {
if (mpd.tag_title == true) printf("%s ", token);
else mpd.tag_title = false;
}
else if (strcmp(token, "Track") == 0) {
if (mpd.tag_track == true) printf("%s ", token);
else mpd.tag_track = false;
}
else if (strcmp(token, "Genre") == 0) {
if (mpd.tag_genre == true) printf("%s ", token);
else mpd.tag_genre = false;
}
else if (strcmp(token, "Date") == 0) {
if (mpd.tag_date == true) printf("%s ", token);
else mpd.tag_date = false;
}
else if (strcmp(token, "Composer") == 0) {
if (mpd.tag_composer == true) printf("%s ", token);
else mpd.tag_composer = false;
}
else if (strcmp(token, "Performer") == 0) {
if (mpd.tag_performer == true) printf("%s ", token);
else mpd.tag_performer = false;
if (list_get_value(&mpd_tags, token) == 1) {
list_push(&mympd_tags, token, 1);
printf("%s ", token);
}
token = strtok(NULL, s);
}
@ -1257,6 +1200,7 @@ int mympd_put_settings(char *buffer) {
struct mpd_status *status;
char *replaygain = strdup("");
int len;
int nr = 0;
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
status = mpd_run_status(mpd.conn);
@ -1279,9 +1223,7 @@ int mympd_put_settings(char *buffer) {
"mixrampdb: %f, mixrampdelay: %f, mpdhost: %Q, mpdport: %d, passwort_set: %B, "
"streamport: %d, coverimage: %Q, stickers: %B, mixramp: %B, smartpls: %B, maxElementsPerPage: %d, "
"replaygain: %Q, notificationWeb: %B, notificationPage: %B, jukeboxMode: %d, jukeboxPlaylist: %Q, jukeboxQueueLength: %d, "
"tags: { Artist: %B, Album: %B, AlbumArtist: %B, Title: %B, Track: %B, Genre: %B, Date: %B,"
"Composer: %B, Performer: %B }"
"}}",
"tags: [",
mpd_status_get_repeat(status),
mpd_status_get_single(status),
mpd_status_get_crossfade(status),
@ -1303,20 +1245,21 @@ int mympd_put_settings(char *buffer) {
mympd_state.notificationPage,
mympd_state.jukeboxMode,
mympd_state.jukeboxPlaylist,
mympd_state.jukeboxQueueLength,
mpd.tag_artist,
mpd.tag_album,
mpd.tag_album_artist,
mpd.tag_title,
mpd.tag_track,
mpd.tag_genre,
mpd.tag_date,
mpd.tag_composer,
mpd.tag_performer
mympd_state.jukeboxQueueLength
);
mpd_status_free(status);
free(replaygain);
struct node *current = mympd_tags.list;
while (current != NULL) {
if (nr ++)
len += json_printf(&out, ",");
len += json_printf(&out, "%Q", current->data);
current = current->next;
}
len += json_printf(&out, "]}}");
if (len > MAX_SIZE)
printf("Buffer truncated\n");
return len;

View File

@ -26,6 +26,7 @@
#define __MPD_CLIENT_H__
#include "../dist/src/mongoose/mongoose.h"
#include "list.h"
#define RETURN_ERROR_AND_RECOVER(X) do { \
printf("MPD X: %s\n", mpd_connection_get_error_message(mpd.conn)); \
@ -137,17 +138,11 @@ struct t_mpd {
const unsigned* protocol;
// Supported tags
bool feat_sticker;
bool tag_artist;
bool tag_album;
bool tag_album_artist;
bool tag_title;
bool tag_track;
bool tag_genre;
bool tag_date;
bool tag_composer;
bool tag_performer;
} mpd;
struct list mpd_tags;
struct list mympd_tags;
typedef struct {
long mpdport;
const char* mpdhost;

View File

@ -372,6 +372,9 @@ int main(int argc, char **argv) {
read_statefiles();
list_init(&mpd_tags);
list_init(&mympd_tags);
if (config.ssl == true)
mg_set_protocol_http_websocket(nc_http);
@ -388,6 +391,8 @@ int main(int argc, char **argv) {
mympd_idle(&mgr, 0);
}
mg_mgr_free(&mgr);
list_free(&mpd_tags);
list_free(&mympd_tags);
mympd_disconnect();
return EXIT_SUCCESS;
}