Skip to content

Instantly share code, notes, and snippets.

@danieltroger
Last active May 16, 2018 18:24
Show Gist options
  • Save danieltroger/1cd4a116c9765cebd012c57776219543 to your computer and use it in GitHub Desktop.
Save danieltroger/1cd4a116c9765cebd012c57776219543 to your computer and use it in GitHub Desktop.
Radio shit
<!DOCTYPE html>
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-title" content="Radio" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Radio</title>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Ubuntu" />
<script>
function rand (min, max) {
// discuss at: http://locutus.io/php/rand/
// original by: Leslie Hoare
// bugfixed by: Onno Marsman (https://twitter.com/onnomarsman)
// note 1: See the commented out code below for a version which
// note 1: will work with our experimental (though probably unnecessary)
// note 1: srand() function)
// example 1: rand(1, 1)
// returns 1: 1
var argc = arguments.length
if (argc === 0) {
min = 0
max = 2147483647
} else if (argc === 1) {
throw new Error('Warning: rand() expects exactly 2 parameters, 1 given')
}
return Math.floor(Math.random() * (max - min + 1)) + min
}
var interval = 0,
stations = {
88.8: {
stream: "http://rbb-radioberlin-live.cast.addradio.de/rbb/radioberlin/live/mp3/128/stream.mp3",
now_playing: function(callback)
{
$.ajax({
type: "GET",
async: true,
url: "https://www.radioberlin.de/livestream/index.htm/SSI=true/box=2/module=livestream%21middleColumnList.html?_"+(Math.floor(new Date().getTime() / 1000)),
}).done(function(m){
callback($(m).text());
});
}
},
91.4:
{
//stream: "http://stream.berliner-rundfunk.de/brf/mp3-128/internetradio",
stream: "https://topradio-de-hz-fal-stream08-cluster01.radiohost.de/brf_128",
now_playing: function(callback)
{
var script = document.createElement("script"),
fn = "f"+rand();
eval('window.'+fn+' = function(json){var fn = "'+fn+'";$("#"+fn).remove();var res = json.results[76];if(res.length == 2){callback(res[1].name+"\\n"+res[1].artistName)}else{callback("Es läuft gerade keine Musik")}eval("delete window."+fn+"")}');
script.src = "https://np.radioplayer.de/qp/v3/onair?rpIds=76&nameSize=200&artistNameSize=200&descriptionSize=200&callback="+fn+"&_="+(Math.floor(new Date().getTime() / 1000));
script.type = "text/javascript";
script.id = fn;
document.body.appendChild(script);
}
},
93.6:
{
stream: "http://stream.jam.fm/jamfm-live/mp3-128/konsole/",
now_playing: function(callback)
{
var script = document.createElement("script"),
fn = "f"+rand();
eval('window.'+fn+' = function(json){var fn = "'+fn+'";$("#"+fn).remove();var res = json.results[124];if(res.length == 2){callback(res[1].name+"\\n"+res[1].artistName)}else{callback("Es läuft gerade keine Musik")}eval("delete window."+fn+"")}');
script.src = "https://np.radioplayer.de/qp/v3/onair?rpIds=124&nameSize=200&artistNameSize=200&descriptionSize=200&callback="+fn+"&_="+(Math.floor(new Date().getTime() / 1000));
script.type = "text/javascript";
script.id = fn;
document.body.appendChild(script);
}
},
94.3:
{
stream: "http://stream.rs2.de/rs2/mp3-128/internetradio/",
now_playing: function(callback)
{
var script = document.createElement("script"),
fn = "f"+rand();
eval('window.'+fn+' = function(json){var fn = "'+fn+'";$("#"+fn).remove();var res = json.results[77];if(res.length == 2){callback(res[1].name+"\\n"+res[1].artistName)}else{callback("Es läuft gerade keine Musik")}eval("delete window."+fn+"")}');
script.src = "https://np.radioplayer.de/qp/v3/onair?rpIds=77&nameSize=200&artistNameSize=200&descriptionSize=200&callback="+fn+"&_="+(Math.floor(new Date().getTime() / 1000));
script.type = "text/javascript";
script.id = fn;
document.body.appendChild(script);
}
}
};
window.addEventListener("load",function()
{
var i = 0, ks = Object.keys(stations),firststation = stations[ks[0]];
window.np = document.createElement("div");
np.id = "np";
document.body.appendChild(np);
window.ap = document.createElement("audio");
ap.src = firststation.stream;
ap.controls = true;
ap.autoplay = true;
document.body.appendChild(ap);
ap.play();
document.body.appendChild(document.createElement("br"))
window.dds = document.createElement("select");
for(; i<ks.length; i++)
{
var itm = document.createElement("option");
itm.value = ks[i];
itm.innerHTML = ks[i];
dds.appendChild(itm);
}
document.body.appendChild(dds);
interval = setInterval(function(){firststation.now_playing(function(text){document.getElementById("np").innerHTML = ap.src+"<br />"+text})},1000);
dds.addEventListener("change",function(e){
clearInterval(interval);
var station = parseFloat(e.target.value);
ap.pause();
ap.src = stations[station].stream;
interval = setInterval(function(){stations[station].now_playing(function(text){document.getElementById("np").innerHTML = ap.src+"<br />"+text})},5000);
ap.play();
});
});
</script>
<style>
select
{
font-size: 10vh;
height: 20vh;
width: 90vw;
}
#np
{
font-family: ubuntu;
font-size: 20pt;
}
</style>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment