Repository navigation
Expand file tree
/
Copy pathsetup.js
More file actions
354 lines (288 loc) · 10.2 KB
/
Copy pathsetup.js
File metadata and controls
354 lines (288 loc) · 10.2 KB
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
require('dotenv').config();
const { CredentialManager } = require('./utils/credential-manager');
const { Database } = require('./database/db');
const { Logger } = require('./utils/logger');
const chalk = require('chalk');
const inquirer = require('inquirer');
const fs = require('fs').promises;
const path = require('path');
class YouTubeAutomationSetup {
constructor() {
this.logger = new Logger('Setup');
this.credentialManager = new CredentialManager();
this.database = new Database();
}
async run() {
console.log(chalk.cyan.bold('\n🎬 YouTube Automation Agent Setup'));
console.log(chalk.gray('═'.repeat(60)));
console.log(chalk.cyan('Welcome to the YouTube Automation Agent setup wizard!'));
console.log(chalk.gray('This will configure your system for fully automated YouTube content creation.\n'));
const { mode } = await inquirer.prompt([{
type: 'list',
name: 'mode',
message: 'How would you like to set up?',
choices: [
{ name: '🧭 Guided walkthrough — explains everything, tests keys as you go (recommended for first-timers)', value: 'walkthrough' },
{ name: '⚡ Classic quick setup — for users who already have all their keys', value: 'classic' }
]
}]);
if (mode === 'walkthrough') {
const { SetupWalkthrough } = require('./walkthrough');
return await new SetupWalkthrough().run();
}
try {
// Step 1: Create directories
await this.createDirectories();
// Step 2: Initialize database
await this.initializeDatabase();
// Step 3: Run credential setup
await this.credentialManager.runSetupWizard();
// Step 4: Create environment file
await this.createEnvironmentFile();
// Step 5: Install additional dependencies if needed
await this.installDependencies();
// Step 6: Create startup scripts
await this.createStartupScripts();
// Step 7: Final validation
await this.validateSetup();
console.log(chalk.green.bold('\n🎉 Setup completed successfully!'));
console.log(chalk.cyan('\n📋 Next steps:'));
console.log(chalk.white('1. Run: npm start'));
console.log(chalk.white('2. Visit: http://localhost:3456'));
console.log(chalk.white('3. Your first video will be generated and scheduled within 24 hours'));
console.log(chalk.gray('\n═'.repeat(60)));
console.log(chalk.yellow('🤖 Your YouTube channel is now fully automated!'));
} catch (error) {
console.log(chalk.red.bold('\n❌ Setup failed!'));
console.log(chalk.red(error.message));
process.exit(1);
}
}
async createDirectories() {
console.log(chalk.cyan('\n📁 Creating directory structure...'));
const directories = [
'config',
'logs',
'data',
'data/production',
'data/assets',
'data/videos',
'data/audio',
'data/scripts',
'data/captions',
'data/thumbnail-templates',
'temp/processing',
'uploads/thumbnails'
];
for (const dir of directories) {
const fullPath = path.join(__dirname, dir);
await fs.mkdir(fullPath, { recursive: true });
console.log(chalk.gray(` ✓ Created: ${dir}`));
}
console.log(chalk.green('✅ Directory structure created'));
}
async initializeDatabase() {
console.log(chalk.cyan('\n🗄️ Initializing database...'));
await this.database.initialize();
console.log(chalk.green('✅ Database initialized'));
}
async createEnvironmentFile() {
console.log(chalk.cyan('\n🔧 Creating environment configuration...'));
const envContent = `# YouTube Automation Agent Environment Configuration
# Generated on ${new Date().toISOString()}
# Application Settings
NODE_ENV=production
PORT=3456
LOG_LEVEL=info
# YouTube Settings
YOUTUBE_REGION=US
DEFAULT_PRIVACY_STATUS=private
# Content Settings
AUTO_SHORTEN_CONTENT=true
AUTO_ADD_BACKLINKS=true
PRESERVE_FORMATTING=true
AUTO_RESIZE_IMAGES=true
MAX_IMAGE_WIDTH=1280
MAX_IMAGE_HEIGHT=720
IMAGE_QUALITY=90
# Rate Limiting
GLOBAL_RATE_LIMIT_PER_HOUR=50
DEFAULT_DELAY_BETWEEN_POSTS=60000
# TTS Settings
TTS_VOICE=neural_voice_1
# Analytics & Monitoring
ENABLE_ANALYTICS=true
ANALYTICS_DB_PATH=./data/analytics.db
# File Upload Settings
MAX_FILE_SIZE=52428800
UPLOAD_PATH=./uploads
# Error Handling
RETRY_ATTEMPTS=3
RETRY_DELAY=5000
# Automation Settings
DAILY_CONTENT_ENABLED=true
AUTO_PUBLISH_ENABLED=true
OPTIMIZATION_ENABLED=true
CONTENT_BUFFER_DAYS=3
MAX_DAILY_POSTS=1
# Notification Settings
NOTIFICATION_ENABLED=true
# Debug Settings (Development only)
DEBUG_MODE=false
VERBOSE_LOGGING=false
SAVE_SCREENSHOTS=false
SCREENSHOT_PATH=./debug/screenshots
`;
await fs.writeFile(path.join(__dirname, '.env'), envContent);
console.log(chalk.green('✅ Environment file created'));
}
async installDependencies() {
console.log(chalk.cyan('\n📦 Checking dependencies...'));
try {
// Check if package.json exists and dependencies are installed
const nodeModulesPath = path.join(__dirname, 'node_modules');
try {
await fs.access(nodeModulesPath);
console.log(chalk.green('✅ Dependencies already installed'));
} catch (error) {
console.log(chalk.yellow('⚠️ Dependencies not installed. Please run: npm install'));
}
} catch (error) {
console.log(chalk.yellow('⚠️ Could not verify dependencies'));
}
}
async createStartupScripts() {
console.log(chalk.cyan('\n🚀 Creating startup scripts...'));
// Create Windows batch file
const windowsScript = `@echo off
echo Starting YouTube Automation Agent...
node index.js
pause`;
await fs.writeFile(path.join(__dirname, 'start.bat'), windowsScript);
// Create Unix shell script
const unixScript = `#!/bin/bash
echo "Starting YouTube Automation Agent..."
node index.js`;
await fs.writeFile(path.join(__dirname, 'start.sh'), unixScript);
// Create PM2 ecosystem file for production
const pm2Config = {
apps: [{
name: 'youtube-automation-agent',
script: 'index.js',
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '1G',
env: {
NODE_ENV: 'production',
PORT: 3456
}
}]
};
await fs.writeFile(
path.join(__dirname, 'ecosystem.config.js'),
`module.exports = ${JSON.stringify(pm2Config, null, 2)};`
);
console.log(chalk.green('✅ Startup scripts created'));
}
async validateSetup() {
console.log(chalk.cyan('\n🔍 Validating setup...'));
const validation = {
directories: true,
database: false,
credentials: false,
environment: false,
ffmpeg: false
};
// Check directories
try {
await fs.access(path.join(__dirname, 'data'));
await fs.access(path.join(__dirname, 'logs'));
await fs.access(path.join(__dirname, 'config'));
} catch (error) {
validation.directories = false;
}
// Check database
try {
await this.database.getStats();
validation.database = true;
} catch (error) {
validation.database = false;
}
// Check credentials
validation.credentials = await this.credentialManager.validateAll();
// Check environment
try {
await fs.access(path.join(__dirname, '.env'));
validation.environment = true;
} catch (error) {
validation.environment = false;
}
// Check FFmpeg (needed for video assembly)
const { checkFFmpeg, ffmpegInstallHint } = require('./utils/ffmpeg');
validation.ffmpeg = await checkFFmpeg();
// Display validation results
Object.entries(validation).forEach(([component, valid]) => {
const icon = valid ? '✅' : '❌';
const color = valid ? chalk.green : chalk.red;
console.log(color(` ${icon} ${component}`));
});
// Only broken infrastructure is fatal — missing credentials/FFmpeg can be fixed later
if (!validation.directories || !validation.database || !validation.environment) {
throw new Error('Setup validation failed. Please check the errors above.');
}
if (!validation.credentials) {
console.log(chalk.yellow('\n⚠️ Credentials are incomplete. Finish them any time with: npm run credentials:setup'));
}
if (!validation.ffmpeg) {
console.log(chalk.yellow(`\n⚠️ ${ffmpegInstallHint()}`));
}
if (validation.credentials && validation.ffmpeg) {
console.log(chalk.green('✅ All validations passed'));
} else {
console.log(chalk.yellow('✅ Core setup complete (with warnings above)'));
}
}
async createSampleContent() {
console.log(chalk.cyan('\n📝 Creating sample content templates...'));
// Create sample script template
const sampleScript = {
title: "Getting Started with YouTube Automation",
hook: {
type: "question",
text: "Have you ever wondered how top YouTubers manage to post consistently?"
},
introduction: {
greeting: "Hey everyone, welcome back to the channel!",
topicIntro: "Today, we're diving into YouTube automation.",
valueProposition: "By the end of this video, you'll understand how automation can transform your channel."
},
mainContent: {
sections: [
{
title: "What is YouTube Automation?",
content: "YouTube automation is the process of using technology to handle repetitive tasks in content creation and channel management."
},
{
title: "Benefits of Automation",
content: "Automation saves time, ensures consistency, and allows you to focus on strategy rather than execution."
}
]
}
};
await fs.writeFile(
path.join(__dirname, 'data', 'sample-script.json'),
JSON.stringify(sampleScript, null, 2)
);
console.log(chalk.green('✅ Sample content created'));
}
}
// Run setup if called directly
if (require.main === module) {
const setup = new YouTubeAutomationSetup();
setup.run().catch(error => {
console.error(chalk.red('Setup failed:'), error);
process.exit(1);
});
}
module.exports = { YouTubeAutomationSetup };