beppe1234 commited on
Commit
d27dbd6
·
verified ·
1 Parent(s): 039fcc2

Add 2 files

Browse files
Files changed (2) hide show
  1. README.md +6 -4
  2. index.html +850 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Videoaieditor
3
- emoji: 🐢
4
- colorFrom: indigo
5
  colorTo: gray
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: videoaieditor
3
+ emoji: 🐳
4
+ colorFrom: red
5
  colorTo: gray
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,850 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>AI Video Highlight Generator</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
9
+ <!-- YouTube Iframe API -->
10
+ <script src="https://www.youtube.com/iframe_api"></script>
11
+ <style>
12
+ .waveform {
13
+ height: 100px;
14
+ background: linear-gradient(90deg, #4f46e5 0%, #10b981 100%);
15
+ border-radius: 8px;
16
+ position: relative;
17
+ overflow: hidden;
18
+ }
19
+ .waveform-progress {
20
+ position: absolute;
21
+ top: 0;
22
+ left: 0;
23
+ height: 100%;
24
+ width: 0;
25
+ background-color: rgba(255, 255, 255, 0.2);
26
+ pointer-events: none;
27
+ }
28
+ .waveform-marker {
29
+ position: absolute;
30
+ top: 0;
31
+ height: 100%;
32
+ width: 2px;
33
+ background-color: white;
34
+ z-index: 10;
35
+ }
36
+ .highlight-clip {
37
+ position: absolute;
38
+ height: 100%;
39
+ background-color: rgba(255, 255, 0, 0.3);
40
+ border-left: 2px solid yellow;
41
+ border-right: 2px solid yellow;
42
+ }
43
+ .subtitle-display {
44
+ background-color: rgba(0, 0, 0, 0.7);
45
+ border-radius: 8px;
46
+ padding: 12px 24px;
47
+ max-width: 80%;
48
+ margin: 0 auto;
49
+ font-size: 1.2rem;
50
+ text-align: center;
51
+ transition: all 0.3s ease;
52
+ }
53
+ .loading-spinner {
54
+ animation: spin 1s linear infinite;
55
+ }
56
+ @keyframes spin {
57
+ 0% { transform: rotate(0deg); }
58
+ 100% { transform: rotate(360deg); }
59
+ }
60
+ .file-upload-label:hover {
61
+ background-color: #4f46e5;
62
+ }
63
+ .youtube-input:hover {
64
+ background-color: #10b981;
65
+ }
66
+ #youtubePlayer {
67
+ width: 100%;
68
+ aspect-ratio: 16/9;
69
+ background: #000;
70
+ }
71
+ .player-container {
72
+ position: relative;
73
+ }
74
+ .player-overlay {
75
+ position: absolute;
76
+ top: 0;
77
+ left: 0;
78
+ right: 0;
79
+ bottom: 0;
80
+ pointer-events: none;
81
+ display: flex;
82
+ align-items: center;
83
+ justify-content: center;
84
+ flex-direction: column;
85
+ background: rgba(0,0,0,0.5);
86
+ z-index: 10;
87
+ }
88
+ .thumbnail-overlay {
89
+ background-size: cover;
90
+ background-position: center;
91
+ }
92
+ </style>
93
+ </head>
94
+ <body class="bg-gray-900 text-gray-100 min-h-screen">
95
+ <div class="container mx-auto px-4 py-8">
96
+ <header class="text-center mb-12">
97
+ <h1 class="text-4xl font-bold text-transparent bg-clip-text bg-gradient-to-r from-purple-400 to-emerald-400 mb-2">
98
+ AI Video Highlight Generator
99
+ </h1>
100
+ <p class="text-lg text-gray-400 max-w-2xl mx-auto">
101
+ Upload a video or paste a YouTube URL to automatically extract the most interesting moments with AI-generated subtitles.
102
+ </p>
103
+ </header>
104
+
105
+ <div class="max-w-4xl mx-auto bg-gray-800 rounded-xl shadow-2xl overflow-hidden">
106
+ <!-- Input Section -->
107
+ <div class="p-6 border-b border-gray-700">
108
+ <div class="flex flex-col md:flex-row gap-4">
109
+ <!-- File Upload -->
110
+ <div class="flex-1">
111
+ <input type="file" id="fileInput" accept="video/*" class="hidden">
112
+ <label for="fileInput" class="file-upload-label flex flex-col items-center justify-center p-8 border-2 border-dashed border-purple-500 rounded-lg cursor-pointer hover:bg-purple-900/20 transition-colors">
113
+ <i class="fas fa-cloud-upload-alt text-4xl text-purple-400 mb-3"></i>
114
+ <h3 class="text-xl font-semibold mb-1">Upload Video</h3>
115
+ <p class="text-gray-400 text-sm">MP4, MOV, AVI up to 100MB</p>
116
+ </label>
117
+ </div>
118
+
119
+ <!-- Or Divider -->
120
+ <div class="flex items-center justify-center">
121
+ <div class="h-px w-16 bg-gray-600 md:h-16 md:w-px"></div>
122
+ </div>
123
+
124
+ <!-- YouTube Input -->
125
+ <div class="flex-1">
126
+ <div class="youtube-input flex flex-col h-full p-4 border-2 border-dashed border-emerald-500 rounded-lg hover:bg-emerald-900/20 transition-colors">
127
+ <div class="flex items-center mb-3">
128
+ <i class="fab fa-youtube text-4xl text-red-500 mr-3"></i>
129
+ <h3 class="text-xl font-semibold">YouTube URL</h3>
130
+ </div>
131
+ <div class="flex gap-2">
132
+ <input type="text" id="youtubeUrl" placeholder="https://youtube.com/watch?v=..." class="flex-1 bg-gray-700 rounded px-4 py-2 text-white focus:outline-none focus:ring-2 focus:ring-emerald-500">
133
+ <button id="loadYoutubeBtn" class="bg-emerald-600 hover:bg-emerald-500 px-4 py-2 rounded font-medium transition-colors">
134
+ Load
135
+ </button>
136
+ </div>
137
+ </div>
138
+ </div>
139
+ </div>
140
+
141
+ <div id="uploadProgress" class="hidden mt-4">
142
+ <div class="flex items-center gap-3 text-purple-400">
143
+ <i class="fas fa-spinner loading-spinner"></i>
144
+ <span id="progressText">Processing your video...</span>
145
+ </div>
146
+ <div id="progressBar" class="w-full bg-gray-700 rounded-full h-2.5 mt-2">
147
+ <div id="progressBarFill" class="bg-emerald-500 h-2.5 rounded-full" style="width: 0%"></div>
148
+ </div>
149
+ </div>
150
+ </div>
151
+
152
+ <!-- Video Player Section -->
153
+ <div id="videoSection" class="hidden p-6 border-b border-gray-700">
154
+ <div class="player-container">
155
+ <div id="youtubePlayer"></div>
156
+ <video id="videoPlayer" controls class="w-full hidden rounded-lg bg-black aspect-video"></video>
157
+ <div id="playerOverlay" class="player-overlay hidden">
158
+ <div class="text-xl font-semibold mb-2">Video Preview</div>
159
+ <button id="playVideoBtn" class="bg-purple-600 hover:bg-purple-500 w-16 h-16 rounded-full flex items-center justify-center transition-colors pointer-events-auto">
160
+ <i class="fas fa-play text-2xl"></i>
161
+ </button>
162
+ </div>
163
+ <div id="subtitleContainer" class="subtitle-display hidden absolute bottom-8 left-0 right-0"></div>
164
+ </div>
165
+
166
+ <div class="flex justify-between items-center mt-4">
167
+ <div class="flex items-center gap-4">
168
+ <button id="playBtn" class="bg-purple-600 hover:bg-purple-500 w-12 h-12 rounded-full flex items-center justify-center transition-colors">
169
+ <i class="fas fa-play"></i>
170
+ </button>
171
+ <button id="pauseBtn" class="bg-gray-700 hover:bg-gray-600 w-12 h-12 rounded-full flex items-center justify-center transition-colors">
172
+ <i class="fas fa-pause"></i>
173
+ </button>
174
+ <div class="text-sm text-gray-400">
175
+ <span id="currentTime">00:00</span> / <span id="duration">00:00</span>
176
+ </div>
177
+ </div>
178
+
179
+ <button id="processBtn" class="bg-gradient-to-r from-purple-600 to-emerald-600 hover:from-purple-500 hover:to-emerald-500 px-6 py-3 rounded-full font-medium transition-all transform hover:scale-105">
180
+ <i class="fas fa-magic mr-2"></i> Generate Highlights
181
+ </button>
182
+ </div>
183
+ </div>
184
+
185
+ <!-- Waveform & Highlights Section -->
186
+ <div id="waveformContainer" class="hidden p-6 border-b border-gray-700">
187
+ <h3 class="text-lg font-semibold mb-4">Video Analysis</h3>
188
+ <div class="waveform relative cursor-pointer mb-4">
189
+ <div class="waveform-progress"></div>
190
+ <div class="waveform-marker"></div>
191
+ <!-- Highlight clips will be added here by JavaScript -->
192
+ </div>
193
+
194
+ <div id="highlightClips" class="grid grid-cols-1 md:grid-cols-2 gap-4">
195
+ <!-- Highlight clips will be added here by JavaScript -->
196
+ </div>
197
+ </div>
198
+
199
+ <!-- Results Section -->
200
+ <div id="resultsSection" class="hidden p-6">
201
+ <div class="flex justify-between items-center mb-6">
202
+ <h3 class="text-xl font-semibold">Your Highlights</h3>
203
+ <button id="downloadBtn" class="bg-gradient-to-r from-purple-600 to-emerald-600 hover:from-purple-500 hover:to-emerald-500 px-6 py-3 rounded-full font-medium transition-all flex items-center gap-2">
204
+ <i class="fas fa-download"></i> Download All
205
+ </button>
206
+ </div>
207
+
208
+ <div id="highlightResults" class="grid grid-cols-1 gap-6">
209
+ <!-- Highlight results will be added here by JavaScript -->
210
+ </div>
211
+ </div>
212
+
213
+ <!-- Empty State -->
214
+ <div id="emptyState" class="p-12 text-center">
215
+ <i class="fas fa-video text-6xl text-gray-600 mb-4"></i>
216
+ <h3 class="text-xl font-semibold mb-2">No Video Loaded</h3>
217
+ <p class="text-gray-500 max-w-md mx-auto">
218
+ Upload a video file or paste a YouTube URL above to get started.
219
+ </p>
220
+ </div>
221
+ </div>
222
+
223
+ <div class="mt-12 text-center text-gray-500 text-sm">
224
+ <p>Powered by AI video analysis technology. Processing may take a few moments.</p>
225
+ </div>
226
+ </div>
227
+
228
+ <script>
229
+ document.addEventListener('DOMContentLoaded', function() {
230
+ // DOM Elements
231
+ const fileInput = document.getElementById('fileInput');
232
+ const youtubeUrl = document.getElementById('youtubeUrl');
233
+ const loadYoutubeBtn = document.getElementById('loadYoutubeBtn');
234
+ const youtubePlayerElement = document.getElementById('youtubePlayer');
235
+ const videoPlayer = document.getElementById('videoPlayer');
236
+ const playBtn = document.getElementById('playBtn');
237
+ const pauseBtn = document.getElementById('pauseBtn');
238
+ const playVideoBtn = document.getElementById('playVideoBtn');
239
+ const processBtn = document.getElementById('processBtn');
240
+ const downloadBtn = document.getElementById('downloadBtn');
241
+ const currentTimeEl = document.getElementById('currentTime');
242
+ const durationEl = document.getElementById('duration');
243
+ const waveformContainer = document.getElementById('waveformContainer');
244
+ const waveform = document.querySelector('.waveform');
245
+ let waveformProgress = document.querySelector('.waveform-progress');
246
+ let waveformMarker = document.querySelector('.waveform-marker');
247
+ const highlightClips = document.getElementById('highlightClips');
248
+ const highlightResults = document.getElementById('highlightResults');
249
+ const subtitleContainer = document.getElementById('subtitleContainer');
250
+ const videoSection = document.getElementById('videoSection');
251
+ const emptyState = document.getElementById('emptyState');
252
+ const uploadProgress = document.getElementById('uploadProgress');
253
+ const progressBarFill = document.getElementById('progressBarFill');
254
+ const progressText = document.getElementById('progressText');
255
+ const resultsSection = document.getElementById('resultsSection');
256
+ const playerOverlay = document.getElementById('playerOverlay');
257
+
258
+ // State variables
259
+ let videoFile = null;
260
+ let videoBlobUrl = null;
261
+ let videoType = null; // 'file' or 'youtube'
262
+ let videoDuration = 0;
263
+ let isProcessing = false;
264
+ let highlights = [];
265
+ let subtitles = [];
266
+ let waveformData = [];
267
+ let youtubePlayer = null;
268
+ let isYouTubePlaying = false;
269
+ let youtubeCurrentTimer = null;
270
+ let youtubeCurrentTime = 0;
271
+ let youtubeThumbnail = '';
272
+ let youtubeTitle = '';
273
+
274
+ // Event Listeners
275
+ fileInput.addEventListener('change', handleFileSelect);
276
+ loadYoutubeBtn.addEventListener('click', useYouTubeVideo);
277
+ playBtn.addEventListener('click', playVideo);
278
+ pauseBtn.addEventListener('click', pauseVideo);
279
+ playVideoBtn.addEventListener('click', playVideo);
280
+ processBtn.addEventListener('click', processVideo);
281
+ downloadBtn.addEventListener('click', downloadHighlights);
282
+ videoPlayer.addEventListener('timeupdate', updateVideoTime);
283
+ videoPlayer.addEventListener('ended', () => {
284
+ playBtn.innerHTML = '<i class="fas fa-redo"></i>';
285
+ });
286
+ waveform.addEventListener('click', handleWaveformClick);
287
+
288
+ // YouTube API callback
289
+ window.onYouTubeIframeAPIReady = function() {
290
+ // Player will be created when YouTube URL is loaded
291
+ };
292
+
293
+ // Functions
294
+ function handleFileSelect(e) {
295
+ const file = e.target.files[0];
296
+ if (!file) return;
297
+
298
+ if (!file.type.startsWith('video/')) {
299
+ alert('Please select a video file');
300
+ return;
301
+ }
302
+
303
+ // Reset any existing YouTube player
304
+ if (youtubePlayer) {
305
+ youtubePlayer.destroy();
306
+ youtubePlayer = null;
307
+ youtubePlayerElement.innerHTML = '';
308
+ youtubePlayerElement.classList.add('hidden');
309
+ }
310
+
311
+ videoFile = file;
312
+ videoType = 'file';
313
+ showUploadProgress('Processing video file...');
314
+
315
+ // Display video
316
+ videoBlobUrl = URL.createObjectURL(file);
317
+ setupFileVideoPlayer();
318
+ }
319
+
320
+ function useYouTubeVideo() {
321
+ const url = youtubeUrl.value.trim();
322
+ if (!url) {
323
+ alert('Please enter a YouTube URL');
324
+ return;
325
+ }
326
+
327
+ // Extract video ID from URL
328
+ const videoId = extractYouTubeId(url);
329
+ if (!videoId) {
330
+ alert('Please enter a valid YouTube URL');
331
+ return;
332
+ }
333
+
334
+ // Clean up any existing video
335
+ if (videoBlobUrl) {
336
+ URL.revokeObjectURL(videoBlobUrl);
337
+ videoBlobUrl = null;
338
+ }
339
+ videoPlayer.src = '';
340
+ videoPlayer.classList.add('hidden');
341
+
342
+ videoType = 'youtube';
343
+ showUploadProgress('Loading YouTube video...');
344
+
345
+ // Load YouTube player
346
+ loadYouTubeVideo(videoId);
347
+ }
348
+
349
+ function extractYouTubeId(url) {
350
+ const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/;
351
+ const match = url.match(regExp);
352
+ return (match && match[2].length === 11) ? match[2] : null;
353
+ }
354
+
355
+ function loadYouTubeVideo(videoId) {
356
+ // First get video info
357
+ fetch(`https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=${videoId}&format=json`)
358
+ .then(response => {
359
+ if (!response.ok) throw new Error('Invalid YouTube URL');
360
+ return response.json();
361
+ })
362
+ .then(data => {
363
+ youtubeTitle = data.title;
364
+ youtubeThumbnail = `https://img.youtube.com/vi/${videoId}/mqdefault.jpg`;
365
+
366
+ // Set up player overlay
367
+ playerOverlay.style.background = `url('${youtubeThumbnail}') center/cover no-repeat`;
368
+ playerOverlay.classList.remove('hidden');
369
+
370
+ // Update progress bar
371
+ updateProgress(50, 'Loading YouTube player...');
372
+
373
+ // Create YouTube player
374
+ if (!window.YT) {
375
+ throw new Error('YouTube API not loaded');
376
+ }
377
+
378
+ youtubePlayer = new YT.Player('youtubePlayer', {
379
+ height: '100%',
380
+ width: '100%',
381
+ videoId: videoId,
382
+ playerVars: {
383
+ 'autoplay': 0,
384
+ 'controls': 0,
385
+ 'disablekb': 1,
386
+ 'modestbranding': 1,
387
+ 'rel': 0
388
+ },
389
+ events: {
390
+ 'onReady': onYouTubePlayerReady,
391
+ 'onStateChange': onYouTubePlayerStateChange,
392
+ 'onError': onYouTubePlayerError
393
+ }
394
+ });
395
+
396
+ youtubePlayerElement.classList.remove('hidden');
397
+ youtubePlayerElement.classList.remove('hidden');
398
+ })
399
+ .catch(error => {
400
+ console.error('Error loading YouTube video:', error);
401
+ alert('Error loading YouTube video. Please check the URL and try again.');
402
+ uploadProgress.classList.add('hidden');
403
+ });
404
+ }
405
+
406
+ function onYouTubePlayerReady(event) {
407
+ updateProgress(80, 'Preparing video...');
408
+ setTimeout(() => {
409
+ // Get duration when metadata is available
410
+ setTimeout(() => {
411
+ videoDuration = event.target.getDuration();
412
+ if (videoDuration && !isNaN(videoDuration)) {
413
+ showVideoUI();
414
+ uploadProgress.classList.add('hidden');
415
+ } else {
416
+ // If duration isn't available right away, keep checking
417
+ const interval = setInterval(() => {
418
+ const duration = event.target.getDuration();
419
+ if (duration && !isNaN(duration)) {
420
+ clearInterval(interval);
421
+ videoDuration = duration;
422
+ showVideoUI();
423
+ uploadProgress.classList.add('hidden');
424
+ }
425
+ }, 500);
426
+ }
427
+ }, 500);
428
+ }, 1000);
429
+ }
430
+
431
+ function onYouTubePlayerStateChange(event) {
432
+ switch(event.data) {
433
+ case YT.PlayerState.PLAYING:
434
+ isYouTubePlaying = true;
435
+ startYouTubeTimeTracker();
436
+ playerOverlay.classList.add('hidden');
437
+ break;
438
+ case YT.PlayerState.PAUSED:
439
+ isYouTubePlaying = false;
440
+ stopYouTubeTimeTracker();
441
+ playerOverlay.classList.remove('hidden');
442
+ playBtn.innerHTML = '<i class="fas fa-play"></i>';
443
+ break;
444
+ case YT.PlayerState.ENDED:
445
+ isYouTubePlaying = false;
446
+ stopYouTubeTimeTracker();
447
+ playerOverlay.classList.remove('hidden');
448
+ playBtn.innerHTML = '<i class="fas fa-redo"></i>';
449
+ break;
450
+ }
451
+ }
452
+
453
+ function onYouTubePlayerError(event) {
454
+ console.error('YouTube Player Error:', event.data);
455
+ alert('Error loading YouTube video. Please try again with a different video.');
456
+ uploadProgress.classList.add('hidden');
457
+ }
458
+
459
+ function startYouTubeTimeTracker() {
460
+ stopYouTubeTimeTracker();
461
+ youtubeCurrentTimer = setInterval(() => {
462
+ if (youtubePlayer && youtubePlayer.getCurrentTime) {
463
+ youtubeCurrentTime = youtubePlayer.getCurrentTime();
464
+ updateCurrentTimeDisplay(youtubeCurrentTime);
465
+ updateWaveformProgress(youtubeCurrentTime);
466
+ updateSubtitles(youtubeCurrentTime);
467
+ }
468
+ }, 200);
469
+ }
470
+
471
+ function stopYouTubeTimeTracker() {
472
+ if (youtubeCurrentTimer) {
473
+ clearInterval(youtubeCurrentTimer);
474
+ youtubeCurrentTimer = null;
475
+ }
476
+ }
477
+
478
+ function updateCurrentTimeDisplay(currentTime) {
479
+ const minutes = Math.floor(currentTime / 60);
480
+ const seconds = Math.floor(currentTime % 60);
481
+ currentTimeEl.textContent = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
482
+ }
483
+
484
+ function updateWaveformProgress(currentTime) {
485
+ const progressPercent = (currentTime / videoDuration) * 100;
486
+ waveformProgress.style.width = `${progressPercent}%`;
487
+ waveformMarker.style.left = `${progressPercent}%`;
488
+ }
489
+
490
+ function updateSubtitles(currentTime) {
491
+ if (subtitles.length > 0) {
492
+ const currentSubtitle = subtitles.find(sub =>
493
+ currentTime >= sub.start && currentTime <= sub.end
494
+ );
495
+
496
+ if (currentSubtitle) {
497
+ subtitleContainer.textContent = currentSubtitle.text;
498
+ subtitleContainer.classList.remove('hidden');
499
+ } else {
500
+ subtitleContainer.classList.add('hidden');
501
+ }
502
+ }
503
+ }
504
+
505
+ function setupFileVideoPlayer() {
506
+ videoPlayer.src = videoBlobUrl;
507
+ videoPlayer.classList.remove('hidden');
508
+ playerOverlay.classList.add('hidden');
509
+ processBtn.disabled = false;
510
+ playBtn.disabled = false;
511
+ pauseBtn.disabled = false;
512
+ waveformContainer.classList.remove('hidden');
513
+ videoSection.classList.remove('hidden');
514
+ emptyState.classList.add('hidden');
515
+
516
+ // Wait for metadata to load
517
+ videoPlayer.onloadedmetadata = () => {
518
+ videoDuration = videoPlayer.duration;
519
+ updateDurationDisplay();
520
+ generateWaveformData();
521
+ renderWaveform();
522
+ updateVideoTime();
523
+
524
+ // Hide upload progress
525
+ uploadProgress.classList.add('hidden');
526
+ };
527
+
528
+ // Handle errors
529
+ videoPlayer.onerror = () => {
530
+ alert('Error loading video file');
531
+ uploadProgress.classList.add('hidden');
532
+ };
533
+ }
534
+
535
+ function showVideoUI() {
536
+ updateDurationDisplay();
537
+ generateWaveformData();
538
+ renderWaveform();
539
+ updateCurrentTimeDisplay(0);
540
+ processBtn.disabled = false;
541
+ playBtn.disabled = false;
542
+ pauseBtn.disabled = false;
543
+ waveformContainer.classList.remove('hidden');
544
+ videoSection.classList.remove('hidden');
545
+ emptyState.classList.add('hidden');
546
+ }
547
+
548
+ function showUploadProgress(text) {
549
+ progressText.textContent = text;
550
+ progressBarFill.style.width = '10%';
551
+ uploadProgress.classList.remove('hidden');
552
+ processBtn.disabled = true;
553
+ }
554
+
555
+ function updateProgress(percent, text) {
556
+ progressBarFill.style.width = `${percent}%`;
557
+ if (text) progressText.textContent = text;
558
+ }
559
+
560
+ function playVideo() {
561
+ if (videoType === 'youtube' && youtubePlayer) {
562
+ youtubePlayer.playVideo();
563
+ isYouTubePlaying = true;
564
+ playerOverlay.classList.add('hidden');
565
+ playBtn.innerHTML = '<i class="fas fa-pause"></i>';
566
+ } else if (videoType === 'file') {
567
+ videoPlayer.play();
568
+ playBtn.innerHTML = '<i class="fas fa-pause"></i>';
569
+ }
570
+ }
571
+
572
+ function pauseVideo() {
573
+ if (videoType === 'youtube' && youtubePlayer) {
574
+ youtubePlayer.pauseVideo();
575
+ isYouTubePlaying = false;
576
+ playerOverlay.classList.remove('hidden');
577
+ playBtn.innerHTML = '<i class="fas fa-play"></i>';
578
+ } else if (videoType === 'file') {
579
+ videoPlayer.pause();
580
+ playBtn.innerHTML = '<i class="fas fa-play"></i>';
581
+ }
582
+ }
583
+
584
+ function updateDurationDisplay() {
585
+ if (isNaN(videoDuration) || !isFinite(videoDuration)) {
586
+ durationEl.textContent = '00:00';
587
+ return;
588
+ }
589
+
590
+ const minutes = Math.floor(videoDuration / 60);
591
+ const seconds = Math.floor(videoDuration % 60);
592
+ durationEl.textContent = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
593
+ }
594
+
595
+ function updateVideoTime() {
596
+ const currentTime = videoPlayer.currentTime;
597
+ const minutes = Math.floor(currentTime / 60);
598
+ const seconds = Math.floor(currentTime % 60);
599
+ currentTimeEl.textContent = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
600
+
601
+ // Update waveform progress
602
+ const progressPercent = (currentTime / videoDuration) * 100;
603
+ waveformProgress.style.width = `${progressPercent}%`;
604
+ waveformMarker.style.left = `${progressPercent}%`;
605
+
606
+ // Update subtitle display if we have subtitles
607
+ updateSubtitles(currentTime);
608
+ }
609
+
610
+ function handleWaveformClick(e) {
611
+ const rect = waveform.getBoundingClientRect();
612
+ const clickPosition = e.clientX - rect.left;
613
+ const percent = clickPosition / rect.width;
614
+ const seekTime = percent * videoDuration;
615
+
616
+ if (videoType === 'youtube' && youtubePlayer) {
617
+ youtubePlayer.seekTo(seekTime, true);
618
+ youtubeCurrentTime = seekTime;
619
+ updateCurrentTimeDisplay(seekTime);
620
+ updateWaveformProgress(seekTime);
621
+ updateSubtitles(seekTime);
622
+ } else if (videoType === 'file') {
623
+ videoPlayer.currentTime = seekTime;
624
+ }
625
+ }
626
+
627
+ function generateWaveformData() {
628
+ // In a real app, you would analyze the audio to generate waveform data
629
+ // For this demo, we'll generate random data
630
+ waveformData = [];
631
+ const segments = 200;
632
+
633
+ for (let i = 0; i < segments; i++) {
634
+ waveformData.push(Math.random() * 0.8 + 0.2); // Values between 0.2 and 1.0
635
+ }
636
+ }
637
+
638
+ function renderWaveform() {
639
+ // Clear any existing highlights
640
+ waveform.innerHTML = `
641
+ <div class="waveform-progress"></div>
642
+ <div class="waveform-marker"></div>
643
+ `;
644
+
645
+ // Get references again after clearing
646
+ waveformProgress = document.querySelector('.waveform-progress');
647
+ waveformMarker = document.querySelector('.waveform-marker');
648
+
649
+ // Create waveform visualization
650
+ const segmentWidth = waveform.offsetWidth / waveformData.length;
651
+
652
+ waveformData.forEach((value, index) => {
653
+ const bar = document.createElement('div');
654
+ bar.className = 'absolute bottom-0 bg-purple-400';
655
+ bar.style.left = `${index * segmentWidth}px`;
656
+ bar.style.width = `${segmentWidth}px`;
657
+ bar.style.height = `${value * 100}%`;
658
+ waveform.appendChild(bar);
659
+ });
660
+ }
661
+
662
+ function processVideo() {
663
+ if (isProcessing) return;
664
+ isProcessing = true;
665
+
666
+ // Show processing state
667
+ processBtn.innerHTML = '<i class="fas fa-spinner loading-spinner mr-2"></i> Processing...';
668
+ processBtn.disabled = true;
669
+
670
+ // Simulate AI processing delay
671
+ setTimeout(() => {
672
+ // Generate mock highlights and subtitles
673
+ generateMockHighlights();
674
+ generateMockSubtitles();
675
+
676
+ // Display highlights on waveform
677
+ displayHighlightsOnWaveform();
678
+
679
+ // Display highlight clips
680
+ displayHighlightClips();
681
+
682
+ // Show results section
683
+ resultsSection.classList.remove('hidden');
684
+
685
+ // Reset button
686
+ processBtn.innerHTML = '<i class="fas fa-magic mr-2"></i> Generate Highlights';
687
+ processBtn.disabled = false;
688
+ isProcessing = false;
689
+ }, 3000);
690
+ }
691
+
692
+ function generateMockHighlights() {
693
+ // In a real app, this would come from your AI analysis
694
+ highlights = [];
695
+
696
+ // Generate 3-5 random highlights
697
+ const highlightCount = Math.floor(Math.random() * 3) + 3;
698
+
699
+ for (let i = 0; i < highlightCount; i++) {
700
+ const duration = Math.random() * 10 + 5; // 5-15 seconds
701
+ const maxStart = videoDuration - duration;
702
+ const start = Math.random() * maxStart;
703
+
704
+ highlights.push({
705
+ start,
706
+ end: start + duration,
707
+ confidence: Math.random() * 0.5 + 0.5, // 0.5-1.0
708
+ title: `Highlight ${i+1}`,
709
+ description: `This is an automatically generated highlight clip from the video. The AI detected this as an interesting moment.`
710
+ });
711
+ }
712
+
713
+ // Sort by start time
714
+ highlights.sort((a, b) => a.start - b.start);
715
+ }
716
+
717
+ function generateMockSubtitles() {
718
+ // In a real app, this would come from speech-to-text
719
+ subtitles = [];
720
+
721
+ // Generate subtitles for each highlight
722
+ highlights.forEach((highlight, i) => {
723
+ const textOptions = [
724
+ "This is an important moment in the video.",
725
+ "The speaker is making a key point here.",
726
+ "Watch this interesting interaction.",
727
+ "The main subject is demonstrating something valuable.",
728
+ "This clip contains the most engaging content."
729
+ ];
730
+
731
+ subtitles.push({
732
+ start: highlight.start,
733
+ end: highlight.end,
734
+ text: textOptions[i % textOptions.length]
735
+ });
736
+ });
737
+ }
738
+
739
+ function displayHighlightsOnWaveform() {
740
+ highlights.forEach(highlight => {
741
+ const clip = document.createElement('div');
742
+ clip.className = 'highlight-clip';
743
+ clip.style.left = `${(highlight.start / videoDuration) * 100}%`;
744
+ clip.style.width = `${((highlight.end - highlight.start) / videoDuration) * 100}%`;
745
+ clip.title = `Highlight: ${formatTime(highlight.start)} - ${formatTime(highlight.end)}`;
746
+ waveform.appendChild(clip);
747
+ });
748
+ }
749
+
750
+ function displayHighlightClips() {
751
+ highlightClips.innerHTML = '';
752
+ highlightResults.innerHTML = '';
753
+
754
+ const titleBase = videoType === 'youtube' ? youtubeTitle : 'Your Video';
755
+
756
+ highlights.forEach((highlight, index) => {
757
+ // Create clip card for waveform section
758
+ const clipCard = document.createElement('div');
759
+ clipCard.className = 'bg-gray-700 rounded-lg p-4 flex items-start gap-4';
760
+ clipCard.innerHTML = `
761
+ <div class="bg-purple-600/20 w-12 h-12 rounded-full flex items-center justify-center flex-shrink-0">
762
+ <span class="text-xl font-bold">${index+1}</span>
763
+ </div>
764
+ <div>
765
+ <h4 class="font-semibold mb-1">${highlight.title}</h4>
766
+ <p class="text-sm text-gray-400 mb-2">${formatTime(highlight.start)} - ${formatTime(highlight.end)}</p>
767
+ <p class="text-sm">${highlight.description}</p>
768
+ </div>
769
+ `;
770
+ highlightClips.appendChild(clipCard);
771
+
772
+ // Create result card for results section
773
+ const resultCard = document.createElement('div');
774
+ resultCard.className = 'bg-gray-800 rounded-xl overflow-hidden border border-gray-700';
775
+ resultCard.innerHTML = `
776
+ <div class="relative">
777
+ <div class="w-full bg-black aspect-video flex items-center justify-center relative">
778
+ ${videoType === 'youtube' ?
779
+ `<img src="${youtubeThumbnail}" alt="${titleBase}" class="w-full h-full object-cover">
780
+ <div class="absolute inset-0 flex items-center justify-center">
781
+ <div class="bg-black/50 rounded-full w-16 h-16 flex items-center justify-center">
782
+ <i class="fas fa-play text-white text-2xl"></i>
783
+ </div>
784
+ </div>` :
785
+ `<video class="w-full h-full" muted>
786
+ <source src="${videoBlobUrl}" type="video/mp4">
787
+ </video>`}
788
+ </div>
789
+ <div class="absolute bottom-4 left-0 right-0 px-4">
790
+ <div class="bg-black/70 text-white rounded px-3 py-2 text-center max-w-md mx-auto">
791
+ ${subtitles[index]?.text || 'Important moment'}
792
+ </div>
793
+ </div>
794
+ </div>
795
+ <div class="p-4">
796
+ <div class="flex justify-between items-start mb-2">
797
+ <h4 class="font-semibold text-lg">${titleBase}: ${highlight.title}</h4>
798
+ <button class="download-clip-btn bg-gray-700 hover:bg-gray-600 px-3 py-1 rounded text-sm flex items-center gap-1" data-index="${index}">
799
+ <i class="fas fa-download text-xs"></i> Download
800
+ </button>
801
+ </div>
802
+ <p class="text-sm text-gray-400 mb-2">${formatTime(highlight.start)} - ${formatTime(highlight.end)}</p>
803
+ <p class="text-sm">${highlight.description}</p>
804
+ </div>
805
+ `;
806
+ highlightResults.appendChild(resultCard);
807
+ });
808
+
809
+ // Add event listeners to download buttons
810
+ document.querySelectorAll('.download-clip-btn').forEach(btn => {
811
+ btn.addEventListener('click', function() {
812
+ const index = this.getAttribute('data-index');
813
+ downloadHighlight(index);
814
+ });
815
+ });
816
+ }
817
+
818
+ function formatTime(seconds) {
819
+ const mins = Math.floor(seconds / 60);
820
+ const secs = Math.floor(seconds % 60);
821
+ return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
822
+ }
823
+
824
+ function downloadHighlight(index) {
825
+ if (index < 0 || index >= highlights.length) return;
826
+
827
+ const highlight = highlights[index];
828
+
829
+ // Show different messages based on video source
830
+ if (videoType === 'youtube') {
831
+ const youtubeUrl = `https://www.youtube.com/watch?v=${youtubePlayer.getVideoData().video_id}&t=${Math.floor(highlight.start)}`;
832
+ alert(`YouTube Highlight: ${highlight.title}\nClip URL: ${youtubeUrl}\nIn a real app, this would download the YouTube clip.`);
833
+ } else {
834
+ alert(`Downloading highlight: ${highlight.title}\nThis would download the clip from ${formatTime(highlight.start)} to ${formatTime(highlight.end)}`);
835
+ }
836
+ }
837
+
838
+ function downloadHighlights() {
839
+ if (videoType === 'youtube') {
840
+ const videoId = youtubePlayer.getVideoData().video_id;
841
+ const url = `https://www.youtube.com/watch?v=${videoId}`;
842
+ alert(`Downloading all highlights from YouTube video\nIn a real app, this would package all clips from ${url}`);
843
+ } else {
844
+ alert('Downloading all highlights as a ZIP file\nIn a real app, this would package all clips together for download');
845
+ }
846
+ }
847
+ });
848
+ </script>
849
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - <a href="https://enzostvs-deepsite.hf.space?remix=beppe1234/videoaieditor" style="color: #fff;text-decoration: underline;" target="_blank" >🧬 Remix</a></p></body>
850
+ </html>