-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
112 lines (97 loc) · 3.36 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>IMG_2208</title>
<style>
/* Centering content and adding padding for better readability */
body {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
}
/* Responsive container for video */
#videoContainer {
position: relative;
width: 100%;
max-width: 1200px; /* Limits the width on larger screens */
padding-bottom: 56.25%; /* 16:9 aspect ratio */
height: 0;
margin-top: 20px;
}
#videoContainer iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
/* Center-aligning the button and setting a max width for larger screens */
#playButton {
max-width: 200px;
margin-top: 20px;
}
</style>
<script src="https://www.youtube.com/iframe_api"></script>
</head>
<body>
<h1>IMG_2208</h1>
<p>I was going through <a href="https://en.wikipedia.org/wiki/Design_rule_for_Camera_File_system">Design rule for Camera File system</a> and found out from a blog there
a lot of people upload unedited, unfiltered videos with iOS filenames. <b> There’s something surreal about these videos! </b> (Note: Total 10,000 tokens per day because of YouTube API policy)</p>
<br>
<button id="playButton">Play Another Video</button>
<div id="videoContainer"></div>
<script>
const apiKey = 'AIzaSyDXtEZecNxx4vFfDHLt7CIT25NS8eQ7n1o';
let player;
function getRandomFileName() {
const randomNum = Math.floor(Math.random() * 10000);
return `IMG_${String(randomNum).padStart(4, '0')}`;
}
async function searchVideo() {
const query = getRandomFileName();
const url = `https://www.googleapis.com/youtube/v3/search?part=snippet&q=${query}&type=video&maxResults=1&key=${apiKey}`;
try {
const response = await fetch(url);
const data = await response.json();
if (data.items && data.items.length > 0) {
const videoId = data.items[0].id.videoId;
displayVideo(videoId);
} else {
alert("Limit exceeded. Total 100 videos per day because of YouTube API policy");
}
} catch (error) {
console.error("Error fetching video:", error);
}
}
function displayVideo(videoId) {
const videoContainer = document.getElementById("videoContainer");
videoContainer.innerHTML = ""; // Clear previous video
// Create a new YouTube player
const iframe = document.createElement('iframe');
iframe.src = `https://www.youtube.com/embed/${videoId}?enablejsapi=1&autoplay=1`;
iframe.frameBorder = "0";
iframe.allow = "autoplay; encrypted-media";
iframe.allowFullscreen = true;
iframe.id = "ytplayer";
videoContainer.appendChild(iframe);
onYouTubeIframeAPIReady();
}
function onYouTubeIframeAPIReady() {
player = new YT.Player('ytplayer', {
events: {
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerStateChange(event) {
if (event.data === YT.PlayerState.ENDED) {
document.getElementById("playButton").click();
}
}
document.getElementById("playButton").addEventListener("click", searchVideo);
</script>
</body>
</html>