File size: 6,846 Bytes
8c1cb49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0f97fb6
8c1cb49
 
0f97fb6
8c1cb49
 
0f97fb6
8c1cb49
 
 
 
0f97fb6
 
 
 
 
8c1cb49
0f97fb6
8c1cb49
 
 
 
 
 
 
 
 
 
 
 
0f97fb6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c1cb49
 
0f97fb6
 
8c1cb49
 
 
 
 
0f97fb6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c1cb49
0f97fb6
8c1cb49
0f97fb6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c1cb49
0f97fb6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
document.addEventListener('DOMContentLoaded', function() {
    // Smooth scrolling for anchor links
    document.querySelectorAll('a[href^="#"]').forEach(anchor => {
        anchor.addEventListener('click', function (e) {
            e.preventDefault();
            document.querySelector(this.getAttribute('href')).scrollIntoView({
                behavior: 'smooth'
            });
        });
    });

    // Video generation form handling
    const generateBtn = document.querySelector('#generate-btn');
    if (generateBtn) {
        generateBtn.addEventListener('click', function() {
            // Simulate video generation
            this.innerHTML = '<span class="flex items-center"><i data-feather="loader" class="animate-spin mr-2"></i> Generating...</span>';
            feather.replace();
            
            setTimeout(() => {
                this.innerHTML = '<span class="flex items-center"><i data-feather="check" class="mr-2"></i> Video Ready!</span>';
                feather.replace();
                
                // Show success modal
                alert('Your 30-minute documentary video has been generated successfully! Click OK to download.');
                
                // Reset button after delay
                setTimeout(() => {
                    this.innerHTML = '<span class="flex items-center"><i data-feather="film" class="mr-2"></i> Generate Video</span>';
                    feather.replace();
                }, 3000);
            }, 5000);
        });
    }
    // Dynamic year for footer
    const yearSpan = document.querySelector('#current-year');
    if (yearSpan) {
        yearSpan.textContent = new Date().getFullYear();
    }
    // Fast download functionality with auto-save
    const downloadButtons = document.querySelectorAll('.fast-download');
    downloadButtons.forEach(button => {
        button.addEventListener('click', async function(e) {
            e.preventDefault();
            const progressBar = this.closest('.download-container').querySelector('.download-progress-fill');
            const downloadTime = 2000; // Fixed time for better UX
            
            // Simulate fast download
            this.disabled = true;
            progressBar.style.width = '0%';
            this.innerHTML = '<i data-feather="loader" class="animate-spin mr-2"></i> Preparing Download...';
            feather.replace();
            
            // Generate a realistic video file blob (simulated)
            await new Promise(resolve => setTimeout(resolve, 1000));
            
            // Update progress
            let progress = 0;
            const interval = setInterval(() => {
                progress += 5;
                progressBar.style.width = `${progress}%`;
                
                if (progress >= 100) {
                    clearInterval(interval);
                    this.disabled = false;
                    this.classList.add('download-pulse');
                    this.innerHTML = '<i data-feather="download" class="mr-2"></i> Download Complete!';
                    feather.replace();
                    
                    // Create and trigger download
                    const videoTitle = document.querySelector('input[type="text"]')?.value || 'documentary-video';
                    const sanitizedTitle = videoTitle.replace(/[^a-z0-9]/gi, '_').toLowerCase();
                    const fileName = `${sanitizedTitle}_${new Date().getTime()}.mp4`;
                    
                    // Create a realistic video file (simulated)
                    const videoBlob = new Blob(['Simulated video content'], { type: 'video/mp4' });
                    const videoUrl = URL.createObjectURL(videoBlob);
                    
                    const link = document.createElement('a');
                    link.href = videoUrl;
                    link.download = fileName;
                    document.body.appendChild(link);
                    link.click();
                    
                    // Clean up
                    setTimeout(() => {
                        document.body.removeChild(link);
                        URL.revokeObjectURL(videoUrl);
                    }, 100);
                }
            }, downloadTime / 20);
        });
    });
});
// Video generation with auto-download
async function generateAndDownloadVideo(scriptContent, options = {}) {
    try {
        // Show generating state
        const generateBtn = document.querySelector('.fast-download');
        if (generateBtn) {
            generateBtn.innerHTML = '<i data-feather="loader" class="animate-spin mr-2"></i> Generating Video...';
            feather.replace();
            generateBtn.disabled = true;
        }

        // Simulate video generation (2-5 seconds)
        const generationTime = Math.random() * 3000 + 2000;
        await new Promise(resolve => setTimeout(resolve, generationTime));

        // Create video file
        const videoTitle = options.title || 'documentary-video';
        const sanitizedTitle = videoTitle.replace(/[^a-z0-9]/gi, '_').toLowerCase();
        const fileName = `${sanitizedTitle}_${new Date().getTime()}.mp4`;
        
        // Create a realistic video file (simulated)
        const videoBlob = new Blob(['Simulated video content'], { type: 'video/mp4' });
        const videoUrl = URL.createObjectURL(videoBlob);

        // Trigger download
        const link = document.createElement('a');
        link.href = videoUrl;
        link.download = fileName;
        document.body.appendChild(link);
        link.click();

        // Clean up
        setTimeout(() => {
            document.body.removeChild(link);
            URL.revokeObjectURL(videoUrl);
        }, 100);

        return {
            success: true,
            fileName,
            size: '150MB',
            format: 'MP4 (H.265)',
            duration: '30:00'
        };
    } catch (error) {
        console.error('Video generation failed:', error);
        return {
            success: false,
            error: error.message
        };
    } finally {
        if (generateBtn) {
            generateBtn.innerHTML = '<i data-feather="film" class="mr-2"></i> Generate & Download Fast';
            feather.replace();
            generateBtn.disabled = false;
        }
    }
}

// Connect form to auto-download
document.querySelectorAll('form').forEach(form => {
    form.addEventListener('submit', async (e) => {
        e.preventDefault();
        const scriptContent = form.querySelector('textarea').value;
        const videoTitle = form.querySelector('input[type="text"]').value;
        const videoStyle = form.querySelector('select').value;
        
        await generateAndDownloadVideo(scriptContent, {
            title: videoTitle,
            style: videoStyle
        });
    });
});