· 6 years ago · Dec 06, 2019, 03:40 PM
1<!DOCTYPE html>
2<html>
3 <head>
4 <title>jutup</title>
5 <meta charset="utf-8" />
6 <style>
7 #video {
8 display: none;
9 }
10 </style>
11 <!-- polyfill do IE -->
12 <script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"></script>
13 <script src="fetch.umd.js"></script>
14 </head>
15 <body>
16 <iframe id="video" width="560" height="315" src="" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
17 <script>
18 // const videoId = "gJjOLRouz7U";
19 const videoId = "vHf8g-6HzaQ"; // działający livestream RP
20 const apiKey = "AIzaSyBXh0AktpWSTtqt5gBLQSpEXDuMCqHtm4k"; // api key do zmiany bo na moim koncie
21 let videoData = null;
22 let isLive = false;
23 let videoElement = document.getElementById("video");
24
25 fetch("https://www.googleapis.com/youtube/v3/videos?id=" + videoId + "&key=" + apiKey + "&part=snippet&fields=items(id,snippet(liveBroadcastContent))")
26 .then(function(response) {
27 return response.json();
28 })
29 .then(function(json) {
30 // console.log(json);
31 videoData = json;
32 isLive = videoData.items[0].snippet.liveBroadcastContent == "live" ? true : false;
33 if (isLive) {
34 videoElement.style.display = "block";
35 videoElement.src = "https://www.youtube.com/embed/" + videoId + "?&autoplay=1";
36 }
37 }
38 );
39 </script>
40 </body>
41</html>