1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-12-26 02:50:26 +00:00

Feat: add config options for stickerusage and mixramp settings

This commit is contained in:
jcorporation 2018-08-21 20:28:13 +01:00
parent 492f008555
commit 988a315f45
6 changed files with 138 additions and 71 deletions

View File

@ -25,3 +25,9 @@ coverimage = folder.jpg
#myMPD statefile #myMPD statefile
statefile = /var/lib/mympd/mympd.state statefile = /var/lib/mympd/mympd.state
#Enable mixramp settings
mixramp = false
#Enable usage of mpd stickers for play statistics and voting
stickers = true

View File

@ -84,6 +84,7 @@
<h4 id="currentArtist" data-href="{'cmd': 'artistClick', 'options': []}"></h4> <h4 id="currentArtist" data-href="{'cmd': 'artistClick', 'options': []}"></h4>
<small>Album</small> <small>Album</small>
<h4 id="currentAlbum"></h4> <h4 id="currentAlbum"></h4>
<div class="stickers">
<small>Vote</small><br/> <small>Vote</small><br/>
<div class="btn-group"> <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="btnVoteDown" data-href="{'cmd': 'voteSong', 'options': ['0']}" class="btn btn-sm btn-light material-icons">thumb_down</button>
@ -91,8 +92,9 @@
</div> </div>
</div> </div>
</div> </div>
</div>
<div class="card-footer card-footer-playback"> <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> <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"> <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">&nbsp;&nbsp;</div> <div class="btn ml-1 mr-1" id="counter">&nbsp;&nbsp;</div>
@ -673,7 +675,7 @@
</select> </select>
</div> </div>
</div> </div>
<div class="row"> <div class="row mixramp">
<div class="form-group input-group col-md-6 border-secondary"> <div class="form-group input-group col-md-6 border-secondary">
<div class="input-group-prepend"> <div class="input-group-prepend">
<div class="input-group-text bg-secondary text-light border-secondary">Mixramp DB</div> <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="genre"><th>Genre</th><td></td></tr>
<tr data-name="date"><th>Date</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 data-name="uri"><th>Uri</th><td></td></tr>
<tr><th colspan="2">Statistics</th></tr> <tr class="stickers"><th colspan="2">Statistics</th></tr>
<tr data-name="playCount"><th>Play count</th><td></td></tr> <tr class="stickers" data-name="playCount"><th>Play count</th><td></td></tr>
<tr data-name="skipCount"><th>Skip count</th><td></td></tr> <tr class="stickers" data-name="skipCount"><th>Skip count</th><td></td></tr>
<tr data-name="lastPlayed"><th>Last played</th><td></td></tr> <tr class="stickers" data-name="lastPlayed"><th>Last played</th><td></td></tr>
<tr data-name="like"><th>Like</th><td></td></tr> <tr class="stickers" data-name="like"><th>Like</th><td></td></tr>
</tbody> </tbody>
</table> </table>
</div> </div>

View File

