-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathindex.html
284 lines (251 loc) · 8.41 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My YouTube Video Album</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
:root {
--bg-color: #1a1a1a;
--text-color: #ffffff;
--accent-color: #ff4500;
--secondary-bg: #2a2a2a;
}
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: var(--bg-color);
color: var(--text-color);
}
.container {
display: grid;
grid-template-columns: 250px 1fr;
grid-template-rows: auto 1fr;
min-height: 100vh;
}
header {
grid-column: 1 / -1;
background-color: var(--secondary-bg);
padding: 1rem;
text-align: center;
}
.sidebar {
background-color: var(--secondary-bg);
padding: 1rem;
}
.main-content {
padding: 1rem;
}
.video-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 1rem;
}
.video-item {
position: relative;
overflow: hidden;
border-radius: 8px;
transition: transform 0.3s ease;
}
.video-item:hover {
transform: scale(1.05);
}
.video-item img {
width: 100%;
height: auto;
}
.video-info {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: rgba(0, 0, 0, 0.7);
padding: 0.5rem;
}
.video-title {
font-size: 0.9rem;
margin-bottom: 0.3rem;
}
.video-tags {
font-size: 0.8rem;
color: var(--accent-color);
}
.play-button {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 3rem;
color: var(--accent-color);
opacity: 0;
transition: opacity 0.3s ease;
}
.video-item:hover .play-button {
opacity: 1;
}
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.9);
}
.modal-content {
position: relative;
margin: 5% auto;
padding: 20px;
width: 80%;
max-width: 800px;
background-color: var(--secondary-bg);
border-radius: 8px;
}
.close {
color: var(--text-color);
float: right;
font-size: 28px;
font-weight: bold;
cursor: pointer;
}
input, button {
width: 100%;
padding: 0.5rem;
margin-bottom: 1rem;
border: none;
border-radius: 4px;
}
button {
background-color: var(--accent-color);
color: var(--text-color);
cursor: pointer;
}
button:hover {
opacity: 0.8;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>My YouTube Video Album</h1>
</header>
<aside class="sidebar">
<h2>Add Video</h2>
<input type="text" id="video-url" placeholder="Enter YouTube URL">
<button id="add-video">Add Video</button>
<h2>Search</h2>
<input type="text" id="search-input" placeholder="Search by title or tag">
<div id="tag-cloud"></div>
</aside>
<main class="main-content">
<div id="video-grid" class="video-grid"></div>
</main>
</div>
<div id="video-modal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<div id="player"></div>
<h2 id="modal-title"></h2>
<p id="modal-description"></p>
<div id="modal-tags"></div>
</div>
</div>
<script src="https://www.youtube.com/iframe_api"></script>
<script>
const API_URL = 'http://localhost:7717';
let player;
// Fetch and display videos
async function fetchVideos() {
const response = await fetch(`${API_URL}/videos`);
const videos = await response.json();
displayVideos(videos);
updateTagCloud(videos);
}
function displayVideos(videos) {
const grid = document.getElementById('video-grid');
grid.innerHTML = '';
videos.forEach(video => {
const item = document.createElement('div');
item.className = 'video-item';
item.innerHTML = `
<img src="https://img.youtube.com/vi/${video.youtube_id}/mqdefault.jpg" alt="${video.title}">
<div class="video-info">
<div class="video-title">${video.title}</div>
<div class="video-tags">${video.tags}</div>
</div>
<i class="fas fa-play-circle play-button"></i>
`;
item.addEventListener('click', () => openVideoModal(video));
grid.appendChild(item);
});
}
function updateTagCloud(videos) {
const tagCloud = document.getElementById('tag-cloud');
const tags = videos.flatMap(video => video.tags.split(','));
const uniqueTags = [...new Set(tags)];
tagCloud.innerHTML = uniqueTags.map(tag => `<span class="tag">${tag}</span>`).join(' ');
}
// Add new video
document.getElementById('add-video').addEventListener('click', async () => {
const url = document.getElementById('video-url').value;
const videoId = extractVideoId(url);
if (videoId) {
const response = await fetch(`${API_URL}/videos`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ youtube_id: videoId })
});
if (response.ok) {
fetchVideos();
document.getElementById('video-url').value = '';
} else {
alert('Failed to add video');
}
} else {
alert('Invalid YouTube URL');
}
});
function extractVideoId(url) {
const regex = /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/;
const match = url.match(regex);
return match ? match[1] : null;
}
// Search functionality
document.getElementById('search-input').addEventListener('input', async (e) => {
const query = e.target.value;
const response = await fetch(`${API_URL}/videos/search?q=${query}`);
const videos = await response.json();
displayVideos(videos);
});
// Video modal
function openVideoModal(video) {
const modal = document.getElementById('video-modal');
document.getElementById('modal-title').textContent = video.title;
document.getElementById('modal-description').textContent = video.description;
document.getElementById('modal-tags').textContent = video.tags;
modal.style.display = 'block';
if (player) {
player.loadVideoById(video.youtube_id);
} else {
player = new YT.Player('player', {
height: '360',
width: '640',
videoId: video.youtube_id,
});
}
}
document.querySelector('.close').addEventListener('click', () => {
document.getElementById('video-modal').style.display = 'none';
if (player) {
player.stopVideo();
}
});
// Initialize
fetchVideos();
</script>
</body>
</html>