Skip to content

🎬 Open-source, self-hosted AI agent that runs a YouTube channel end to end: researches topics, writes scripts, generates narration, visuals and video, optimizes SEO, and publishes after your approval, then learns from analytics. Works with Gemini, OpenAI, OpenRouter, DeepSeek and more.

v2.4: Guided setup walkthrough for first-timers; actually load .env

darkzOGxf5b349664099
diff --git a/.env.example b/.env.example
index 69103e4..e1b3c53 100644
--- a/.env.example
+++ b/.env.example
@@ -2,7 +2,8 @@
# Copy this file to .env and fill in your actual values
# AI Provider - Pick one (or use OpenRouter for access to all)
-OPENAI_API_KEY=your-openai-api-key-here
+# Uncomment the line you use β€” placeholder values must stay commented out
+# OPENAI_API_KEY=your-openai-api-key-here
# OPENROUTER_API_KEY=your-openrouter-api-key-here
# GEMINI_API_KEY=your-gemini-api-key-here
# MOONSHOT_API_KEY=your-kimi-api-key-here
diff --git a/README.md b/README.md
index 077a687..313a9d9 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,12 @@
# YouTube Automation Agent
+## What's New in v2.4
+
+- **Guided walkthrough for first-time setup** β€” `npm run walkthrough` (also offered when you run `npm run setup`). It explains every choice in plain English, shows exactly where to get each key (and opens the page in your browser), **live-tests keys the moment you paste them**, walks you click-by-click through Google Cloud for the YouTube connection, and signs you in via your browser instead of copy-pasting auth codes. Every step is skippable and progress is saved β€” re-run it any time.
+- **`.env` files actually work now** β€” `dotenv` was a dependency but was never loaded, so `.env` settings (API keys, `API_KEY`, `FFMPEG_PATH`…) were silently ignored unless exported in your shell. `index.js` and the setup tools now load `.env` on start.
+- **`.env.example` no longer poisons setup** β€” the uncommented `OPENAI_API_KEY=your-openai-api-key-here` placeholder would have been picked up as a real key; all placeholders are now commented out.
+- **Browser OAuth opens automatically** β€” the YouTube authorization URL now opens in your default browser.
+
## What's New in v2.3
- **Full free-tier pipeline with Gemini** β€” image generation (`gemini-3.1-flash-image`) and native voice narration (`gemini-3.1-flash-tts-preview`) now run on your Gemini key. A Gemini-only setup produces complete narrated videos end to end; OpenAI/ElevenLabs are used first when configured. Models and voice are configurable via `GEMINI_IMAGE_MODEL`, `GEMINI_TTS_MODEL`, `GEMINI_TTS_VOICE`. (Thanks to PR #6 for demonstrating the demand and fallback-chain direction.)
@@ -114,14 +121,14 @@ Additional integrations: Anthropic Claude (`claude-opus-4-8`), ElevenLabs (Eleve
git clone https://github.com/darkzOGx/youtube-automation-agent.git
cd youtube-automation-agent
npm install
-cp .env.example .env
-cp config/credentials.example.json config/credentials.json
-npm run setup # interactive credential wizard
+npm run walkthrough # guided first-time setup: explains everything, tests your keys live
npm start
```
Dashboard runs at `http://localhost:3456`.
+Already know what you're doing? `npm run setup` offers a classic quick mode, and `.env.example` documents every setting.
+
### Prerequisites
- Node.js 18+
diff --git a/index.js b/index.js
index b407171..ca0d3cb 100644
--- a/index.js
+++ b/index.js
@@ -1,3 +1,5 @@
+require('dotenv').config();
+
const express = require('express');
const path = require('path');
const { Logger } = require('./utils/logger');
diff --git a/modern-auth.js b/modern-auth.js
index 23d8b5f..583a961 100644
--- a/modern-auth.js
+++ b/modern-auth.js
@@ -48,6 +48,17 @@ class ModernAuth {
console.log(chalk.cyan('πŸ”— Please visit this URL to authorize:'));
console.log(chalk.blue(authUrl));
+
+ // Best effort: open the URL in the default browser
+ const { exec } = require('child_process');
+ const openCommands = {
+ win32: `start "" "${authUrl}"`,
+ darwin: `open "${authUrl}"`,
+ linux: `xdg-open "${authUrl}"`
+ };
+ if (openCommands[process.platform]) {
+ exec(openCommands[process.platform], () => {});
+ }
console.log(chalk.yellow(`\n⚑ A temporary server is running on port ${port}`));
console.log(chalk.yellow('After authorization, you\'ll be redirected automatically.'));
console.log(chalk.gray('Waiting for authorization...'));
diff --git a/package.json b/package.json
index d8d4e7b..e63517c 100644
--- a/package.json
+++ b/package.json
@@ -1,11 +1,12 @@
{
"name": "youtube-automation-agent",
- "version": "2.3.0",
+ "version": "2.4.0",
"description": "Fully automated YouTube channel management system with specialized AI agents",
"main": "index.js",
"scripts": {
"start": "node index.js",
"setup": "node setup.js",
+ "walkthrough": "node walkthrough.js",
"scheduler": "node schedules/daily-automation.js",
"test": "node test.js",
"agent:strategy": "node agents/content-strategy-agent.js",
diff --git a/setup.js b/setup.js
index 2d43ed1..7fed741 100644
--- a/setup.js
+++ b/setup.js
@@ -1,7 +1,10 @@
+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');
@@ -18,6 +21,21 @@ class YouTubeAutomationSetup {
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();
diff --git a/test.js b/test.js
index 69d09b6..aeb1da0 100644
--- a/test.js
+++ b/test.js
@@ -26,6 +26,7 @@ class SystemTest {
{ name: 'Gemini Media Provider Selection', test: () => this.testGeminiMediaProvider() },
{ name: 'Slideshow Renderer', test: () => this.testSlideshowRenderer() },
{ name: 'Evergreen Template Topics', test: () => this.testEvergreenTopics() },
+ { name: 'Walkthrough Module', test: () => this.testWalkthroughModule() },
{ name: 'Logger System', test: () => this.testLogger() },
{ name: 'Directory Structure', test: () => this.testDirectories() },
{ name: 'Agent Loading', test: () => this.testAgentLoading() },
@@ -466,6 +467,56 @@ class SystemTest {
this.logger.info('Evergreen template topics test completed successfully');
}
+ async testWalkthroughModule() {
+ const { SetupWalkthrough, AI_PROVIDER_GUIDE } = require('./walkthrough');
+ const { PROVIDERS } = require('./utils/ai-text-service');
+
+ const walkthrough = new SetupWalkthrough();
+ if (typeof walkthrough.run !== 'function') {
+ throw new Error('SetupWalkthrough.run is not implemented');
+ }
+
+ // Every guided provider must be complete and coherent
+ for (const [id, guide] of Object.entries(AI_PROVIDER_GUIDE)) {
+ for (const field of ['label', 'keyUrl', 'instructions', 'models', 'defaultModel', 'save', 'validationCreds']) {
+ if (!guide[field]) {
+ throw new Error(`Provider guide "${id}" is missing "${field}"`);
+ }
+ }
+ if (!guide.models.includes(guide.defaultModel)) {
+ throw new Error(`Provider guide "${id}" default model is not in its model list`);
+ }
+
+ // save() must produce credentials that pass validation
+ const credentials = {};
+ guide.save(credentials, 'test-key', guide.defaultModel);
+ const manager = new CredentialManager();
+ manager.credentials = { youtube: { client_id: 'x' }, ...credentials };
+
+ const envKeys = [...Object.values(PROVIDERS).map(p => p.envKey), 'GEMINI_API_KEY'];
+ const savedEnv = {};
+ for (const key of envKeys) {
+ savedEnv[key] = process.env[key];
+ delete process.env[key];
+ }
+ try {
+ if (manager.getMissingCredentials().length !== 0) {
+ throw new Error(`Provider guide "${id}" save() output fails credential validation`);
+ }
+ } finally {
+ for (const key of envKeys) {
+ if (savedEnv[key] === undefined) {
+ delete process.env[key];
+ } else {
+ process.env[key] = savedEnv[key];
+ }
+ }
+ }
+ }
+
+ this.logger.info('Walkthrough module test completed successfully');
+ }
+
async testLogger() {
const testLogger = new Logger('TestLogger');
diff --git a/walkthrough.js b/walkthrough.js
new file mode 100644
index 0000000..08d9fdb
--- /dev/null
+++ b/walkthrough.js
@@ -0,0 +1,490 @@
+require('dotenv').config();
+
+const inquirer = require('inquirer');
+const chalk = require('chalk');
+const fs = require('fs').promises;
+const path = require('path');
+const { exec } = require('child_process');
+const { CredentialManager } = require('./utils/credential-manager');
+const { AITextService, PROVIDERS } = require('./utils/ai-text-service');
+const { Database } = require('./database/db');
+const { checkFFmpeg, ffmpegInstallHint } = require('./utils/ffmpeg');
+
+// Everything a beginner needs to know about each provider, in one place
+const AI_PROVIDER_GUIDE = {
+ gemini: {
+ label: 'Google Gemini β€” FREE tier, no credit card (recommended for beginners)',
+ keyUrl: 'https://aistudio.google.com/apikey',
+ keyHint: 'starts with "AIza"',
+ instructions: [
+ 'Sign in with any Google account',
+ 'Click "Create API key"',
+ 'Copy the key it shows you'
+ ],
+ models: ['gemini-3.5-flash', 'gemini-3.1-pro-preview', 'gemini-2.5-pro'],
+ defaultModel: 'gemini-3.5-flash',
+ covers: 'scripts + images + voice narration (full free pipeline)',
+ save(credentials, apiKey, model) {
+ credentials.gemini = { apiKey, model };
+ },
+ validationCreds: (apiKey, model) => ({ gemini: { apiKey, model } })
+ },
+ openai: {
+ label: 'OpenAI β€” paid (~$0.05–0.20/video), premium image + voice quality',
+ keyUrl: 'https://platform.openai.com/api-keys',
+ keyHint: 'starts with "sk-"',
+ instructions: [
+ 'Sign in (or create an account) and add billing',
+ 'Click "Create new secret key"',
+ 'Copy the key β€” it is shown only once'
+ ],
+ models: ['gpt-5.5', 'gpt-5.5-pro', 'gpt-5.4'],
+ defaultModel: 'gpt-5.5',
+ covers: 'scripts + images + voice narration',
+ save(credentials, apiKey, model) {
+ credentials.openai = { apiKey, model };
+ },
+ validationCreds: (apiKey, model) => ({ aiProvider: { provider: 'openai', apiKey, model } })
+ },
+ openrouter: {
+ label: 'OpenRouter β€” one key, 300+ models (pay per use)',
+ keyUrl: 'https://openrouter.ai/keys',
+ keyHint: 'starts with "sk-or-"',
+ instructions: [
+ 'Sign in and add a few dollars of credit',
+ 'Create a key and copy it'
+ ],
+ models: ['openai/gpt-5.5', 'anthropic/claude-opus-4-8', 'google/gemini-3.5-flash', 'moonshotai/kimi-k2.6', 'zhipu/glm-5'],
+ defaultModel: 'google/gemini-3.5-flash',
+ covers: 'scripts only (add a Gemini or OpenAI key for images/voice)',
+ save(credentials, apiKey, model) {
+ credentials.aiProvider = { provider: 'openrouter', apiKey, model };
+ },
+ validationCreds: (apiKey, model) => ({ aiProvider: { provider: 'openrouter', apiKey, model } })
+ },
+ kimi: {
+ label: 'Kimi (Moonshot AI) β€” very cheap, strong quality',
+ keyUrl: 'https://platform.kimi.ai',
+ keyHint: 'from the Moonshot platform console',
+ instructions: ['Create an account', 'Open the API keys page and create a key'],
+ models: ['kimi-k2.6', 'kimi-k2.5', 'moonshot-v1-auto'],
+ defaultModel: 'kimi-k2.6',
+ covers: 'scripts only (add a Gemini or OpenAI key for images/voice)',
+ save(credentials, apiKey, model) {
+ credentials.aiProvider = { provider: 'kimi', apiKey, model };
+ },
+ validationCreds: (apiKey, model) => ({ aiProvider: { provider: 'kimi', apiKey, model } })
+ },
+ mimo: {
+ label: 'MiMo (Xiaomi) β€” competitive pricing',
+ keyUrl: 'https://mimo.mi.com',
+ keyHint: 'from the MiMo console',
+ instructions: ['Create an account', 'Create an API key in the console'],
+ models: ['mimo-v2.5-pro', 'mimo-v2.5'],
+ defaultModel: 'mimo-v2.5-pro',
+ covers: 'scripts only (add a Gemini or OpenAI key for images/voice)',
+ save(credentials, apiKey, model) {
+ credentials.aiProvider = { provider: 'mimo', apiKey, model };
+ },
+ validationCreds: (apiKey, model) => ({ aiProvider: { provider: 'mimo', apiKey, model } })
+ },
+ glm: {
+ label: 'GLM (Zhipu AI) β€” ~$1/M input tokens',
+ keyUrl: 'https://z.ai',
+ keyHint: 'from the Z.ai console',
+ instructions: ['Create an account', 'Create an API key in the console'],
+ models: ['glm-5', 'glm-5.1'],
+ defaultModel: 'glm-5',
+ covers: 'scripts only (add a Gemini or OpenAI key for images/voice)',
+ save(credentials, apiKey, model) {
+ credentials.aiProvider = { provider: 'glm', apiKey, model };
+ },
+ validationCreds: (apiKey, model) => ({ aiProvider: { provider: 'glm', apiKey, model } })
+ }
+};
+
+class SetupWalkthrough {
+ constructor() {
+ this.cm = new CredentialManager();
+ this.totalSteps = 5;
+ }
+
+ header(step, title) {
+ console.log(chalk.cyan.bold(`\n━━━ Step ${step} of ${this.totalSteps}: ${title} `.padEnd(62, '━')));
+ }
+
+ openBrowser(url) {
+ const commands = {
+ win32: `start "" "${url}"`,
+ darwin: `open "${url}"`,
+ linux: `xdg-open "${url}"`
+ };
+ const command = commands[process.platform];
+ if (command) {
+ exec(command, () => {}); // best effort β€” the URL is printed either way
+ }
+ }
+
+ async run() {
+ console.log(chalk.cyan.bold('\n🧭 YouTube Automation Agent β€” Guided Walkthrough'));
+ console.log(chalk.gray('═'.repeat(60)));
+ console.log(chalk.white('This takes about 10–15 minutes and explains everything as you go.'));
+ console.log(chalk.white('Every step can be skipped and finished later β€” your progress is'));
+ console.log(chalk.white('saved after each step. Re-run any time with: ') + chalk.cyan('npm run walkthrough'));
+
+ await this.cm.loadCredentials();
+ await this.cm.loadTokens();
+
+ try {
+ await this.stepSystemCheck();
+ await this.stepAIProvider();
+ await this.stepYouTube();
+ await this.stepChannelBasics();
+ await this.stepFinish();
+ } catch (error) {
+ if (error && (error.isTtyError || /User force closed/i.test(error.message || ''))) {
+ console.log(chalk.yellow('\n\nπŸ‘‹ No problem β€” everything you completed is saved.'));
+ console.log(chalk.cyan('Pick up where you left off with: npm run walkthrough'));
+ return;
+ }
+ throw error;
+ }
+ }
+
+ // ── Step 1: environment ────────────────────────────────────────────────
+ async stepSystemCheck() {
+ this.header(1, 'Checking your system');
+
+ const nodeMajor = parseInt(process.versions.node.split('.')[0], 10);
+ console.log(nodeMajor >= 18
+ ? chalk.green(` βœ“ Node.js ${process.versions.node}`)
+ : chalk.red(` βœ— Node.js ${process.versions.node} β€” version 18+ is required (https://nodejs.org)`));
+
+ const ffmpegOk = await checkFFmpeg();
+ console.log(ffmpegOk
+ ? chalk.green(' βœ“ FFmpeg (video assembly)')
+ : chalk.yellow(` βœ— FFmpeg β€” ${ffmpegInstallHint()}`));
+
+ const directories = [
+ 'config', 'logs', 'data', 'data/production', 'data/assets', 'data/videos',
+ 'data/audio', 'data/scripts', 'data/captions', 'temp/processing', 'uploads/thumbnails'
+ ];
+ for (const dir of directories) {
+ await fs.mkdir(path.join(__dirname, dir), { recursive: true });
+ }
+ console.log(chalk.green(' βœ“ Project folders'));
+
+ const db = new Database();
+ await db.initialize();
+ await db.close();
+ console.log(chalk.green(' βœ“ Database'));
+
+ // Create .env from a minimal template if the user doesn't have one yet
+ try {
+ await fs.access(path.join(__dirname, '.env'));
+ console.log(chalk.green(' βœ“ .env file'));
+ } catch (error) {
+ await fs.writeFile(path.join(__dirname, '.env'), [
+ '# Created by the guided walkthrough β€” see .env.example for every option',
+ 'NODE_ENV=production',
+ 'PORT=3456',
+ 'LOG_LEVEL=info',
+ 'DEFAULT_PRIVACY_STATUS=private',
+ ''
+ ].join('\n'));
+ console.log(chalk.green(' βœ“ .env file created'));
+ }
+ }
+
+ // ── Step 2: AI provider ────────────────────────────────────────────────
+ async stepAIProvider() {
+ this.header(2, 'Your AI provider (writes scripts, makes images & narration)');
+
+ if (this.cm.hasAITextProvider()) {
+ const { redo } = await inquirer.prompt([{
+ type: 'confirm',
+ name: 'redo',
+ message: 'An AI provider is already configured. Set up a different one?',
+ default: false
+ }]);
+ if (!redo) return;
+ } else {
+ console.log(chalk.white('The agent needs one AI service. If you don\'t want to spend money,'));
+ console.log(chalk.white('pick Google Gemini β€” its free tier covers the whole pipeline:'));
+ console.log(chalk.white('scripts, images, and voice narration.'));
+ }
+
+ const { providerId } = await inquirer.prompt([{
+ type: 'list',
+ name: 'providerId',
+ message: 'Which AI provider do you want to use?',
+ choices: Object.entries(AI_PROVIDER_GUIDE).map(([value, guide]) => ({ name: guide.label, value }))
+ }]);
+
+ const guide = AI_PROVIDER_GUIDE[providerId];
+
+ console.log(chalk.cyan(`\nHow to get your key (${guide.keyHint}):`));
+ guide.instructions.forEach((line, i) => console.log(chalk.white(` ${i + 1}. ${line}`)));
+ console.log(chalk.white(` β†’ ${chalk.blue(guide.keyUrl)} (opening in your browser)`));
+ console.log(chalk.gray(` This key covers: ${guide.covers}`));
+ this.openBrowser(guide.keyUrl);
+
+ while (true) {
+ const { apiKey } = await inquirer.prompt([{
+ type: 'password',
+ name: 'apiKey',
+ mask: '*',
+ message: `Paste your ${providerId} API key (or leave empty to skip this step):`
+ }]);
+
+ if (!apiKey.trim()) {
+ console.log(chalk.yellow(' Skipped β€” configure later with: npm run walkthrough'));
+ return;
+ }
+
+ const { model } = await inquirer.prompt([{
+ type: 'list',
+ name: 'model',
+ message: 'Model to use:',
+ choices: guide.models,
+ default: guide.defaultModel
+ }]);
+
+ console.log(chalk.gray(' Testing your key with a tiny request...'));
+ const ok = await this.validateAIKey(guide, apiKey.trim(), model);
+
+ if (ok) {
+ guide.save(this.cm.credentials, apiKey.trim(), model);
+ await this.cm.saveCredentials();
+ console.log(chalk.green(' βœ“ Key works! Saved.'));
+ return;
+ }
+
+ const { retry } = await inquirer.prompt([{
+ type: 'confirm',
+ name: 'retry',
+ message: 'That key didn\'t work. Try pasting it again?',
+ default: true
+ }]);
+ if (!retry) {
+ console.log(chalk.yellow(' Skipped β€” configure later with: npm run walkthrough'));
+ return;
+ }
+ }
+ }
+
+ async validateAIKey(guide, apiKey, model) {
+ // Temporarily clear provider env keys so the test hits exactly the pasted key
+ const envKeys = [...Object.values(PROVIDERS).map(p => p.envKey), 'GEMINI_API_KEY'];
+ const savedEnv = {};
+ for (const key of envKeys) {
+ savedEnv[key] = process.env[key];
+ delete process.env[key];
+ }
+
+ try {
+ const service = new AITextService(guide.validationCreds(apiKey, model));
+ const reply = await service.generateText('Reply with the single word OK.', { maxTokens: 20, temperature: 0 });
+ return typeof reply === 'string' && reply.length > 0;
+ } catch (error) {
+ console.log(chalk.red(` βœ— ${error.message}`));
+ return false;
+ } finally {
+ for (const key of envKeys) {
+ if (savedEnv[key] === undefined) {
+ delete process.env[key];
+ } else {
+ process.env[key] = savedEnv[key];
+ }
+ }
+ }
+ }
+
+ // ── Step 3: YouTube ────────────────────────────────────────────────────
+ async stepYouTube() {
+ this.header(3, 'Connecting your YouTube channel');
+
+ if (this.cm.credentials.youtube && this.cm.tokens.youtube) {
+ const { redo } = await inquirer.prompt([{
+ type: 'confirm',
+ name: 'redo',
+ message: 'YouTube is already connected. Reconnect?',
+ default: false
+ }]);
+ if (!redo) return;
+ } else {
+ console.log(chalk.white('This lets the agent upload to your channel. It\'s the fiddliest step,'));
+ console.log(chalk.white('but it\'s free and you only do it once. You can also skip it β€” videos'));
+ console.log(chalk.white('will still be generated locally in data/videos/.'));
+ }
+
+ const { action } = await inquirer.prompt([{
+ type: 'list',
+ name: 'action',
+ message: 'How do you want to proceed?',
+ choices: [
+ { name: '🧭 Walk me through creating the Google credentials (~5 min)', value: 'guided' },
+ { name: '⚑ I already have a Client ID and Client Secret', value: 'have' },
+ { name: '⏭️ Skip for now', value: 'skip' }
+ ]
+ }]);
+
+ if (action === 'skip') {
+ console.log(chalk.yellow(' Skipped β€” connect later with: npm run walkthrough'));
+ return;
+ }
+
+ if (action === 'guided') {
+ console.log(chalk.cyan('\nDo this in the browser tab that just opened:'));
+ console.log(chalk.white(' 1. Create a project (any name) β€” top bar β†’ "New project"'));
+ console.log(chalk.white(' 2. Menu β†’ "APIs & Services" β†’ "Library" β†’ search "YouTube Data API v3" β†’ Enable'));
+ console.log(chalk.white(' 3. "APIs & Services" β†’ "OAuth consent screen" β†’ External β†’ fill the 3 required'));
+ console.log(chalk.white(' fields β†’ add YOUR OWN email under "Test users"'));
+ console.log(chalk.white(' 4. "APIs & Services" β†’ "Credentials" β†’ "Create credentials" β†’ "OAuth client ID"'));
+ console.log(chalk.white(' β†’ Application type: "Desktop app"'));
+ console.log(chalk.white(' 5. Copy the Client ID and Client Secret it shows you'));
+ console.log(chalk.white(` β†’ ${chalk.blue('https://console.cloud.google.com/')}`));
+ this.openBrowser('https://console.cloud.google.com/');
+ }
+
+ const answers = await inquirer.prompt([
+ {
+ type: 'input',
+ name: 'clientId',
+ message: 'Paste your Client ID (ends in .apps.googleusercontent.com, empty to skip):'
+ },
+ {
+ type: 'password',
+ name: 'clientSecret',
+ mask: '*',
+ message: 'Paste your Client Secret:',
+ when: (a) => a.clientId.trim().length > 0
+ }
+ ]);
+
+ if (!answers.clientId.trim()) {
+ console.log(chalk.yellow(' Skipped β€” connect later with: npm run walkthrough'));
+ return;
+ }
+
+ this.cm.credentials.youtube = {
+ client_id: answers.clientId.trim(),
+ client_secret: (answers.clientSecret || '').trim(),
+ redirect_uris: ['http://localhost:8080/oauth2callback']
+ };
+ await this.cm.saveCredentials();
+
+ console.log(chalk.cyan('\nNow let\'s sign in. A Google page will open β€” approve the access.'));
+ console.log(chalk.gray('(You may see "Google hasn\'t verified this app" β€” click "Continue".'));
+ console.log(chalk.gray(' That\'s expected: the "app" is your own Cloud project.)'));
+
+ try {
+ const { ModernAuth } = require('./modern-auth');
+ const auth = new ModernAuth();
+ await auth.authenticate();
+ await this.cm.loadTokens();
+ console.log(chalk.gray(' Checking which channel this is...'));
+ await auth.testAuthentication();
+ } catch (error) {
+ console.log(chalk.red(` βœ— Sign-in failed: ${error.message}`));
+ console.log(chalk.yellow(' Your Client ID/Secret are saved β€” retry with: npm run walkthrough'));
+ }
+ }
+
+ // ── Step 4: channel basics ─────────────────────────────────────────────
+ async stepChannelBasics() {
+ this.header(4, 'Channel & content basics');
+
+ const existing = this.cm.credentials.channel || {};
+ const answers = await inquirer.prompt([
+ {
+ type: 'input',
+ name: 'channelName',
+ message: 'What\'s your channel called?',
+ default: existing.channelName || 'My Automated Channel'
+ },
+ {
+ type: 'list',
+ name: 'postingFrequency',
+ message: 'How often should it post?',
+ choices: [
+ { name: 'Daily', value: 'daily' },
+ { name: 'Every other day', value: 'every-2-days' },
+ { name: '3 times per week', value: '3-per-week' },
+ { name: 'Weekly', value: 'weekly' }
+ ],
+ default: this.cm.credentials.content?.postingFrequency || 'daily'
+ },
+ {
+ type: 'input',
+ name: 'targetAudience',
+ message: 'Describe your target audience in one line:',
+ default: this.cm.credentials.content?.targetAudience || 'General audience interested in educational content'
+ }
+ ]);
+
+ this.cm.credentials.channel = {
+ ...existing,
+ channelName: answers.channelName,
+ channelDescription: existing.channelDescription || 'Automated content channel',
+ defaultCategory: existing.defaultCategory || '22',
+ defaultPrivacy: existing.defaultPrivacy || 'private'
+ };
+ this.cm.credentials.content = {
+ contentTypes: this.cm.credentials.content?.contentTypes || ['tutorial', 'explainer', 'list'],
+ competitorChannels: this.cm.credentials.content?.competitorChannels || [],
+ targetAudience: answers.targetAudience,
+ postingFrequency: answers.postingFrequency,
+ preferredPostTime: this.cm.credentials.content?.preferredPostTime || '14:00'
+ };
+ await this.cm.saveCredentials();
+
+ console.log(chalk.green(' βœ“ Saved.') + chalk.gray(' Uploads default to PRIVATE so you can review them first β€”'));
+ console.log(chalk.gray(' set DEFAULT_PRIVACY_STATUS=public in .env when you\'re confident.'));
+ }
+
+ // ── Step 5: summary ────────────────────────────────────────────────────
+ async stepFinish() {
+ this.header(5, 'All set β€” here\'s what your pipeline can do');
+
+ await this.cm.loadCredentials();
+ await this.cm.loadTokens();
+ const creds = this.cm.credentials;
+
+ const hasText = this.cm.hasAITextProvider();
+ const hasGemini = Boolean(creds.gemini?.apiKey || process.env.GEMINI_API_KEY);
+ const hasMedia = Boolean(creds.openai?.apiKey || process.env.OPENAI_API_KEY || hasGemini);
+ const hasFFmpeg = await checkFFmpeg();
+ const hasUpload = Boolean(creds.youtube && this.cm.tokens.youtube);
+
+ const rows = [
+ { ok: hasText, name: 'Write scripts & pick topics', fix: 'step 2 (AI provider)' },
+ { ok: hasMedia, name: 'Generate images & voice narration', fix: 'step 2 β€” use a Gemini or OpenAI key' },
+ { ok: hasFFmpeg, name: 'Assemble real .mp4 videos', fix: ffmpegInstallHint() },
+ { ok: hasUpload, name: 'Upload to YouTube', fix: 'step 3 (YouTube connection)' }
+ ];
+
+ for (const row of rows) {
+ console.log(row.ok
+ ? chalk.green(` βœ“ ${row.name}`)
+ : chalk.yellow(` βœ— ${row.name} β€” re-run the walkthrough: ${row.fix}`));
+ }
+
+ console.log(chalk.cyan.bold('\nπŸš€ Next steps:'));
+ console.log(chalk.white(' 1. npm start'));
+ console.log(chalk.white(' 2. Open http://localhost:3456 and press "Generate Content"'));
+ console.log(chalk.white(' (or wait β€” it generates automatically every day at 6 AM)'));
+ console.log(chalk.white(' 3. Finished videos land in data/videos/ and upload as PRIVATE'));
+ console.log(chalk.gray('\nChanged your mind about anything? Just run: npm run walkthrough'));
+ }
+}
+
+if (require.main === module) {
+ new SetupWalkthrough().run().catch(error => {
+ console.error(chalk.red('\nWalkthrough failed:'), error.message);
+ console.log(chalk.yellow('Your progress so far is saved β€” re-run: npm run walkthrough'));
+ process.exit(1);
+ });
+}
+
+module.exports = { SetupWalkthrough, AI_PROVIDER_GUIDE };