@ -500,6 +500,10 @@ function appInit() {
window.addEventListener('hashchange', appRoute, false); window.addEventListener('hashchange', appRoute, false);
window.addEventListener('focus', function() {
sendAPI({"cmd":"MPD_API_GET_STATE"}, parseState);
}, false);
document.addEventListener('keydown', function(event) { document.addEventListener('keydown', function(event) {
if (event.target.tagName == 'INPUT') if (event.target.tagName == 'INPUT')
return; return;
@ -799,6 +803,19 @@ function parseSettings(obj) {
toggleBtn('btnnotifyPage', obj.data.notificationPage); 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=obj.data;
settings.mpdstream = 'http://'; settings.mpdstream = 'http://';
if (settings.mpdhost == '127.0.0.1' || settings.mpdhost == 'localhost') if (settings.mpdhost == '127.0.0.1' || settings.mpdhost == 'localhost')
@ -1372,11 +1389,15 @@ function replaceQueue(type, uri, name) {
} }
function songClick() { function songClick() {
songDetails(domCache.currentTrack.getAttribute('data-uri')); var uri = domCache.currentTrack.getAttribute('data-uri')
if (uri != '')
songDetails(uri);
} }
function artistClick() { 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) { function songDetails(uri) {
@ -1919,6 +1940,7 @@ function songChange(obj) {
htmlNotification += obj.data.artist; htmlNotification += obj.data.artist;
pageTitle += obj.data.artist + ' - '; pageTitle += obj.data.artist + ' - ';
document.getElementById('currentArtist').innerText = obj.data.artist; document.getElementById('currentArtist').innerText = obj.data.artist;
document.getElementById('currentArtist').setAttribute('data-albumartist', obj.data.albumartist);
} else { } else {
document.getElementById('currentArtist').innerText = ''; document.getElementById('currentArtist').innerText = '';
} }

View File

@ -80,12 +80,17 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg) {
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"error\", \"data\": \"Unknown request\"}"); n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"error\", \"data\": \"Unknown request\"}");
break; break;
case MPD_API_LIKE: case MPD_API_LIKE:
if (config.stickers) {
je = json_scanf(msg.p, msg.len, "{data: {uri: %Q, like: %d}}", &p_charbuf1, &uint_buf1); je = json_scanf(msg.p, msg.len, "{data: {uri: %Q, like: %d}}", &p_charbuf1, &uint_buf1);
if (je == 2) { if (je == 2) {
mympd_like_song_uri(p_charbuf1, uint_buf1); mympd_like_song_uri(p_charbuf1, uint_buf1);
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}"); n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}");
free(p_charbuf1); free(p_charbuf1);
} }
}
else {
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"error\", \"data\": \"MPD stickers are disabled\"}");
}
break; break;
case MPD_API_GET_STATE: case MPD_API_GET_STATE:
n = mympd_put_state(mpd.buf, &mpd.song_id, &mpd.next_song_id, &mpd.queue_version); n = mympd_put_state(mpd.buf, &mpd.song_id, &mpd.next_song_id, &mpd.queue_version);
@ -119,6 +124,7 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg) {
if (je == 1) if (je == 1)
mpd_run_crossfade(mpd.conn, uint_buf1); mpd_run_crossfade(mpd.conn, uint_buf1);
if (config.mixramp) {
je = json_scanf(msg.p, msg.len, "{data: {mixrampdb: %f}}", &float_buf); je = json_scanf(msg.p, msg.len, "{data: {mixrampdb: %f}}", &float_buf);
if (je == 1) if (je == 1)
mpd_run_mixrampdb(mpd.conn, float_buf); mpd_run_mixrampdb(mpd.conn, float_buf);
@ -126,6 +132,7 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg) {
je = json_scanf(msg.p, msg.len, "{data: {mixrampdelay: %f}}", &float_buf); je = json_scanf(msg.p, msg.len, "{data: {mixrampdelay: %f}}", &float_buf);
if (je == 1) if (je == 1)
mpd_run_mixrampdelay(mpd.conn, float_buf); mpd_run_mixrampdelay(mpd.conn, float_buf);
}
je = json_scanf(msg.p, msg.len, "{data: {replaygain:%Q}}", &p_charbuf1); je = json_scanf(msg.p, msg.len, "{data: {replaygain:%Q}}", &p_charbuf1);
if (je == 1) { if (je == 1) {
@ -163,6 +170,7 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg) {
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}"); n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}");
break; break;
case MPD_API_SET_NEXT: case MPD_API_SET_NEXT:
if (config.stickers)
mympd_count_song_id(mpd.song_id, "skipCount", 1); mympd_count_song_id(mpd.song_id, "skipCount", 1);
mpd_run_next(mpd.conn); mpd_run_next(mpd.conn);
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}"); n = snprintf(mpd.buf, MAX_SIZE, "{\"type\": \"result\", \"data\": \"ok\"}");
@ -682,8 +690,10 @@ void mympd_parse_idle(struct mg_mgr *s) {
break; break;
case MPD_IDLE_PLAYER: case MPD_IDLE_PLAYER:
len = mympd_put_state(mpd.buf, &mpd.song_id, &mpd.next_song_id, &mpd.queue_version); len = mympd_put_state(mpd.buf, &mpd.song_id, &mpd.next_song_id, &mpd.queue_version);
if (config.stickers) {
mympd_count_song_id(mpd.song_id, "playCount", 1); mympd_count_song_id(mpd.song_id, "playCount", 1);
mympd_last_played_song_id(mpd.song_id); mympd_last_played_song_id(mpd.song_id);
}
break; break;
case MPD_IDLE_MIXER: case MPD_IDLE_MIXER:
len = mympd_put_state(mpd.buf, &mpd.song_id, &mpd.next_song_id, &mpd.queue_version); len = mympd_put_state(mpd.buf, &mpd.song_id, &mpd.next_song_id, &mpd.queue_version);
@ -822,7 +832,8 @@ int mympd_put_settings(char *buffer) {
"{type: settings, data: {" "{type: settings, data: {"
"repeat: %d, single: %d, crossfade: %d, consume: %d, random: %d, " "repeat: %d, single: %d, crossfade: %d, consume: %d, random: %d, "
"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, max_elements_per_page: %d, replaygain: %Q," "streamport: %d, coverimage: %Q, stickers: %B, mixramp: %B, "
"max_elements_per_page: %d, replaygain: %Q,"
"notificationWeb: %d, notificationPage: %d" "notificationWeb: %d, notificationPage: %d"
"}}", "}}",
mpd_status_get_repeat(status), mpd_status_get_repeat(status),
@ -837,6 +848,8 @@ int mympd_put_settings(char *buffer) {
config.mpdpass ? "true" : "false", config.mpdpass ? "true" : "false",
config.streamport, config.streamport,
config.coverimage, config.coverimage,
config.stickers,
config.mixramp,
MAX_ELEMENTS_PER_PAGE, MAX_ELEMENTS_PER_PAGE,
replaygain, replaygain,
state.a, state.a,
@ -901,7 +914,6 @@ int mympd_get_cover(const char *uri, char *cover, int cover_len) {
int mympd_put_current_song(char *buffer) { int mympd_put_current_song(char *buffer) {
struct mpd_song *song; struct mpd_song *song;
t_sticker *sticker = (t_sticker *) malloc(sizeof(t_sticker));
int len; int len;
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE); struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
char cover[500]; 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_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, " "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), mpd_song_get_pos(song),
mympd_get_tag(song, MPD_TAG_TITLE), mympd_get_tag(song, MPD_TAG_TITLE),
mympd_get_tag(song, MPD_TAG_ARTIST), mympd_get_tag(song, MPD_TAG_ARTIST),
@ -926,16 +937,24 @@ int mympd_put_current_song(char *buffer) {
mpd.song_id, mpd.song_id,
mympd_get_tag(song, MPD_TAG_ALBUM_ARTIST), mympd_get_tag(song, MPD_TAG_ALBUM_ARTIST),
mpd_song_get_duration(song), mpd_song_get_duration(song),
cover, cover
);
mpd_response_finish(mpd.conn);
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->playCount,
sticker->skipCount, sticker->skipCount,
sticker->like, sticker->like,
sticker->lastPlayed sticker->lastPlayed
); );
mpd_song_free(song);
mpd_response_finish(mpd.conn);
free(sticker); free(sticker);
}
len += json_printf(&out, "}}");
mpd_song_free(song);
if (len > MAX_SIZE) if (len > MAX_SIZE)
fprintf(stderr, "Buffer truncated\n"); fprintf(stderr, "Buffer truncated\n");
@ -948,7 +967,6 @@ int mympd_put_songdetails(char *buffer, char *uri) {
int len; int len;
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE); struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
char cover[500]; char cover[500];
t_sticker *sticker = (t_sticker *) malloc(sizeof(t_sticker));
len = json_printf(&out, "{type: song_details, data: {"); len = json_printf(&out, "{type: song_details, data: {");
mpd_send_list_all_meta(mpd.conn, uri); mpd_send_list_all_meta(mpd.conn, uri);
@ -973,6 +991,8 @@ int mympd_put_songdetails(char *buffer, char *uri) {
} }
mpd_response_finish(mpd.conn); mpd_response_finish(mpd.conn);
if (config.stickers) {
t_sticker *sticker = (t_sticker *) malloc(sizeof(t_sticker));
mympd_get_sticker(uri, sticker); mympd_get_sticker(uri, sticker);
len += json_printf(&out, ", playCount: %d, skipCount: %d, like: %d, lastPlayed: %d", len += json_printf(&out, ", playCount: %d, skipCount: %d, like: %d, lastPlayed: %d",
sticker->playCount, sticker->playCount,
@ -981,6 +1001,7 @@ int mympd_put_songdetails(char *buffer, char *uri) {
sticker->lastPlayed sticker->lastPlayed
); );
free(sticker); free(sticker);
}
len += json_printf(&out, "}}"); len += json_printf(&out, "}}");
if (len > MAX_SIZE) if (len > MAX_SIZE)

View File

@ -135,6 +135,8 @@ typedef struct {
int streamport; int streamport;
const char* coverimage; const char* coverimage;
const char* statefile; const char* statefile;
bool stickers;
bool mixramp;
} t_config; } t_config;
t_config config; t_config config;

