mirror of
https://github.com/SuperBFG7/ympd
synced 2024-12-25 02:20:27 +00:00
Feat: add config options for stickerusage and mixramp settings
This commit is contained in:
parent
492f008555
commit
988a315f45
@ -25,3 +25,9 @@ coverimage = folder.jpg
|
||||
|
||||
#myMPD statefile
|
||||
statefile = /var/lib/mympd/mympd.state
|
||||
|
||||
#Enable mixramp settings
|
||||
mixramp = false
|
||||
|
||||
#Enable usage of mpd stickers for play statistics and voting
|
||||
stickers = true
|
||||
|
@ -84,15 +84,17 @@
|
||||
<h4 id="currentArtist" data-href="{'cmd': 'artistClick', 'options': []}"></h4>
|
||||
<small>Album</small>
|
||||
<h4 id="currentAlbum"></h4>
|
||||
<small>Vote</small><br/>
|
||||
<div class="btn-group">
|
||||
<button id="btnVoteDown" data-href="{'cmd': 'voteSong', 'options': ['0']}" class="btn btn-sm btn-light material-icons">thumb_down</button>
|
||||
<button id="btnVoteUp" data-href="{'cmd': 'voteSong', 'options': ['2']}" class="btn btn-sm btn-light material-icons">thumb_up</button>
|
||||
<div class="stickers">
|
||||
<small>Vote</small><br/>
|
||||
<div class="btn-group">
|
||||
<button id="btnVoteDown" data-href="{'cmd': 'voteSong', 'options': ['0']}" class="btn btn-sm btn-light material-icons">thumb_down</button>
|
||||
<button id="btnVoteUp" data-href="{'cmd': 'voteSong', 'options': ['2']}" class="btn btn-sm btn-light material-icons">thumb_up</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer card-footer-playback">
|
||||
<div class="d-flex">
|
||||
<div class="d-flex align-items-center">
|
||||
<button data-href="{'cmd':'clickPlay','options':[]}" class="mr-1 ml-1 btn btn-light material-icons btnPlay progressBarPlay">pause</button>
|
||||
<input type="range" min="0" max="100" step="1" class="mr-1 ml-1 form-control-range flex-grow-1" id="progressBar">
|
||||
<div class="btn ml-1 mr-1" id="counter"> </div>
|
||||
@ -673,7 +675,7 @@
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="row mixramp">
|
||||
<div class="form-group input-group col-md-6 border-secondary">
|
||||
<div class="input-group-prepend">
|
||||
<div class="input-group-text bg-secondary text-light border-secondary">Mixramp DB</div>
|
||||
@ -798,11 +800,11 @@
|
||||
<tr data-name="genre"><th>Genre</th><td></td></tr>
|
||||
<tr data-name="date"><th>Date</th><td></td></tr>
|
||||
<tr data-name="uri"><th>Uri</th><td></td></tr>
|
||||
<tr><th colspan="2">Statistics</th></tr>
|
||||
<tr data-name="playCount"><th>Play count</th><td></td></tr>
|
||||
<tr data-name="skipCount"><th>Skip count</th><td></td></tr>
|
||||
<tr data-name="lastPlayed"><th>Last played</th><td></td></tr>
|
||||
<tr data-name="like"><th>Like</th><td></td></tr>
|
||||
<tr class="stickers"><th colspan="2">Statistics</th></tr>
|
||||
<tr class="stickers" data-name="playCount"><th>Play count</th><td></td></tr>
|
||||
<tr class="stickers" data-name="skipCount"><th>Skip count</th><td></td></tr>
|
||||
<tr class="stickers" data-name="lastPlayed"><th>Last played</th><td></td></tr>
|
||||
<tr class="stickers" data-name="like"><th>Like</th><td></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -500,6 +500,10 @@ function appInit() {
|
||||
|
||||
window.addEventListener('hashchange', appRoute, false);
|
||||
|
||||
window.addEventListener('focus', function() {
|
||||
sendAPI({"cmd":"MPD_API_GET_STATE"}, parseState);
|
||||
}, false);
|
||||
|
||||
document.addEventListener('keydown', function(event) {
|
||||
if (event.target.tagName == 'INPUT')
|
||||
return;
|
||||
@ -799,6 +803,19 @@ function parseSettings(obj) {
|
||||
|
||||
toggleBtn('btnnotifyPage', obj.data.notificationPage);
|
||||
|
||||
var stickerEls = document.getElementsByClassName('stickers');
|
||||
var stickerEls_len = stickerEls.length;
|
||||
var displayStickers = obj.data.stickers == true ? '' : 'none';
|
||||
for (var i = 0; i < stickerEls_len; i++) {
|
||||
stickerEls[i].style.display = displayStickers;
|
||||
}
|
||||
|
||||
if (obj.data.mixramp == true) {
|
||||
document.getElementsByClassName('mixramp')[0].style.display = '';
|
||||
} else {
|
||||
document.getElementsByClassName('mixramp')[0].style.display = 'none';
|
||||
}
|
||||
|
||||
settings=obj.data;
|
||||
settings.mpdstream = 'http://';
|
||||
if (settings.mpdhost == '127.0.0.1' || settings.mpdhost == 'localhost')
|
||||
@ -1372,11 +1389,15 @@ function replaceQueue(type, uri, name) {
|
||||
}
|
||||
|
||||
function songClick() {
|
||||
songDetails(domCache.currentTrack.getAttribute('data-uri'));
|
||||
var uri = domCache.currentTrack.getAttribute('data-uri')
|
||||
if (uri != '')
|
||||
songDetails(uri);
|
||||
}
|
||||
|
||||
function artistClick() {
|
||||
appGoto('Browse', 'Database', 'Album', '0/-/' + document.getElementById('currentArtist').innerText);
|
||||
var albumartist = document.getElementById('currentArtist').getAttribute('data-albumartist');
|
||||
if (albumartist != '')
|
||||
appGoto('Browse', 'Database', 'Album', '0/-/' + albumartist);
|
||||
}
|
||||
|
||||
function songDetails(uri) {
|
||||
@ -1919,6 +1940,7 @@ function songChange(obj) {
|
||||
htmlNotification += obj.data.artist;
|
||||
pageTitle += obj.data.artist + ' - ';
|
||||
document.getElementById('currentArtist').innerText = obj.data.artist;
|
||||
document.getElementById('currentArtist').setAttribute('data-albumartist', obj.data.albumartist);
|
||||
} else {
|
||||
document.getElementById('currentArtist').innerText = '';
|
||||
}
|
||||
|
123
src/mpd_client.c
123
src/mpd_client.c
@ -80,11 +80,16 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg) {
|
||||
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"error\", \"data\": \"Unknown request\"}");
|
||||
break;
|
||||
case MPD_API_LIKE:
|
||||
je = json_scanf(msg.p, msg.len, "{data: {uri: %Q, like: %d}}", &p_charbuf1, &uint_buf1);
|
||||
if (je == 2) {
|
||||
mympd_like_song_uri(p_charbuf1, uint_buf1);
|
||||
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}");
|
||||
free(p_charbuf1);
|
||||
if (config.stickers) {
|
||||
je = json_scanf(msg.p, msg.len, "{data: {uri: %Q, like: %d}}", &p_charbuf1, &uint_buf1);
|
||||
if (je == 2) {
|
||||
mympd_like_song_uri(p_charbuf1, uint_buf1);
|
||||
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}");
|
||||
free(p_charbuf1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"error\", \"data\": \"MPD stickers are disabled\"}");
|
||||
}
|
||||
break;
|
||||
case MPD_API_GET_STATE:
|
||||
@ -119,13 +124,15 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg) {
|
||||
if (je == 1)
|
||||
mpd_run_crossfade(mpd.conn, uint_buf1);
|
||||
|
||||
je = json_scanf(msg.p, msg.len, "{data: {mixrampdb: %f}}", &float_buf);
|
||||
if (je == 1)
|
||||
mpd_run_mixrampdb(mpd.conn, float_buf);
|
||||
if (config.mixramp) {
|
||||
je = json_scanf(msg.p, msg.len, "{data: {mixrampdb: %f}}", &float_buf);
|
||||
if (je == 1)
|
||||
mpd_run_mixrampdb(mpd.conn, float_buf);
|
||||
|
||||
je = json_scanf(msg.p, msg.len, "{data: {mixrampdelay: %f}}", &float_buf);
|
||||
if (je == 1)
|
||||
mpd_run_mixrampdelay(mpd.conn, float_buf);
|
||||
je = json_scanf(msg.p, msg.len, "{data: {mixrampdelay: %f}}", &float_buf);
|
||||
if (je == 1)
|
||||
mpd_run_mixrampdelay(mpd.conn, float_buf);
|
||||
}
|
||||
|
||||
je = json_scanf(msg.p, msg.len, "{data: {replaygain:%Q}}", &p_charbuf1);
|
||||
if (je == 1) {
|
||||
@ -163,7 +170,8 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg) {
|
||||
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}");
|
||||
break;
|
||||
case MPD_API_SET_NEXT:
|
||||
mympd_count_song_id(mpd.song_id, "skipCount", 1);
|
||||
if (config.stickers)
|
||||
mympd_count_song_id(mpd.song_id, "skipCount", 1);
|
||||
mpd_run_next(mpd.conn);
|
||||
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}");
|
||||
break;
|
||||
@ -682,8 +690,10 @@ void mympd_parse_idle(struct mg_mgr *s) {
|
||||
break;
|
||||
case MPD_IDLE_PLAYER:
|
||||
len = mympd_put_state(mpd.buf, &mpd.song_id, &mpd.next_song_id, &mpd.queue_version);
|
||||
mympd_count_song_id(mpd.song_id, "playCount", 1);
|
||||
mympd_last_played_song_id(mpd.song_id);
|
||||
if (config.stickers) {
|
||||
mympd_count_song_id(mpd.song_id, "playCount", 1);
|
||||
mympd_last_played_song_id(mpd.song_id);
|
||||
}
|
||||
break;
|
||||
case MPD_IDLE_MIXER:
|
||||
len = mympd_put_state(mpd.buf, &mpd.song_id, &mpd.next_song_id, &mpd.queue_version);
|
||||
@ -741,7 +751,7 @@ int mympd_put_state(char *buffer, int *current_song_id, int *next_song_id, unsig
|
||||
audioformat = mpd_status_get_audio_format(status);
|
||||
|
||||
len = json_printf(&out,"{type: update_state, data: {"
|
||||
"state:%d, volume:%d, songPos: %d, elapsedTime: %d, "
|
||||
"state: %d, volume: %d, songPos: %d, elapsedTime: %d, "
|
||||
"totalTime: %d, currentSongId: %d, kbitrate: %d, "
|
||||
"audioFormat: { sampleRate: %d, bits: %d, channels: %d}, "
|
||||
"queueLength: %d, nextSongPos: %d, nextSongId: %d, "
|
||||
@ -796,12 +806,12 @@ int mympd_put_settings(char *buffer) {
|
||||
char *content = json_fread(config.statefile);
|
||||
je = json_scanf(content, strlen(content), "{notificationWeb: %d, notificationPage: %d}", &state.a, &state.b);
|
||||
if (je != 2) {
|
||||
state.a=0;
|
||||
state.b=0;
|
||||
state.a = 0;
|
||||
state.b = 0;
|
||||
}
|
||||
} else {
|
||||
state.a=0;
|
||||
state.b=0;
|
||||
state.a = 0;
|
||||
state.b = 0;
|
||||
}
|
||||
|
||||
status = mpd_run_status(mpd.conn);
|
||||
@ -821,8 +831,9 @@ int mympd_put_settings(char *buffer) {
|
||||
len = json_printf(&out,
|
||||
"{type: settings, data: {"
|
||||
"repeat: %d, single: %d, crossfade: %d, consume: %d, random: %d, "
|
||||
"mixrampdb: %f, mixrampdelay: %f, mpdhost : %Q, mpdport: %d, passwort_set: %B, "
|
||||
"streamport: %d, coverimage: %Q, max_elements_per_page: %d, replaygain: %Q,"
|
||||
"mixrampdb: %f, mixrampdelay: %f, mpdhost: %Q, mpdport: %d, passwort_set: %B, "
|
||||
"streamport: %d, coverimage: %Q, stickers: %B, mixramp: %B, "
|
||||
"max_elements_per_page: %d, replaygain: %Q,"
|
||||
"notificationWeb: %d, notificationPage: %d"
|
||||
"}}",
|
||||
mpd_status_get_repeat(status),
|
||||
@ -834,9 +845,11 @@ int mympd_put_settings(char *buffer) {
|
||||
mpd_status_get_mixrampdelay(status),
|
||||
config.mpdhost,
|
||||
config.mpdport,
|
||||
config.mpdpass ? "true" : "false",
|
||||
config.mpdpass ? "true" : "false",
|
||||
config.streamport,
|
||||
config.coverimage,
|
||||
config.stickers,
|
||||
config.mixramp,
|
||||
MAX_ELEMENTS_PER_PAGE,
|
||||
replaygain,
|
||||
state.a,
|
||||
@ -885,23 +898,22 @@ int mympd_get_cover(const char *uri, char *cover, int cover_len) {
|
||||
char *path = strdup(uri);
|
||||
int len;
|
||||
if (strncasecmp("http:", path, 5) == 0 ) {
|
||||
len=snprintf(cover,cover_len, "/assets/coverimage-httpstream.png");
|
||||
len = snprintf(cover, cover_len, "/assets/coverimage-httpstream.png");
|
||||
}
|
||||
else {
|
||||
dirname(path);
|
||||
snprintf(cover,cover_len,"%s/library/%s/%s", SRC_PATH, path, config.coverimage);
|
||||
if ( access(cover, F_OK ) == -1 ) {
|
||||
len = snprintf(cover, cover_len, "/assets/coverimage-notavailable.png");
|
||||
} else {
|
||||
len = snprintf(cover, cover_len, "/library/%s/%s", path, config.coverimage);
|
||||
}
|
||||
dirname(path);
|
||||
snprintf(cover, cover_len, "%s/library/%s/%s", SRC_PATH, path, config.coverimage);
|
||||
if ( access(cover, F_OK ) == -1 ) {
|
||||
len = snprintf(cover, cover_len, "/assets/coverimage-notavailable.png");
|
||||
} else {
|
||||
len = snprintf(cover, cover_len, "/library/%s/%s", path, config.coverimage);
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int mympd_put_current_song(char *buffer) {
|
||||
struct mpd_song *song;
|
||||
t_sticker *sticker = (t_sticker *) malloc(sizeof(t_sticker));
|
||||
int len;
|
||||
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
|
||||
char cover[500];
|
||||
@ -913,11 +925,10 @@ int mympd_put_current_song(char *buffer) {
|
||||
}
|
||||
|
||||
mympd_get_cover(mpd_song_get_uri(song), cover, 500);
|
||||
mympd_get_sticker(mpd_song_get_uri(song), sticker);
|
||||
|
||||
len = json_printf(&out,"{type: song_change, data: { pos: %d, title: %Q, "
|
||||
len = json_printf(&out,"{type: song_change, data: {pos: %d, title: %Q, "
|
||||
"artist: %Q, album: %Q, uri: %Q, currentSongId: %d, albumartist: %Q, "
|
||||
"duration: %d, cover: %Q, playCount: %d, skipCount: %d, like: %d, lastPlayed: %d}}",
|
||||
"duration: %d, cover: %Q",
|
||||
mpd_song_get_pos(song),
|
||||
mympd_get_tag(song, MPD_TAG_TITLE),
|
||||
mympd_get_tag(song, MPD_TAG_ARTIST),
|
||||
@ -926,16 +937,24 @@ int mympd_put_current_song(char *buffer) {
|
||||
mpd.song_id,
|
||||
mympd_get_tag(song, MPD_TAG_ALBUM_ARTIST),
|
||||
mpd_song_get_duration(song),
|
||||
cover,
|
||||
sticker->playCount,
|
||||
sticker->skipCount,
|
||||
sticker->like,
|
||||
sticker->lastPlayed
|
||||
cover
|
||||
);
|
||||
|
||||
mpd_song_free(song);
|
||||
|
||||
mpd_response_finish(mpd.conn);
|
||||
free(sticker);
|
||||
|
||||
if (config.stickers) {
|
||||
t_sticker *sticker = (t_sticker *) malloc(sizeof(t_sticker));
|
||||
mympd_get_sticker(mpd_song_get_uri(song), sticker);
|
||||
len += json_printf(&out, ", playCount: %d, skipCount: %d, like: %d, lastPlayed: %d",
|
||||
sticker->playCount,
|
||||
sticker->skipCount,
|
||||
sticker->like,
|
||||
sticker->lastPlayed
|
||||
);
|
||||
free(sticker);
|
||||
}
|
||||
len += json_printf(&out, "}}");
|
||||
mpd_song_free(song);
|
||||
|
||||
if (len > MAX_SIZE)
|
||||
fprintf(stderr, "Buffer truncated\n");
|
||||
@ -948,7 +967,6 @@ int mympd_put_songdetails(char *buffer, char *uri) {
|
||||
int len;
|
||||
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
|
||||
char cover[500];
|
||||
t_sticker *sticker = (t_sticker *) malloc(sizeof(t_sticker));
|
||||
|
||||
len = json_printf(&out, "{type: song_details, data: {");
|
||||
mpd_send_list_all_meta(mpd.conn, uri);
|
||||
@ -973,14 +991,17 @@ int mympd_put_songdetails(char *buffer, char *uri) {
|
||||
}
|
||||
mpd_response_finish(mpd.conn);
|
||||
|
||||
mympd_get_sticker(uri, sticker);
|
||||
len += json_printf(&out, ", playCount: %d, skipCount: %d, like: %d, lastPlayed: %d",
|
||||
sticker->playCount,
|
||||
sticker->skipCount,
|
||||
sticker->like,
|
||||
sticker->lastPlayed
|
||||
);
|
||||
free(sticker);
|
||||
if (config.stickers) {
|
||||
t_sticker *sticker = (t_sticker *) malloc(sizeof(t_sticker));
|
||||
mympd_get_sticker(uri, sticker);
|
||||
len += json_printf(&out, ", playCount: %d, skipCount: %d, like: %d, lastPlayed: %d",
|
||||
sticker->playCount,
|
||||
sticker->skipCount,
|
||||
sticker->like,
|
||||
sticker->lastPlayed
|
||||
);
|
||||
free(sticker);
|
||||
}
|
||||
len += json_printf(&out, "}}");
|
||||
|
||||
if (len > MAX_SIZE)
|
||||
|
@ -135,6 +135,8 @@ typedef struct {
|
||||
int streamport;
|
||||
const char* coverimage;
|
||||
const char* statefile;
|
||||
bool stickers;
|
||||
bool mixramp;
|
||||
} t_config;
|
||||
|
||||
t_config config;
|
||||
|
28
src/mympd.c
28
src/mympd.c
@ -84,7 +84,6 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||
#ifdef DEBUG
|
||||
printf("Websocket connection closed\n");
|
||||
#endif
|
||||
// mympd_close_handler(nc);
|
||||
}
|
||||
else {
|
||||
#ifdef DEBUG
|
||||
@ -110,6 +109,7 @@ static int inihandler(void* user, const char* section, const char* name, const c
|
||||
t_config* p_config = (t_config*)user;
|
||||
|
||||
#define MATCH(n) strcmp(name, n) == 0
|
||||
|
||||
if (MATCH("mpdhost"))
|
||||
p_config->mpdhost = strdup(value);
|
||||
else if (MATCH("mpdhost"))
|
||||
@ -139,6 +139,16 @@ static int inihandler(void* user, const char* section, const char* name, const c
|
||||
p_config->coverimage = strdup(value);
|
||||
else if (MATCH("statefile"))
|
||||
p_config->statefile = strdup(value);
|
||||
else if (MATCH("stickers"))
|
||||
if (strcmp(value, "true") == 0)
|
||||
p_config->stickers = true;
|
||||
else
|
||||
p_config->stickers = false;
|
||||
else if (MATCH("mixramp"))
|
||||
if (strcmp(value, "true") == 0)
|
||||
p_config->mixramp = true;
|
||||
else
|
||||
p_config->mixramp = false;
|
||||
else
|
||||
return 0; /* unknown section/name, error */
|
||||
|
||||
@ -169,6 +179,8 @@ int main(int argc, char **argv) {
|
||||
config.streamport = 8000;
|
||||
config.coverimage = "folder.jpg";
|
||||
config.statefile = "/var/lib/mympd/mympd.state";
|
||||
config.stickers = true;
|
||||
config.mixramp = true;
|
||||
|
||||
mpd.timeout = 3000;
|
||||
|
||||
@ -179,12 +191,14 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
fprintf(stdout, "myMPD %s\n"
|
||||
"Copyright (C) 2018 Juergen Mang <mail@jcgames.de>\n"
|
||||
"https://github.com/jcorporation/myMPD\n"
|
||||
"Built " __DATE__ " "__TIME__"\n\n",
|
||||
MYMPD_VERSION);
|
||||
printf("Usage: %s /path/to/mympd.conf\n", argv[0]);
|
||||
printf("myMPD %s\n"
|
||||
"Copyright (C) 2018 Juergen Mang <mail@jcgames.de>\n"
|
||||
"https://github.com/jcorporation/myMPD\n"
|
||||
"Built " __DATE__ " "__TIME__"\n\n"
|
||||
"Usage: %s /path/to/mympd.conf\n",
|
||||
MYMPD_VERSION,
|
||||
argv[0]
|
||||
);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user