@ -27,13 +27,8 @@ var browsepath = "";
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 ( ) {
@ -43,7 +38,6 @@ 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" ) ;
@ -74,7 +68,6 @@ var app = $.sammy(function() {
$ ( '#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 ) {
@ -104,7 +97,6 @@ var app = $.sammy(function() {
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 ) ;
@ -113,60 +105,6 @@ var app = $.sammy(function() {
$ ( '#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" ) ;
} ) ;
@ -260,8 +198,6 @@ $(document).ready(function(){
break ;
}
} , true ) ;
if ( TOKEN === "" ) $ ( '#dirble' ) . addClass ( 'hide' ) ;
} ) ;
function webSocketConnect ( ) {
@ -282,8 +218,6 @@ 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 ) {
@ -667,19 +601,7 @@ function webSocketConnect() {
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 } ,
@ -969,16 +891,12 @@ $('.page-btn').on('click', function (e) {
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 ;
}
@ -989,9 +907,6 @@ $('.page-btn').on('click', function (e) {
case "browse" :
app . setLocation ( '#/browse/' + pagination + '/' + browsepath ) ;
break ;
case "dirble" :
app . setLocation ( "#/dirble/" + dirble _catid + "/" + dirble _page ) ;
break ;
}
e . preventDefault ( ) ;
} ) ;
@ -1085,161 +1000,6 @@ $(document).keydown(function(e){
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' ) ;