mirror of
https://github.com/SuperBFG7/ympd
synced 2025-01-14 19:25:49 +00:00
Feat: replace static tag list with dynamic list, this adds support of all mpd tags to myMPD
This commit is contained in:
parent
6d549853b4
commit
b8d422e564
@ -1535,16 +1535,14 @@ function parseSongDetails(obj) {
|
|||||||
modal.getElementsByTagName('h1')[0].innerText = obj.data.title;
|
modal.getElementsByTagName('h1')[0].innerText = obj.data.title;
|
||||||
|
|
||||||
var songDetails = '';
|
var songDetails = '';
|
||||||
for (var key in settings.tags) {
|
for (var i = 0; i < settings.tags.length; i++) {
|
||||||
if (settings.tags[key] == true) {
|
var value = obj.data[settings.tags[i].toLowerCase()];
|
||||||
var value = obj.data[key.toLowerCase()];
|
if (settings.tags[i] == 'duration') {
|
||||||
if (key == 'duration') {
|
|
||||||
var minutes = Math.floor(value / 60);
|
var minutes = Math.floor(value / 60);
|
||||||
var seconds = value - minutes * 60;
|
var seconds = value - minutes * 60;
|
||||||
value = minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
|
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>';
|
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('saveSmartPlaylistSticker').classList.add('hide');
|
||||||
document.getElementById('saveSmartPlaylistNewest').classList.add('hide');
|
document.getElementById('saveSmartPlaylistNewest').classList.add('hide');
|
||||||
var tagList = '<option value="any">Any Tag</option>';
|
var tagList = '<option value="any">Any Tag</option>';
|
||||||
for (var key in settings.tags) {
|
for (var i = 0; i < settings.tags.length; i++) {
|
||||||
if (settings.tags[key] == true && key != 'Track') {
|
if (settings.tags[i] != 'Track') {
|
||||||
tagList += '<option value="' + key + '">' + key + '</option>';
|
tagList += '<option value="' + settings.tags[i] + '">' + settings.tags[i] + '</option>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
document.getElementById('selectSaveSmartPlaylistTag').innerHTML = tagList;
|
document.getElementById('selectSaveSmartPlaylistTag').innerHTML = tagList;
|
||||||
@ -2398,9 +2396,9 @@ function addTagList(x, any) {
|
|||||||
var tagList = '';
|
var tagList = '';
|
||||||
if (any == true)
|
if (any == true)
|
||||||
tagList += '<button type="button" class="btn btn-secondary btn-sm btn-block" data-tag="any">Any Tag</button>';
|
tagList += '<button type="button" class="btn btn-secondary btn-sm btn-block" data-tag="any">Any Tag</button>';
|
||||||
for (var key in settings.tags) {
|
for (var i = 0; i < settings.tags.length; i++) {
|
||||||
if (settings.tags[key] == true && key != 'Track') {
|
if (settings.tags[i] != 'Track') {
|
||||||
tagList += '<button type="button" class="btn btn-secondary btn-sm btn-block" data-tag="' + key + '">' + key + '</button>';
|
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);
|
var tagListEl = document.getElementById(x);
|
||||||
|
14
src/list.c
14
src/list.c
@ -10,8 +10,20 @@ int list_init(struct list *l) {
|
|||||||
return 0;
|
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 there's no data in the list, fail */
|
||||||
if (l->list == NULL) { return NULL; }
|
if (l->list == NULL) { return NULL; }
|
||||||
struct node * current = l->list;
|
struct node * current = l->list;
|
||||||
|
@ -15,7 +15,7 @@ int list_init(struct list *l);
|
|||||||
int list_push(struct list *l, char *data, int value);
|
int list_push(struct list *l, char *data, int value);
|
||||||
int list_replace(struct list *l, int pos, char *data, int value);
|
int list_replace(struct list *l, int pos, char *data, int value);
|
||||||
int list_free(struct list *l);
|
int list_free(struct list *l);
|
||||||
|
int list_get_value(const struct list *l, char *data);
|
||||||
int list_shuffle(struct list *l);
|
int list_shuffle(struct list *l);
|
||||||
int list_swap_item(struct node *n1, struct node *n2);
|
int list_swap_item(struct node *n1, struct node *n2);
|
||||||
struct node *list_node_at(const struct list * l, unsigned index);
|
struct node *list_node_at(const struct list * l, unsigned index);
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
#include <mpd/client.h>
|
#include <mpd/client.h>
|
||||||
|
|
||||||
#include "mpd_client.h"
|
#include "mpd_client.h"
|
||||||
#include "list.h"
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "../dist/src/frozen/frozen.h"
|
#include "../dist/src/frozen/frozen.h"
|
||||||
|
|
||||||
@ -681,15 +680,6 @@ void mympd_mpd_features() {
|
|||||||
|
|
||||||
// Defaults
|
// Defaults
|
||||||
mpd.feat_sticker = false;
|
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);
|
mpd_send_allowed_commands(mpd.conn);
|
||||||
while ((pair = mpd_recv_command_pair(mpd.conn)) != NULL) {
|
while ((pair = mpd_recv_command_pair(mpd.conn)) != NULL) {
|
||||||
@ -709,69 +699,22 @@ void mympd_mpd_features() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("MPD supported tags: ");
|
printf("MPD supported tags: ");
|
||||||
|
list_free(&mpd_tags);
|
||||||
mpd_send_list_tag_types(mpd.conn);
|
mpd_send_list_tag_types(mpd.conn);
|
||||||
while ((pair = mpd_recv_tag_type_pair(mpd.conn)) != NULL) {
|
while ((pair = mpd_recv_tag_type_pair(mpd.conn)) != NULL) {
|
||||||
printf("%s ", pair->value);
|
printf("%s ", pair->value);
|
||||||
if (strcmp(pair->value, "Artist") == 0)
|
list_push(&mpd_tags, pair->value, 1);
|
||||||
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;
|
|
||||||
mpd_return_pair(mpd.conn, pair);
|
mpd_return_pair(mpd.conn, pair);
|
||||||
}
|
}
|
||||||
mpd_response_finish(mpd.conn);
|
mpd_response_finish(mpd.conn);
|
||||||
printf("\nmyMPD enabled tags: ");
|
printf("\nmyMPD enabled tags: ");
|
||||||
|
|
||||||
|
list_free(&mympd_tags);
|
||||||
token = strtok(str, s);
|
token = strtok(str, s);
|
||||||
while (token != NULL) {
|
while (token != NULL) {
|
||||||
if (strcmp(token, "Artist") == 0) {
|
if (list_get_value(&mpd_tags, token) == 1) {
|
||||||
if (mpd.tag_artist == true) printf("%s ", token);
|
list_push(&mympd_tags, token, 1);
|
||||||
else mpd.tag_artist = false;
|
printf("%s ", token);
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
token = strtok(NULL, s);
|
token = strtok(NULL, s);
|
||||||
}
|
}
|
||||||
@ -1257,6 +1200,7 @@ int mympd_put_settings(char *buffer) {
|
|||||||
struct mpd_status *status;
|
struct mpd_status *status;
|
||||||
char *replaygain = strdup("");
|
char *replaygain = strdup("");
|
||||||
int len;
|
int len;
|
||||||
|
int nr = 0;
|
||||||
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
|
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
|
||||||
|
|
||||||
status = mpd_run_status(mpd.conn);
|
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, "
|
"mixrampdb: %f, mixrampdelay: %f, mpdhost: %Q, mpdport: %d, passwort_set: %B, "
|
||||||
"streamport: %d, coverimage: %Q, stickers: %B, mixramp: %B, smartpls: %B, maxElementsPerPage: %d, "
|
"streamport: %d, coverimage: %Q, stickers: %B, mixramp: %B, smartpls: %B, maxElementsPerPage: %d, "
|
||||||
"replaygain: %Q, notificationWeb: %B, notificationPage: %B, jukeboxMode: %d, jukeboxPlaylist: %Q, jukeboxQueueLength: %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,"
|
"tags: [",
|
||||||
"Composer: %B, Performer: %B }"
|
|
||||||
"}}",
|
|
||||||
mpd_status_get_repeat(status),
|
mpd_status_get_repeat(status),
|
||||||
mpd_status_get_single(status),
|
mpd_status_get_single(status),
|
||||||
mpd_status_get_crossfade(status),
|
mpd_status_get_crossfade(status),
|
||||||
@ -1303,20 +1245,21 @@ int mympd_put_settings(char *buffer) {
|
|||||||
mympd_state.notificationPage,
|
mympd_state.notificationPage,
|
||||||
mympd_state.jukeboxMode,
|
mympd_state.jukeboxMode,
|
||||||
mympd_state.jukeboxPlaylist,
|
mympd_state.jukeboxPlaylist,
|
||||||
mympd_state.jukeboxQueueLength,
|
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
|
|
||||||
);
|
);
|
||||||
mpd_status_free(status);
|
mpd_status_free(status);
|
||||||
free(replaygain);
|
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)
|
if (len > MAX_SIZE)
|
||||||
printf("Buffer truncated\n");
|
printf("Buffer truncated\n");
|
||||||
return len;
|
return len;
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#define __MPD_CLIENT_H__
|
#define __MPD_CLIENT_H__
|
||||||
|
|
||||||
#include "../dist/src/mongoose/mongoose.h"
|
#include "../dist/src/mongoose/mongoose.h"
|
||||||
|
#include "list.h"
|
||||||
|
|
||||||
#define RETURN_ERROR_AND_RECOVER(X) do { \
|
#define RETURN_ERROR_AND_RECOVER(X) do { \
|
||||||
printf("MPD X: %s\n", mpd_connection_get_error_message(mpd.conn)); \
|
printf("MPD X: %s\n", mpd_connection_get_error_message(mpd.conn)); \
|
||||||
@ -137,17 +138,11 @@ struct t_mpd {
|
|||||||
const unsigned* protocol;
|
const unsigned* protocol;
|
||||||
// Supported tags
|
// Supported tags
|
||||||
bool feat_sticker;
|
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;
|
} mpd;
|
||||||
|
|
||||||
|
struct list mpd_tags;
|
||||||
|
struct list mympd_tags;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
long mpdport;
|
long mpdport;
|
||||||
const char* mpdhost;
|
const char* mpdhost;
|
||||||
|
@ -372,6 +372,9 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
read_statefiles();
|
read_statefiles();
|
||||||
|
|
||||||
|
list_init(&mpd_tags);
|
||||||
|
list_init(&mympd_tags);
|
||||||
|
|
||||||
if (config.ssl == true)
|
if (config.ssl == true)
|
||||||
mg_set_protocol_http_websocket(nc_http);
|
mg_set_protocol_http_websocket(nc_http);
|
||||||
|
|
||||||
@ -388,6 +391,8 @@ int main(int argc, char **argv) {
|
|||||||
mympd_idle(&mgr, 0);
|
mympd_idle(&mgr, 0);
|
||||||
}
|
}
|
||||||
mg_mgr_free(&mgr);
|
mg_mgr_free(&mgr);
|
||||||
|
list_free(&mpd_tags);
|
||||||
|
list_free(&mympd_tags);
|
||||||
mympd_disconnect();
|
mympd_disconnect();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user