Skip to content

Instantly share code, notes, and snippets.

@theeternalsw0rd
Created February 20, 2014 22:38
Show Gist options
  • Save theeternalsw0rd/9124777 to your computer and use it in GitHub Desktop.
Save theeternalsw0rd/9124777 to your computer and use it in GitHub Desktop.
DTNS Current
<!DOCTYPE html>
<html>
<head>
<title>DTNS Current</title>
<style>
body { background: #111; font-size: 18px; }
#video { width: 80%; margin: auto }
#summary { width: 80%; margin: auto; color: #eee; padding: 1em;
</style>
</head>
<body>
<div id="video"></div>
<div id="summary"></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
function embedVideo(entry) {
$('#summary').html(entry.summary.$t);
var video = entry.content.src.split('/');
video = video[video.length - 1].split('?')[0];
var width = $('#video').width();
var height = (width * 9) / 16;
$('#video').html("<iframe height='" + height + "' width='" + width + "' src='//www.youtube.com/embed/" + video + "?autoplay=1' frameborder='0' allowfullscreen></iframe>");
}
function getDate() {
var date = new Date();
var dd = date.getDate() - 1;
var mm = date.getMonth() + 1;
var yyyy = date.getFullYear();
if(dd<10){dd='0'+dd} if(mm<10){mm='0'+mm}
return yyyy + '-' + mm + '-' + dd;
}
function checkActive() {
$.getJSON(window.feed + getDate() + "&status=active", function(data) {
if(typeof data.feed.entry === "undefined") return;
var entry = data.feed.entry;
if(entry.length > 0) {
embedVideo(entry[entry.length - 1]);
clearInterval(window.active);
}
});
}
function checkPending() {
$.getJSON(window.feed + getDate() + "&status=pending", function(data) {
if(typeof data.feed.entry === "undefined") return;
var entry = data.feed.entry;
if(entry.length > 0) {
embedVideo(entry[entry.length - 1]);
window.active = setInterval(checkActive, 2000);
clearInterval(window.pending);
}
});
}
window.feed = "https://gdata.youtube.com/feeds/api/users/acedtect/live/events?v=2&alt=json&starts-after=";
$.getJSON(window.feed + getDate(), function(data) {
var entry = data.feed.entry;
if(entry.length > 0) {
embedVideo(entry[entry.length -1]);
}
});
window.pending = setInterval(checkPending, 60000);
$(window).resize(function() {
var width = $('#video').width();
var height = (width * 9) / 16;
$('#video > iframe').attr('height', height).attr('width', width);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment