From: SuperBFG7 Date: Fri, 26 Jan 2018 12:51:20 +0000 (+0100) Subject: Merge branch 'master' into notandy-master X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=1e93d2dc825d076703250427fb5a7952536c6859;p=ympd.git Merge branch 'master' into notandy-master --- 1e93d2dc825d076703250427fb5a7952536c6859 diff --cc README.md index bc14cb8,af3a310..4bf91f2 --- a/README.md +++ b/README.md @@@ -29,13 -28,14 +29,15 @@@ Run flag ``` Usage: ./ympd [OPTION]... - -d, --digest path to htdigest file for authorization - (realm ympd) [no authorization] - -h, --host connect to mpd at host [localhost] - -p, --port connect to mpd at port [6600] - -w, --webport [ip:] listen interface/port for webserver [8080] - -u, --user drop priviliges to user after socket bind - -V, --version get version - --help this help ++ -D, --digest path to htdigest file for authorization ++ (realm ympd) [no authorization] + -h, --host connect to mpd at host [localhost] + -p, --port connect to mpd at port [6600] + -w, --webport [ip:] listen interface/port for webserver [8080] + -d, --dirbletoken Dirble API token + -u, --user drop priviliges to user after socket bind + -V, --version get version + --help this help ``` SSL Support diff --cc contrib/init.debian index 943e4de,e1c6fab..012adf1 --- a/contrib/init.debian +++ b/contrib/init.debian @@@ -24,7 -24,7 +24,8 @@@ YMPD_USER=nobod MPD_HOST=localhost MPD_PORT=6600 WEB_PORT=8080 +DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a + #DIGEST=--digest /path/to/htdigest # Exit if the package is not installed @@@ -36,7 -36,7 +37,7 @@@ # Load the VERBOSE setting and other rcS variables [ -f /etc/default/rcS ] && . /etc/default/rcS - DAEMON_OPT="--user $YMPD_USER --mpdpass '$MPD_PASSWORD' --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT --dirbletoken $DIRBLE_API_TOKEN" -DAEMON_OPT="--user $YMPD_USER --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT $DIGEST" ++DAEMON_OPT="--user $YMPD_USER --mpdpass '$MPD_PASSWORD' --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT --dirbletoken $DIRBLE_API_TOKEN $DIGEST" do_start() { diff --cc contrib/ympd.default index cb3ca72,184b2ed..27e9ebb --- a/contrib/ympd.default +++ b/contrib/ympd.default @@@ -1,6 -1,5 +1,7 @@@ MPD_HOST=localhost MPD_PORT=6600 +MPD_PASSWORD= WEB_PORT=8080 YMPD_USER=nobody +DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a + #DIGEST=--digest /path/to/htdigest diff --cc contrib/ympd.service index 7b42ebb,4969337..4151534 --- a/contrib/ympd.service +++ b/contrib/ympd.service @@@ -5,12 -5,11 +5,13 @@@ Requires=network.target local-fs.targe [Service] Environment=MPD_HOST=localhost Environment=MPD_PORT=6600 +Environment=MPD_PASSWORD= Environment=WEB_PORT=8080 Environment=YMPD_USER=nobody +Environment=DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a + Environment=DIGEST= EnvironmentFile=/etc/default/ympd - ExecStart=/usr/bin/ympd --user $YMPD_USER --mpdpass "$MPD_PASSWORD" --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT --dirbletoken $DIRBLE_API_TOKE -ExecStart=/usr/bin/ympd --user $YMPD_USER --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT $DIGEST ++ExecStart=/usr/bin/ympd --user $YMPD_USER --mpdpass "$MPD_PASSWORD" --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT --dirbletoken $DIRBLE_API_TOKE $DIGEST Type=simple [Install] diff --cc htdocs/js/mpd.js index 5c8a8d1,b6e7644..09b7705 --- a/htdocs/js/mpd.js +++ b/htdocs/js/mpd.js @@@ -195,8 -186,67 +203,69 @@@ $(document).ready(function() else if ($.cookie("notification") === "true") $('#btnnotify').addClass("active") + + add_filter(); + + document.getElementById('player').addEventListener('stalled', function() { + if ( !document.getElementById('player').paused ) { + this.pause(); + clickLocalPlay(); + $('.top-right').notify({ + message:{text:"music stream stalled - trying to recover..."}, + type: "danger", + fadeOut: { enabled: true, delay: 1000 }, + }).show(); + } + }); + + document.getElementById('player').addEventListener('pause', function() { + this.src=''; + this.removeAttribute("src"); + $("#localplay-icon").removeClass("glyphicon-pause").addClass("glyphicon-play"); + }); + + document.getElementById('player').addEventListener('error', function failed(e) { + this.pause(); + switch (e.target.error.code) { + case e.target.error.MEDIA_ERR_ABORTED: + $('.top-right').notify({ + message:{text:"Audio playback aborted by user."}, + type: "info", + fadeOut: { enabled: true, delay: 1000 }, + }).show(); + break; + case e.target.error.MEDIA_ERR_NETWORK: + $('.top-right').notify({ + message:{text:"Network error while playing audio."}, + type: "danger", + fadeOut: { enabled: true, delay: 1000 }, + }).show(); + break; + case e.target.error.MEDIA_ERR_DECODE: + $('.top-right').notify({ + message:{text:"Audio playback aborted. Did you unplug your headphones?"}, + type: "danger", + fadeOut: { enabled: true, delay: 1000 }, + }).show(); + break; + case e.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED: + $('.top-right').notify({ + message:{text:"Error while loading audio (server, network or format error)."}, + type: "danger", + fadeOut: { enabled: true, delay: 1000 }, + }).show(); + break; + default: + $('.top-right').notify({ + message:{text:"Unknown error while playing audio."}, + type: "danger", + fadeOut: { enabled: true, delay: 1000 }, + }).show(); + break; + } + }, true); + + if (TOKEN === "") $('#dirble').addClass('hide'); }); @@@ -677,6 -713,62 +754,52 @@@ function clickPlay() socket.send('MPD_API_SET_PAUSE'); } -function renumber_table(tableID,item) { - was = item.children("td").first().text();//Check if first item exists! - is = item.index() + 1;//maybe add pagination - - if (was != is) { - socket.send("MPD_API_MOVE_TRACK," + was + "," + is); - socket.send('MPD_API_GET_QUEUE,'+pagination); - } -} - + function clickLocalPlay() { + var player = document.getElementById('player'); + $("#localplay-icon").removeClass("glyphicon-play").removeClass("glyphicon-pause"); + + + if ( !$('#track-icon').hasClass('glyphicon-play') ) { + clickPlay(); + } + + if ( player.paused ) { + var mpdstream = $.cookie("mpdstream"); + + if ( mpdstream ) { + player.src = mpdstream; + console.log("playing mpd stream: " + player.src); + player.load(); + player.play(); + $("#localplay-icon").addClass("glyphicon-pause"); + } else { + $("#mpdstream").change(function(){ clickLocalPlay(); $(this).unbind("change"); }); + $("#localplay-icon").addClass("glyphicon-play"); + getHost(); + } + } else { + player.pause(); + } + } + + function setLocalStream(mpdhost) { + var mpdstream = $.cookie("mpdstream"); + + if ( !mpdstream ) { + mpdstream = "http://"; + if ( mpdhost == "127.0.0.1" ) + mpdstream += window.location.hostname; + else + mpdstream += mpdhost; + mpdstream += ":8000/"; + + $.cookie("mpdstream", mpdstream, { expires: 424242 }); + } + + $("#mpdstream").val(mpdstream); + $("#mpdstream").change(); + } + function trash(tr) { if ( $('#btntrashmodeup').hasClass('active') ) { socket.send('MPD_API_RM_RANGE,0,' + (tr.index() + 1)); diff --cc src/ympd.c index 00b82ee,d8b1b65..1252cb5 --- a/src/ympd.c +++ b/src/ympd.c @@@ -80,9 -95,8 +95,10 @@@ int main(int argc, char **argv mpd.port = 6600; strcpy(mpd.host, "127.0.0.1"); + strcpy(dirble_api_token, "2e223c9909593b94fc6577361a"); + static struct option long_options[] = { - {"digest", required_argument, 0, 'd'}, ++ {"digest", required_argument, 0, 'D'}, {"host", required_argument, 0, 'h'}, {"port", required_argument, 0, 'p'}, {"webport", required_argument, 0, 'w'}, @@@ -94,9 -106,12 +110,12 @@@ {0, 0, 0, 0 } }; - while((n = getopt_long(argc, argv, "h:p:w:u:vm:", - while((n = getopt_long(argc, argv, "d:h:p:w:u:v", ++ while((n = getopt_long(argc, argv, "D:h:p:w:u:d:v:m", long_options, &option_index)) != -1) { switch (n) { - case 'd': ++ case 'D': + gpass = strdup(optarg); + break; case 'h': strncpy(mpd.host, optarg, sizeof(mpd.host)); break; @@@ -124,13 -133,13 +143,15 @@@ break; default: fprintf(stderr, "Usage: %s [OPTION]...\n\n" - " -d, --digest \tpath to htdigest file for authorization\n" ++ " -D, --digest \tpath to htdigest file for authorization\n" + " \t(realm ympd) [no authorization]\n" " -h, --host \t\tconnect to mpd at host [localhost]\n" " -p, --port \t\tconnect to mpd at port [6600]\n" " -w, --webport [ip:]\tlisten interface/port for webserver [8080]\n" " -u, --user \t\tdrop priviliges to user after socket bind\n" + " -d, --dirbletoken \tDirble API token\n" - " -V, --version\t\t\tget version\n" + " -v, --version\t\t\tget version\n" + " -m, --mpdpass \tspecifies the password to use when connecting to mpd\n" " --help\t\t\t\tthis help\n" , argv[0]); return EXIT_FAILURE;