Spaces:
Sleeping
Sleeping
File size: 9,317 Bytes
36d488d | 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 | const { CredentialManager } = require('./utils/credential-manager');
const { Database } = require('./database/db');
const { Logger } = require('./utils/logger');
const chalk = require('chalk');
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'));
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=public
# 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
# Security
JWT_SECRET=${this.generateJWTSecret()}
# 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'));
}
generateJWTSecret() {
const crypto = require('crypto');
return crypto.randomBytes(64).toString('hex');
}
async installDependencies() {
console.log(chalk.cyan('\nπ¦ Checking dependencies...'));
try {
// Check if package.json exists and dependencies are installed
const packagePath = path.join(__dirname, 'package.json');
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
};
// 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 {
const stats = 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;
}
// Display validation results
Object.entries(validation).forEach(([component, valid]) => {
const icon = valid ? 'β
' : 'β';
const color = valid ? chalk.green : chalk.red;
console.log(color(` ${icon} ${component}`));
});
const allValid = Object.values(validation).every(Boolean);
if (!allValid) {
throw new Error('Setup validation failed. Please check the errors above.');
}
console.log(chalk.green('β
All validations passed'));
}
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 }; |