var lastSongTitle = "";
var current_song = new Object();
var MAX_ELEMENTS_PER_PAGE = 512;
-var dirble_selected_cat = "";
-var dirble_catid = "";
-var dirble_page = 1;
var isTouch = Modernizr.touch ? 1 : 0;
var filter = "";
-var dirble_api_token = "";
-var dirble_stations = false;
var app = $.sammy(function() {
$('#breadcrump').addClass('hide');
$('#filter').addClass('hide');
$('#salamisandwich').removeClass('hide').find("tr:gt(0)").remove();
- $('#dirble_panel').addClass('hide');
socket.send('MPD_API_GET_QUEUE,'+pagination);
$('#panel-heading').text("Queue");
$('#breadcrump').removeClass('hide').empty().append("<li><a uri=\"\" onclick=\"set_filter('')\">root</a></li>");
add_filter();
$('#salamisandwich').removeClass('hide').find("tr:gt(0)").remove();
- $('#dirble_panel').addClass('hide');
socket.send('MPD_API_GET_BROWSE,'+pagination+','+(browsepath ? browsepath : "/"));
// Don't add all songs from root
if (browsepath) {
this.get(/\#\/search\/(.*)/, function() {
current_app = 'search';
$('#salamisandwich').find("tr:gt(0)").remove();
- $('#dirble_panel').addClass('hide');
var searchstr = this.params['splat'][0];
$('#search > div > input').val(searchstr);
$('#panel-heading').text("Search: "+searchstr);
});
- 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>");
- $('#salamisandwich').addClass('hide');
- $('#dirble_panel').removeClass('hide');
- $('#dirble_loading').removeClass('hide');
- $('#dirble_left').find("tr:gt(0)").remove();
- $('#dirble_right').find("tr:gt(0)").remove();
-
- $('#panel-heading').text("Dirble");
- $('#panel-heading-info').empty();
-
- $('#dirble').addClass('active');
-
- $('#next').addClass('hide');
-
- if (this.params['splat'][1] > 1) $('#prev').removeClass('hide');
- else $('#prev').addClass('hide');
-
- dirble_catid = this.params['splat'][0];
- dirble_page = this.params['splat'][1];
-
- dirble_stations = true;
-
- if (dirble_api_token) { dirble_load_stations(); }
- });
-
- this.get(/\#\/dirble\//, function() {
-
- if (TOKEN === "") context.redirect("#/0");
-
- prepare();
- current_app = 'dirble';
- $('#breadcrump').removeClass('hide').empty().append("<li>Categories</li>");
- $('#salamisandwich').addClass('hide');
- $('#dirble_panel').removeClass('hide');
- $('#dirble_loading').removeClass('hide');
- $('#dirble_left').find("tr:gt(0)").remove();
- $('#dirble_right').find("tr:gt(0)").remove();
-
- $('#panel-heading').text("Dirble");
- $('#panel-heading-info').empty();
-
- $('#dirble').addClass('active');
-
- dirble_stations = false;
-
- if (dirble_api_token) { dirble_load_categories(); }
- });
-
this.get("/", function(context) {
context.redirect("#/0");
});
break;
}
}, true);
-
- if (TOKEN === "") $('#dirble').addClass('hide');
});
function webSocketConnect() {
app.run();
/* emit initial request for output names */
socket.send('MPD_API_GET_OUTPUTS');
- /* emit initial request for dirble api token */
- socket.send('MPD_API_GET_DIRBLEAPITOKEN');
}
socket.onmessage = function got_packet(msg) {
if(obj.data.passwort_set)
$('#mpd_password_set').removeClass('hide');
break;
- case 'dirbleapitoken':
- dirble_api_token = obj.data;
-
- if (dirble_api_token) {
- $('#dirble').removeClass('hide');
-
- if (dirble_stations) { dirble_load_stations(); }
- else { dirble_load_categories(); }
-
- } else {
- $('#dirble').addClass('hide');
- }
- break;
+
case 'error':
$('.top-right').notify({
message:{text: obj.data},
switch ($(this).text()) {
case "Next":
- if (current_app == "dirble") dirble_page++;
- else pagination += MAX_ELEMENTS_PER_PAGE;
+ pagination += MAX_ELEMENTS_PER_PAGE;
break;
case "Previous":
- if (current_app == "dirble") dirble_page--
- else {
- pagination -= MAX_ELEMENTS_PER_PAGE;
- if(pagination <= 0)
- pagination = 0;
- }
+ pagination -= MAX_ELEMENTS_PER_PAGE;
+ if(pagination <= 0)
+ pagination = 0;
break;
}
case "browse":
app.setLocation('#/browse/'+pagination+'/'+browsepath);
break;
- case "dirble":
- app.setLocation("#/dirble/"+dirble_catid+"/"+dirble_page);
- break;
}
e.preventDefault();
});
e.preventDefault();
});
-function dirble_load_categories() {
-
- dirble_page = 1;
-
- $.getJSON( "https://api.dirble.com/v2/categories?token=" + dirble_api_token, function( data ) {
-
- $('#dirble_loading').addClass('hide');
-
- data = data.sort(function(a, b) {
- return (a.title > b.title) ? 1 : 0;
- });
-
- var max = data.length - data.length%2;
-
- for(i = 0; i < max; i+=2) {
-
- $('#dirble_left > tbody').append(
- "<tr><td catid=\""+data[i].id+"\">"+data[i].title+"</td></tr>"
- );
-
- $('#dirble_right > tbody').append(
- "<tr><td catid=\""+data[i+1].id+"\">"+data[i+1].title+"</td></tr>"
- );
- }
-
- if (max != data.length) {
- $('#dirble_left > tbody').append(
- "<tr><td catid=\""+data[max].id+"\">"+data[max].title+"</td></tr>"
- );
- }
-
- $('#dirble_left > tbody > tr > td').on({
- click: function() {
- dirble_selected_cat = $(this).text();
- dirble_catid = $(this).attr("catid");
- app.setLocation("#/dirble/"+dirble_catid+"/"+dirble_page);
- }
- });
-
- $('#dirble_right > tbody > tr > td').on({
- click: function() {
- dirble_selected_cat = $(this).text();
- dirble_catid = $(this).attr("catid");
- app.setLocation("#/dirble/"+dirble_catid+"/"+dirble_page);
- }
- });
- });
-}
-
-
-function dirble_load_stations() {
-
- $.getJSON( "https://api.dirble.com/v2/category/"+dirble_catid+"/stations?page="+dirble_page+"&per_page=20&token=" + dirble_api_token, function( data ) {
-
- $('#dirble_loading').addClass('hide');
- if (data.length == 20) $('#next').removeClass('hide');
-
- var max = data.length - data.length%2;
-
- for(i = 0; i < max; i+=2) {
-
- $('#dirble_left > tbody').append(
- "<tr><td radioid=\""+data[i].id+"\">"+data[i].name+"</td></tr>"
- );
- $('#dirble_right > tbody').append(
- "<tr><td radioid=\""+data[i+1].id+"\">"+data[i+1].name+"</td></tr>"
- );
- }
-
- if (max != data.length) {
- $('#dirble_left > tbody').append(
- "<tr><td radioid=\""+data[max].id+"\">"+data[max].name+"</td></tr>"
- );
- }
-
- $('#dirble_left > tbody > tr > td').on({
- click: function() {
- var _this = $(this);
-
- $.getJSON( "https://api.dirble.com/v2/station/"+$(this).attr("radioid")+"?token=" + dirble_api_token, function( data ) {
-
- socket.send("MPD_API_ADD_TRACK," + data.streams[0].stream);
- $('.top-right').notify({
- message:{
- text: _this.text() + " added"
- }
- }).show();
- });
- },
- mouseenter: function() {
- var _this = $(this);
-
- $(this).last().append(
- "<a role=\"button\" class=\"pull-right btn-group-hover\">" +
- "<span class=\"glyphicon glyphicon-play\"></span></a>").find('a').click(function(e) {
- e.stopPropagation();
-
- $.getJSON( "https://api.dirble.com/v2/station/"+_this.attr("radioid")+"?token=" + dirble_api_token, function( data ) {
-
- socket.send("MPD_API_ADD_PLAY_TRACK," + data.streams[0].stream);
- $('.top-right').notify({
- message:{
- text: _this.text() + " added"
- }
- }).show();
- });
- }).fadeTo('fast',1);
- },
-
- mouseleave: function(){
- $(this).last().find("a").stop().remove();
- }
- });
-
- $('#dirble_right> tbody > tr > td').on({
- click: function() {
- var _this = $(this);
-
- $.getJSON( "https://api.dirble.com/v2/station/"+$(this).attr("radioid")+"?token=" + dirble_api_token, function( data ) {
-
- socket.send("MPD_API_ADD_TRACK," + data.streams[0].stream);
- $('.top-right').notify({
- message:{
- text: _this.text() + " added"
- }
- }).show();
- });
- },
- mouseenter: function() {
- var _this = $(this);
-
- $(this).last().append(
- "<a role=\"button\" class=\"pull-right btn-group-hover\">" +
- "<span class=\"glyphicon glyphicon-play\"></span></a>").find('a').click(function(e) {
- e.stopPropagation();
-
- $.getJSON( "https://api.dirble.com/v2/station/"+_this.attr("radioid")+"?token=" + dirble_api_token, function( data ) {
-
- socket.send("MPD_API_ADD_PLAY_TRACK," + data.streams[0].stream);
- $('.top-right').notify({
- message:{
- text: _this.text() + " added"
- }
- }).show();
- });
- }).fadeTo('fast',1);
- },
-
- mouseleave: function(){
- $(this).last().find("a").stop().remove();
- }
- });
- });
-}
-
function set_filter (c) {
filter = c;
$('#filter > a').removeClass('active');
{"port", required_argument, 0, 'p'},
{"localport", required_argument, 0, 'l'},
{"webport", required_argument, 0, 'w'},
- {"dirbletoken", required_argument, 0, 'd'},
{"user", required_argument, 0, 'u'},
{"version", no_argument, 0, 'v'},
{"help", no_argument, 0, 0 },
case 'w':
webport = strdup(optarg);
break;
- case 'd':
- strncpy(dirble_api_token, optarg, sizeof(dirble_api_token));
- break;
case 'u':
run_as_user = strdup(optarg);
break;
" -l, --localport <port>\t\tskip authorization for local port\n"
" -w, --webport [ip:]<port>\tlisten interface/port for webserver [8080]\n"
" -u, --user <username>\t\tdrop priviliges to user after socket bind\n"
- " -d, --dirbletoken <apitoken>\tDirble API token\n"
" -v, --version\t\t\tget version\n"
" -m, --mpdpass <password>\tspecifies the password to use when connecting to mpd\n"
" --help\t\t\t\tthis help\n"