mirror of
https://github.com/SuperBFG7/ympd
synced 2024-12-25 10:30:26 +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,6 +84,7 @@
|
||||
<h4 id="currentArtist" data-href="{'cmd': 'artistClick', 'options': []}"></h4>
|
||||
<small>Album</small>
|
||||
<h4 id="currentAlbum"></h4>
|
||||
<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>
|
||||
@ -91,8 +92,9 @@
|
||||
</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 = '';
|
||||
}
|
||||
|
@ -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\"}");
|
||||
break;
|
||||
case MPD_API_LIKE:
|
||||
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:
|
||||
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)
|
||||
mpd_run_crossfade(mpd.conn, uint_buf1);
|
||||
|
||||
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);
|
||||
@ -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);
|
||||
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,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\"}");
|
||||
break;
|
||||
case MPD_API_SET_NEXT:
|
||||
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\"}");
|
||||
@ -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);
|
||||
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);
|
||||
@ -822,7 +832,8 @@ int mympd_put_settings(char *buffer) {
|
||||
"{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,"
|
||||
"streamport: %d, coverimage: %Q, stickers: %B, mixramp: %B, "
|
||||
"max_elements_per_page: %d, replaygain: %Q,"
|
||||
"notificationWeb: %d, notificationPage: %d"
|
||||
"}}",
|
||||
mpd_status_get_repeat(status),
|
||||
@ -837,6 +848,8 @@ int mympd_put_settings(char *buffer) {
|
||||
config.mpdpass ? "true" : "false",
|
||||
config.streamport,
|
||||
config.coverimage,
|
||||
config.stickers,
|
||||
config.mixramp,
|
||||
MAX_ELEMENTS_PER_PAGE,
|
||||
replaygain,
|
||||
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) {
|
||||
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, "
|
||||
"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,
|
||||
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->skipCount,
|
||||
sticker->like,
|
||||
sticker->lastPlayed
|
||||
);
|
||||
|
||||
mpd_song_free(song);
|
||||
mpd_response_finish(mpd.conn);
|
||||
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,6 +991,8 @@ int mympd_put_songdetails(char *buffer, char *uri) {
|
||||
}
|
||||
mpd_response_finish(mpd.conn);
|
||||
|
||||
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,
|
||||
@ -981,6 +1001,7 @@ int mympd_put_songdetails(char *buffer, char *uri) {
|
||||
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;
|
||||
|
24
src/mympd.c
24
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"
|
||||
printf("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]);
|
||||
"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