View File

@ -84,7 +84,6 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
#ifdef DEBUG #ifdef DEBUG
printf("Websocket connection closed\n"); printf("Websocket connection closed\n");
#endif #endif
// mympd_close_handler(nc);
} }
else { else {
#ifdef DEBUG #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; t_config* p_config = (t_config*)user;
#define MATCH(n) strcmp(name, n) == 0 #define MATCH(n) strcmp(name, n) == 0
if (MATCH("mpdhost")) if (MATCH("mpdhost"))
p_config->mpdhost = strdup(value); p_config->mpdhost = strdup(value);
else if (MATCH("mpdhost")) 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); p_config->coverimage = strdup(value);
else if (MATCH("statefile")) else if (MATCH("statefile"))
p_config->statefile = strdup(value); 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 else
return 0; /* unknown section/name, error */ return 0; /* unknown section/name, error */
@ -169,6 +179,8 @@ int main(int argc, char **argv) {
config.streamport = 8000; config.streamport = 8000;
config.coverimage = "folder.jpg"; config.coverimage = "folder.jpg";
config.statefile = "/var/lib/mympd/mympd.state"; config.statefile = "/var/lib/mympd/mympd.state";
config.stickers = true;
config.mixramp = true;
mpd.timeout = 3000; mpd.timeout = 3000;
@ -179,12 +191,14 @@ int main(int argc, char **argv) {
} }
} }
else { else {
fprintf(stdout, "myMPD %s\n" printf("myMPD %s\n"
"Copyright (C) 2018 Juergen Mang <mail@jcgames.de>\n" "Copyright (C) 2018 Juergen Mang <mail@jcgames.de>\n"
"https://github.com/jcorporation/myMPD\n" "https://github.com/jcorporation/myMPD\n"
"Built " __DATE__ " "__TIME__"\n\n", "Built " __DATE__ " "__TIME__"\n\n"
MYMPD_VERSION); "Usage: %s /path/to/mympd.conf\n",
printf("Usage: %s /path/to/mympd.conf\n", argv[0]); MYMPD_VERSION,
argv[0]
);
return EXIT_FAILURE; return EXIT_FAILURE;
} }