2017-01-09 14:43:56 +00:00
|
|
|
$(function(){
|
2016-11-17 22:07:22 +00:00
|
|
|
|
2017-08-04 18:29:08 +00:00
|
|
|
searchTimeout = null;
|
|
|
|
|
2017-08-05 11:21:11 +00:00
|
|
|
/* ==============
|
|
|
|
// EVENTS //
|
|
|
|
/===============*/
|
|
|
|
|
2017-08-04 20:08:31 +00:00
|
|
|
/* Click on a radio station (table entry) and play it */
|
2017-08-05 11:21:11 +00:00
|
|
|
$('body').on('click', '.filename', function() {
|
|
|
|
var stationid = $(this).parent().attr('data-id');
|
|
|
|
action_play(stationid);
|
2017-08-04 20:08:31 +00:00
|
|
|
});
|
2017-08-04 18:29:08 +00:00
|
|
|
|
2017-08-05 11:21:11 +00:00
|
|
|
$('body').on('click', '.favpls', function() {
|
|
|
|
var stationid = $(this).parent().parent().attr('data-id');
|
|
|
|
action_favorite(stationid);
|
2017-08-04 18:29:08 +00:00
|
|
|
});
|
|
|
|
|
2016-11-17 22:07:22 +00:00
|
|
|
|
2017-08-05 11:21:11 +00:00
|
|
|
/* ==============
|
|
|
|
// ACTIONS //
|
|
|
|
/===============*/
|
|
|
|
|
|
|
|
function action_favorite(stationid){
|
|
|
|
|
2017-08-06 21:23:26 +00:00
|
|
|
var removed = false;
|
2017-08-05 11:21:11 +00:00
|
|
|
var stations = []
|
|
|
|
var baseUrl = OC.generateUrl('/apps/radio');
|
2017-08-06 21:23:26 +00:00
|
|
|
|
2017-08-05 11:21:11 +00:00
|
|
|
$.get(baseUrl + '/stations', function ( data ) {
|
|
|
|
for (var station in data) {
|
|
|
|
if (data[station]["stationid"] == stationid){
|
|
|
|
removed = true;
|
|
|
|
$.ajax({
|
|
|
|
url: baseUrl + '/stations/' + data[station]["id"],
|
|
|
|
method: 'DELETE'
|
|
|
|
}).done(function(){
|
2017-08-05 17:41:29 +00:00
|
|
|
$( "tr[data-id='"+data[station]["stationid"]+"']" ).find('.icon-stationfav').removeClass('starred');
|
2017-08-05 11:21:11 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
if (removed == true) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
var station = {
|
|
|
|
"stationid": stationid
|
|
|
|
};
|
|
|
|
$.ajax({
|
|
|
|
url: baseUrl + '/stations',
|
|
|
|
method: 'POST',
|
|
|
|
contentType: 'application/json',
|
|
|
|
data: JSON.stringify(station)
|
2017-08-05 17:41:29 +00:00
|
|
|
}).done(function(){
|
|
|
|
$( "tr[data-id='"+stationid+"']" ).find('.icon-stationfav').addClass('starred');
|
2017-08-05 11:21:11 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
function action_play(stationid){
|
2017-08-06 21:23:26 +00:00
|
|
|
$.ajax({
|
|
|
|
method: "GET",
|
|
|
|
url: "https://onny.project-insanity.org/getmetadata/"+stationid,
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data){
|
|
|
|
var title = data['metadata'];
|
|
|
|
$("#station_metadata").html(title);
|
|
|
|
}
|
|
|
|
});
|
2017-01-08 08:36:13 +00:00
|
|
|
$.ajax({
|
|
|
|
method: "GET",
|
2017-08-04 20:08:31 +00:00
|
|
|
url: "https://www.radio-browser.info/webservice/v2/json/url/"+stationid,
|
2017-01-08 08:36:13 +00:00
|
|
|
dataType: 'json',
|
|
|
|
success: function(data){
|
|
|
|
var sourceUrl = data['url'];
|
|
|
|
$("#player").attr("src", sourceUrl);
|
|
|
|
$('#player').trigger('play');
|
2017-08-04 20:08:31 +00:00
|
|
|
$('#playbutton').attr("class", "pause");
|
2017-01-08 08:36:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-01-06 09:52:12 +00:00
|
|
|
function render_result(data){
|
2017-08-05 17:41:29 +00:00
|
|
|
|
|
|
|
var baseUrl = OC.generateUrl('/apps/radio');
|
|
|
|
$.get(baseUrl + '/stations', function ( fav_stations ) {
|
|
|
|
|
|
|
|
$.each(data, function(i, station) {
|
|
|
|
|
|
|
|
var isstarred = ""
|
|
|
|
for (var fav_station in fav_stations) {
|
|
|
|
if (fav_stations[fav_station]["stationid"] == station['id']) {
|
|
|
|
isstarred = "starred";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$('tbody').append('<tr data-src='+station['url']+' data-id='+station['id']+'>\
|
|
|
|
<td class="favcolumn">\
|
|
|
|
<a href="#" class="favpls" onclick="station_fav();">\
|
|
|
|
<span class="icon-stationfav ' + isstarred + '"></span>\
|
|
|
|
<span class="hidden-visually">Favorite</span>\
|
|
|
|
</a>\
|
|
|
|
</td>\
|
|
|
|
<td class="filename">\
|
|
|
|
<label for="select-files-3">\
|
|
|
|
<div class="thumbnail" style="background-image:url('+station['favicon']+'); background-size: 32px;"></div>\
|
|
|
|
</label>\
|
|
|
|
<a class="name" href="#">\
|
|
|
|
<span class="nametext"><span class="innernametext">'+station['name']+'</span></span>\
|
|
|
|
</a>\
|
|
|
|
</td>\
|
|
|
|
</tr>');
|
|
|
|
});
|
|
|
|
|
2016-11-17 22:07:22 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-08-05 11:21:11 +00:00
|
|
|
function action_load_favorites(){
|
2017-08-04 18:29:08 +00:00
|
|
|
var stations = []
|
2017-02-21 16:57:30 +00:00
|
|
|
var baseUrl = OC.generateUrl('/apps/radio');
|
|
|
|
$.get(baseUrl + '/stations', function ( data ) {
|
2017-08-04 18:29:08 +00:00
|
|
|
for (var station in data) {
|
|
|
|
stations.push(data[station]["stationid"]);
|
|
|
|
};
|
|
|
|
render_stations(stations);
|
2017-02-16 12:00:43 +00:00
|
|
|
});
|
2017-01-08 08:36:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function render_stations(station_ids){
|
|
|
|
for (stationid in station_ids){
|
|
|
|
$.ajax({
|
|
|
|
method: "GET",
|
|
|
|
url: "https://www.radio-browser.info/webservice/json/stations/byid/"+station_ids[stationid],
|
|
|
|
dataType: 'json',
|
|
|
|
success: render_result
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-01-06 09:52:12 +00:00
|
|
|
function radio_query(type, query){
|
|
|
|
switch (type) {
|
|
|
|
case 0:
|
|
|
|
var url = "https://www.radio-browser.info/webservice/json/stations/search";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
var url = "https://www.radio-browser.info/webservice/json/stations/topclick/20";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
var url = "https://www.radio-browser.info/webservice/json/stations/lastchange/20";
|
|
|
|
break;
|
|
|
|
};
|
2016-11-17 22:07:22 +00:00
|
|
|
$.ajax({
|
|
|
|
method: "POST",
|
2017-01-06 09:52:12 +00:00
|
|
|
url: url,
|
2016-11-17 22:07:22 +00:00
|
|
|
data: {
|
2017-01-09 14:43:56 +00:00
|
|
|
name: query,
|
|
|
|
limit: 20
|
2016-11-17 22:07:22 +00:00
|
|
|
},
|
|
|
|
dataType: 'json',
|
2017-01-06 09:52:12 +00:00
|
|
|
success: render_result
|
2016-11-17 22:07:22 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-01-06 09:52:12 +00:00
|
|
|
function switch_menu(type) {
|
2017-01-08 08:36:13 +00:00
|
|
|
$('#app-navigation').find('li').removeClass("active");
|
|
|
|
$("tbody > tr").remove();
|
2017-01-06 09:52:12 +00:00
|
|
|
switch (type) {
|
|
|
|
case 0:
|
|
|
|
$('li.nav-files').addClass('active');
|
|
|
|
radio_query(1);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
$('li.nav-recent').addClass('active');
|
|
|
|
radio_query(2);
|
|
|
|
break;
|
|
|
|
case 2:
|
2017-08-05 15:59:25 +00:00
|
|
|
$('li.nav-favorites').addClass('active');
|
2017-08-05 11:21:11 +00:00
|
|
|
action_load_favorites();
|
2017-01-06 09:52:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$('a.nav-icon-files').click(function() {
|
|
|
|
switch_menu(0);
|
2016-11-17 22:07:22 +00:00
|
|
|
});
|
2017-01-06 09:52:12 +00:00
|
|
|
|
|
|
|
$('a.nav-icon-recent').click(function() {
|
|
|
|
switch_menu(1);
|
|
|
|
});
|
|
|
|
|
2017-01-08 08:36:13 +00:00
|
|
|
$('a.nav-icon-favorites').click(function() {
|
|
|
|
switch_menu(2);
|
|
|
|
});
|
|
|
|
|
2017-01-09 13:36:07 +00:00
|
|
|
function mySearch(query){
|
2017-08-04 18:29:08 +00:00
|
|
|
if (query != "") {
|
|
|
|
clearTimeout(searchTimeout);
|
|
|
|
searchTimeout = setTimeout(function(){
|
|
|
|
$("tbody > tr").remove();
|
|
|
|
radio_query(0, query);
|
|
|
|
}, 500);
|
|
|
|
};
|
2017-01-09 13:36:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
OC.Plugins.register('OCA.Search', {
|
|
|
|
attach: function(search) {
|
|
|
|
search.setFilter('radio', mySearch);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-08-04 20:08:31 +00:00
|
|
|
$('#playbutton').click(function() {
|
|
|
|
var music = document.getElementById('player');
|
|
|
|
if (music.paused && $("#player").attr("src") != "") {
|
|
|
|
music.play();
|
|
|
|
playbutton.className = "";
|
|
|
|
playbutton.className = "pause";
|
|
|
|
} else {
|
|
|
|
music.pause();
|
|
|
|
playbutton.className = "";
|
|
|
|
playbutton.className = "play";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#volumeslider').slider({
|
|
|
|
orientation: "horizontal",
|
|
|
|
value: player.volume,
|
|
|
|
min: 0,
|
|
|
|
max: 1,
|
|
|
|
range: 'min',
|
|
|
|
animate: true,
|
|
|
|
step: .1,
|
|
|
|
slide: function(e, ui) {
|
|
|
|
player.volume = ui.value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-01-06 09:52:12 +00:00
|
|
|
switch_menu(0);
|
2016-11-17 22:07:22 +00:00
|
|
|
});
|