151 lines
4.0 KiB
JavaScript
151 lines
4.0 KiB
JavaScript
$(function(){
|
|
|
|
searchTimeout = null;
|
|
|
|
/*$('body').on('click', 'tr', function() {
|
|
var stationid = $(this).attr('data-id');
|
|
play_station(stationid);
|
|
}); */
|
|
|
|
$('body').on('click', 'tr .icon', function() {
|
|
alert('test');
|
|
});
|
|
|
|
$('.icon-star').click(function (){
|
|
alert('test');
|
|
});
|
|
|
|
function play_station(stationid){
|
|
$.ajax({
|
|
method: "GET",
|
|
url: "http://www.radio-browser.info/webservice/v2/json/url/"+stationid,
|
|
dataType: 'json',
|
|
success: function(data){
|
|
var sourceUrl = data['url'];
|
|
$("#player").attr("src", sourceUrl);
|
|
$('#player').trigger('play');
|
|
return true;
|
|
}
|
|
});
|
|
};
|
|
|
|
function render_result(data){
|
|
$.each(data, function(i, station) {
|
|
$('tbody').append('<tr data-src='+station['url']+' data-id='+station['id']+'>\
|
|
<td class="filename">\
|
|
<a href="#" class="action action-favorite" onclick="station_fav();">\
|
|
<span class="icon icon-star"></span>\
|
|
<span class="hidden-visually">Favorite</span>\
|
|
</a>\
|
|
<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>');
|
|
});
|
|
}
|
|
|
|
function get_station_ids(){
|
|
var stations = []
|
|
var baseUrl = OC.generateUrl('/apps/radio');
|
|
var station = {
|
|
"id": 16,
|
|
"stationid": "89920",
|
|
"active": true
|
|
};
|
|
$.get(baseUrl + '/stations', function ( data ) {
|
|
for (var station in data) {
|
|
stations.push(data[station]["stationid"]);
|
|
};
|
|
render_stations(stations);
|
|
});
|
|
};
|
|
|
|
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
|
|
});
|
|
};
|
|
};
|
|
|
|
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;
|
|
};
|
|
$.ajax({
|
|
method: "POST",
|
|
url: url,
|
|
data: {
|
|
name: query,
|
|
limit: 20
|
|
},
|
|
dataType: 'json',
|
|
success: render_result
|
|
});
|
|
};
|
|
|
|
function switch_menu(type) {
|
|
$('#app-navigation').find('li').removeClass("active");
|
|
$("tbody > tr").remove();
|
|
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:
|
|
$('li.nav-favorite').addClass('active');
|
|
get_station_ids();
|
|
break;
|
|
}
|
|
}
|
|
|
|
$('a.nav-icon-files').click(function() {
|
|
switch_menu(0);
|
|
});
|
|
|
|
$('a.nav-icon-recent').click(function() {
|
|
switch_menu(1);
|
|
});
|
|
|
|
$('a.nav-icon-favorites').click(function() {
|
|
switch_menu(2);
|
|
});
|
|
|
|
function mySearch(query){
|
|
if (query != "") {
|
|
clearTimeout(searchTimeout);
|
|
searchTimeout = setTimeout(function(){
|
|
$("tbody > tr").remove();
|
|
radio_query(0, query);
|
|
}, 500);
|
|
};
|
|
};
|
|
|
|
OC.Plugins.register('OCA.Search', {
|
|
attach: function(search) {
|
|
search.setFilter('radio', mySearch);
|
|
}
|
|
});
|
|
|
|
switch_menu(0);
|
|
});
|