File size: 11,478 Bytes
3156d28
 
 
 
 
 
 
 
 
9912101
3156d28
 
 
45bb8f5
 
 
3156d28
 
45bb8f5
 
 
 
3156d28
 
45bb8f5
 
 
9912101
3156d28
45bb8f5
3156d28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9912101
45bb8f5
 
 
 
 
3156d28
45bb8f5
3156d28
45bb8f5
3156d28
 
 
 
 
45bb8f5
3156d28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45bb8f5
3156d28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
614d53c
 
 
3156d28
 
 
614d53c
3156d28
 
 
 
 
 
 
 
 
 
 
45bb8f5
 
614d53c
 
 
 
 
 
3156d28
45bb8f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3156d28
 
 
 
 
 
 
 
45bb8f5
 
614d53c
 
 
 
 
 
 
3156d28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
614d53c
3156d28
 
 
45bb8f5
3156d28
 
 
 
 
45bb8f5
 
 
 
 
3156d28
 
 
 
 
45bb8f5
 
 
3156d28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45bb8f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
285
286
287
288
289
290
291
292
293
294
// Main application functionality
class TranscriptionApp {
    constructor() {
        this.init();
    }
    init() {
        this.setupEventListeners();
        this.setupBackToTop();
    }

    setupEventListeners() {
        // Transcription form submission
        const form = document.getElementById('transcription-form');
        if (form) {
            form.addEventListener('submit', (e) => this.handleTranscription(e));
        }

        // Copy button
        const copyBtn = document.getElementById('copy-btn');
        if (copyBtn) {
            copyBtn.addEventListener('click', () => this.copyToClipboard());
        }

        // Download button
        const downloadBtn = document.getElementById('download-btn');
        if (downloadBtn) {
            downloadBtn.addEventListener('click', () => this.downloadTranscription());
        }
    }
setupBackToTop() {
        const backToTop = document.createElement('button');
        backToTop.className = 'back-to-top';
        backToTop.innerHTML = '<i data-feather="arrow-up"></i>';
        document.body.appendChild(backToTop);

        // Show/hide back to top button
        window.addEventListener('scroll', () => {
            if (window.pageYOffset > 300) {
                backToTop.classList.add('visible');
            } else {
                backToTop.classList.remove('visible');
            }
        });

        // Scroll to top when clicked
        backToTop.addEventListener('click', () => {
            window.scrollTo({
                top: 0,
                behavior: 'smooth'
            });
        });

        // Update icons after adding new ones
        feather.replace();
    }
    async handleTranscription(e) {
        e.preventDefault();
        
        const videoUrl = document.getElementById('video-url').value;
        const language = document.getElementById('language').value;
        const format = document.getElementById('format').value;

        // Show loading state
        this.showLoading();

        try {
            // Simulate API call (replace with actual API integration)
            const transcription = await this.simulateTranscription(videoUrl, language, format);
            
            // Display results
            this.displayResults(transcription);
            
        } catch (error) {
            this.showError('Failed to transcribe video. Please check the URL and try again.');
        }
    }
async simulateTranscription(videoUrl, language, format) {
        // Validate video URL
        if (!videoUrl || !videoUrl.includes('http')) {
            throw new Error('Please enter a valid video URL');
        }

        // Simulate API processing time
        await new Promise(resolve => setTimeout(resolve, 2000));

        // Mock transcription data based on format
        const mockTranscriptions = {
            txt: `Video Transcription Sample\n\n[00:00:00] Welcome to this demonstration of our transcription service.\n[00:00:05] This is a sample transcription showing how our AI converts video content into text.\n[00:00:15] You can use this text for subtitles, content creation, or accessibility purposes.\n[00:00:25] Thank you for using VidTranscribe Magic Wand!`,
            
            srt: `1\n00:00:00,000 --> 00:00:05,000\nWelcome to this demonstration of our transcription service.\n\n2\n00:00:05,000 --> 00:00:15,000\nThis is a sample transcription showing how our AI converts video content into text.\n\n3\n00:00:15,000 --> 00:00:25,000\nYou can use this text for subtitles, content creation, or accessibility purposes.\n\n4\n00:00:25,000 --> 00:00:30,000\nThank you for using VidTranscribe Magic Wand!`,
            
            vtt: `WEBVTT\n\n00:00:00.000 --> 00:00:05.000\nWelcome to this demonstration of our transcription service.\n\n00:00:05.000 --> 00:00:15.000\nThis is a sample transcription showing how our AI converts video content into text.\n\n00:00:15.000 --> 00:00:25.000\nYou can use this text for subtitles, content creation, or accessibility purposes.\n\n00:00:25.000 --> 00:00:30.000\nThank you for using VidTranscribe Magic Wand!`,
            
            json: JSON.stringify({
                videoUrl: videoUrl,
                language: language,
                duration: "30 seconds",
                transcription: [
                    {
                        start: "00:00:00",
                        end: "00:00:05",
                        text: "Welcome to this demonstration of our transcription service."
                    },
                    {
                        start: "00:00:05",
                        end: "00:00:15",
                        text: "This is a sample transcription showing how our AI converts video content into text."
                    },
                    {
                        start: "00:00:15",
                        end: "00:00:25",
                        text: "You can use this text for subtitles, content creation, or accessibility purposes."
                    },
                    {
                        start: "00:00:25",
                        end: "00:00:30",
                        text: "Thank you for using VidTranscribe Magic Wand!"
                    }
                ]
            }, null, 2)
        };

        return mockTranscriptions[format] || mockTranscriptions.txt;
    }
showLoading() {
        const resultsSection = document.getElementById('results');
        const outputDiv = document.getElementById('transcription-output');
        
        resultsSection.classList.remove('hidden');
        outputDiv.innerHTML = `
            <div class="flex flex-col items-center justify-center py-8">
                <div class="w-16 h-16 border-4 border-primary-500 border-t-transparent rounded-full loading-pulse mb-4"></div>
                <p class="text-gray-300">Transcribing your video...</p>
                <p class="text-sm text-gray-400 mt-2">This may take a few moments</p>
            </div>
        `;
    }
    displayResults(transcription) {
        const outputDiv = document.getElementById('transcription-output');
        const format = document.getElementById('format').value;
        
        if (format === 'json') {
            outputDiv.innerHTML = `<pre class="text-green-400 whitespace-pre-wrap">${transcription}</pre>`;
        } else {
            outputDiv.innerHTML = `<div class="text-gray-200 whitespace-pre-wrap leading-relaxed">${transcription}</div>`;
        }

        // Store transcription in global variable for access
        window.currentTranscription = transcription;

        // Scroll to results
        document.getElementById('results').scrollIntoView({ behavior: 'smooth' });
    }
showError(message) {
        const outputDiv = document.getElementById('transcription-output');
        outputDiv.innerHTML = `
            <div class="text-center py-8">
                <i data-feather="alert-circle" class="w-12 h-12 text-red-500 mx-auto mb-4"></i>
                <p class="text-red-400 text-lg">${message}</p>
            </div>
        `;
        feather.replace();
    }
    copyToClipboard() {
        const outputDiv = document.getElementById('transcription-output');
        if (!outputDiv) return;
        
        let text;
        if (outputDiv.querySelector('pre')) {
            text = outputDiv.querySelector('pre').textContent;
        } else {
            text = outputDiv.textContent || outputDiv.innerText;
        }
        
        // Fallback for older browsers
        if (!navigator.clipboard) {
            const textArea = document.createElement('textarea');
            textArea.value = text;
            document.body.appendChild(textArea);
            textArea.select();
            try {
                document.execCommand('copy');
                this.showToast('Transcription copied to clipboard!', 'success');
            } catch (err) {
                this.showToast('Failed to copy transcription', 'error');
            }
            document.body.removeChild(textArea);
            return;
        }

        navigator.clipboard.writeText(text).then(() => {
            this.showToast('Transcription copied to clipboard!', 'success');
        }).catch(() => {
            this.showToast('Failed to copy transcription', 'error');
        });
    }
    downloadTranscription() {
        const outputDiv = document.getElementById('transcription-output');
        if (!outputDiv) return;
        
        let text;
        if (outputDiv.querySelector('pre')) {
            text = outputDiv.querySelector('pre').textContent;
        } else {
            text = outputDiv.textContent || outputDiv.innerText;
        }
        
        const format = document.getElementById('format').value;
        const filename = `transcription.${format}`;
        
        const blob = new Blob([text], { type: 'text/plain' });
        const url = URL.createObjectURL(blob);
        const a = document.createElement('a');
        a.href = url;
        a.download = filename;
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
        URL.revokeObjectURL(url);
        
        this.showToast('Transcription downloaded!', 'success');
    }
showToast(message, type = 'info') {
        const toast = document.createElement('div');
        const bgColor = type === 'success' ? 'bg-primary-500' : 'bg-red-500';
        
        toast.className = `fixed top-4 right-4 ${bgColor} text-white px-6 py-3 rounded-lg shadow-lg transform transition-all duration-300 translate-x-full z-50`;
        toast.textContent = message;
        
        document.body.appendChild(toast);
        
        // Animate in
        requestAnimationFrame(() => {
            requestAnimationFrame(() => {
                toast.classList.remove('translate-x-full');
            });
        });
        
        // Remove after 3 seconds
        setTimeout(() => {
            toast.classList.add('translate-x-full');
            setTimeout(() => {
                if (document.body.contains(toast)) {
                    document.body.removeChild(toast);
                }
            }, 300);
        }, 3000);
    }
}
// Initialize the app when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
    new TranscriptionApp();
});

// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
    anchor.addEventListener('click', function (e) {
        e.preventDefault();
        const target = document.querySelector(this.getAttribute('href'));
        if (target) {
            target.scrollIntoView({
                behavior: 'smooth',
                block: 'start'
            });
        }
    });
});

// Handle feather icons in dynamically added content
document.addEventListener('DOMContentLoaded', function() {
    // Replace icons initially
    if (typeof feather !== 'undefined') {
        feather.replace();
    }
    
    // Watch for DOM changes to replace icons in new content
    const observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            if (mutation.addedNodes.length > 0) {
                setTimeout(() => {
                    if (typeof feather !== 'undefined') {
                        feather.replace();
                    }
                }, 100);
            }
        });
    });
    
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
});