Skip to content

Commit

Permalink
Merge branch 'master' into notandy-master
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperBFG7 committed Jan 26, 2018
2 parents 3dac7ce + 5589013 commit 1e93d2d
Show file tree
Hide file tree
Showing 11 changed files with 371 additions and 14 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -43,6 +43,7 @@ file(GLOB RESOURCES
htdocs/css/*.css
htdocs/fonts/*
htdocs/index.html
htdocs/player.html
)

set(SOURCES
Expand Down
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -29,6 +29,8 @@ Run flags
```
Usage: ./ympd [OPTION]...
-D, --digest <htdigest> path to htdigest file for authorization
(realm ympd) [no authorization]
-h, --host <host> connect to mpd at host [localhost]
-p, --port <port> connect to mpd at port [6600]
-w, --webport [ip:]<port> listen interface/port for webserver [8080]
Expand All @@ -52,6 +54,12 @@ To run ympd with SSL support:
# ./ympd -w "ssl://8081:/path/to/ssl.pem"
```

Dirble support
--------------

1. Get an API-key from http://dirble.com
2. Add the key at ```var TOKEN = "";```, in ```mpd.js```.

Copyright
---------

Expand Down
3 changes: 2 additions & 1 deletion contrib/init.debian
Expand Up @@ -25,6 +25,7 @@ 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
Expand All @@ -36,7 +37,7 @@ DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a
# 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 --mpdpass '$MPD_PASSWORD' --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT --dirbletoken $DIRBLE_API_TOKEN $DIGEST"

do_start()
{
Expand Down
1 change: 1 addition & 0 deletions contrib/ympd.default
Expand Up @@ -4,3 +4,4 @@ MPD_PASSWORD=
WEB_PORT=8080
YMPD_USER=nobody
DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a
#DIGEST=--digest /path/to/htdigest
3 changes: 2 additions & 1 deletion contrib/ympd.service
Expand Up @@ -9,8 +9,9 @@ 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 --mpdpass "$MPD_PASSWORD" --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT --dirbletoken $DIRBLE_API_TOKE $DIGEST
Type=simple

[Install]
Expand Down
6 changes: 6 additions & 0 deletions htdocs/css/mpd.css
Expand Up @@ -15,6 +15,12 @@ body {
margin-bottom: 0;
}


button {
overflow: hidden;
}


#volume-icon {
float: left;
margin-right: 10px;
Expand Down
25 changes: 22 additions & 3 deletions htdocs/index.html
Expand Up @@ -34,7 +34,7 @@

<ul id="nav_links" class="nav navbar-nav">
<li id="queue"><a href="#/">Queue</a></li>
<li id="browse"><a href="#/browse/0/">Browse database</a></li>
<li id="browse"><a href="#/browse/0/">Browse</a></li>
<li id="dirble"><a href="#/dirble/">Dirble</a></li>
<li><a href="#" data-toggle="modal" data-target="#addstream">Add Stream</a></li>
<li><a href="#" data-toggle="modal" data-target="#settings" onclick="getHost();">Settings</a></li>
Expand All @@ -60,13 +60,25 @@
<span class="glyphicon glyphicon-heart"></span>
</button>
</div>
<!--
<div class="btn-group">
<div class="btn btn-toolbar btn-default">
<span id="volume-icon" class="glyphicon glyphicon-volume-up"></span>
<div id="volumeslider"></div>
</div>
</div>
</div>
-->
<div class="btn-group" role="group">
<audio id="player" preload="none"></audio>
<button type="button" class="btn btn-default" onclick="clickLocalPlay()">
<span id="localplay-icon" class="glyphicon glyphicon-play"></span>
</button>
<button type="button" class="btn btn-default" onclick="window.open('/player.html');">
<span id="localplay-icon" class="glyphicon glyphicon-new-window"></span>
</button>
</div>
</div>

<form id="search" class="navbar-form navbar-right" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
Expand Down Expand Up @@ -115,6 +127,8 @@ <h4>
<tr>
<th>#</th>
<th>Title</th>
<th>Album</th>
<th>Artist</th>
<th>Duration</th>
<th></th>
</tr>
Expand Down Expand Up @@ -252,7 +266,12 @@ <h6><a href="http://www.musicpd.org/libs/libmpdclient/">libMPDClient</a> <small>
MPD Password is set
</div>
</div>

</div>
<div class="row">
<div class="form-group col-md-12">
<label class="control-label" for="mpdstream">MPD Stream URL</label>
<input type="text" class="form-control" id="mpdstream" />
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
Expand Down
137 changes: 131 additions & 6 deletions htdocs/js/mpd.js
Expand Up @@ -16,6 +16,8 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

var TOKEN = "";

var socket;
var last_state;
var last_outputs;
Expand Down Expand Up @@ -112,6 +114,9 @@ var app = $.sammy(function() {


this.get(/\#\/dirble\/(\d+)\/(\d+)/, function() {

if (TOKEN === "") context.redirect("#/0");

prepare();
current_app = 'dirble';
$('#breadcrump').removeClass('hide').empty().append("<li><a href=\"#/dirble/\">Categories</a></li><li>"+dirble_selected_cat+"</li>");
Expand Down Expand Up @@ -143,6 +148,9 @@ var app = $.sammy(function() {


this.get(/\#\/dirble\//, function() {

if (TOKEN === "") context.redirect("#/0");

prepare();
current_app = 'dirble';
$('#breadcrump').removeClass('hide').empty().append("<li>Categories</li>");
Expand Down Expand Up @@ -197,6 +205,67 @@ $(document).ready(function(){
$('#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');
});


Expand Down Expand Up @@ -225,6 +294,7 @@ function webSocketConnect() {
return;

var obj = JSON.parse(msg.data);


switch (obj.type) {
case "queue":
Expand All @@ -238,7 +308,9 @@ function webSocketConnect() {

$('#salamisandwich > tbody').append(
"<tr trackid=\"" + obj.data[song].id + "\"><td>" + (obj.data[song].pos + 1) + "</td>" +
"<td>"+ obj.data[song].title +"</td>" +
"<td>"+ obj.data[song].title +"</td>" +
"<td>"+ obj.data[song].album +"</td>" +
"<td>"+ obj.data[song].artist +"</td>" +
"<td>"+ minutes + ":" + (seconds < 10 ? '0' : '') + seconds +
"</td><td></td></tr>");
}
Expand Down Expand Up @@ -356,9 +428,11 @@ function webSocketConnect() {

$('#salamisandwich > tbody').append(
"<tr uri=\"" + encodeURI(obj.data[item].uri) + "\" class=\"song\">" +
"<td><span class=\"glyphicon glyphicon-music\"></span></td>" +
"<td>" + obj.data[item].title +"</td>" +
"<td>"+ minutes + ":" + (seconds < 10 ? '0' : '') + seconds +
"<td><span class=\"glyphicon glyphicon-music\"></span></td>" +
"<td>" + obj.data[item].title + "</td>" +
"<td>" + obj.data[item].album + "</td>" +
"<td>" + obj.data[item].artist + "</td>" +
"<td>" + minutes + ":" + (seconds < 10 ? '0' : '') + seconds +
"</td><td></td></tr>"
);
break;
Expand Down Expand Up @@ -556,6 +630,7 @@ function webSocketConnect() {
break;
case "mpdhost":
$('#mpdhost').val(obj.data.host);
setLocalStream(obj.data.host);
$('#mpdport').val(obj.data.port);
if(obj.data.passwort_set)
$('#mpd_password_set').removeClass('hide');
Expand Down Expand Up @@ -654,12 +729,14 @@ var updatePlayIcon = function(state)
if(state == 1) { // stop
$("#play-icon").addClass("glyphicon-play");
$('#track-icon').addClass("glyphicon-stop");
} else if(state == 2) { // pause
document.getElementById('player').pause();
} else if(state == 2) { // play
$("#play-icon").addClass("glyphicon-pause");
$('#track-icon').addClass("glyphicon-play");
} else { // play
} else { // pause
$("#play-icon").addClass("glyphicon-play");
$('#track-icon').addClass("glyphicon-pause");
document.getElementById('player').pause();
}
}

Expand All @@ -677,6 +754,52 @@ function clickPlay() {
socket.send('MPD_API_SET_PAUSE');
}

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));
Expand Down Expand Up @@ -767,6 +890,7 @@ function getHost() {

$('#mpdhost').keypress(onEnter);
$('#mpdport').keypress(onEnter);
$('#mpdstream').keypress(onEnter);
$('#mpd_pw').keypress(onEnter);
$('#mpd_pw_con').keypress(onEnter);
}
Expand Down Expand Up @@ -843,6 +967,7 @@ function confirmSettings() {
socket.send('MPD_API_SET_MPDPASS,'+$('#mpd_pw').val());
}
socket.send('MPD_API_SET_MPDHOST,'+$('#mpdport').val()+','+$('#mpdhost').val());
$.cookie("mpdstream", $("#mpdstream").val(), { expires: 424242 });
$('#settings').modal('hide');
}

Expand Down

0 comments on commit 1e93d2d

Please sign in to comment.