# How to Debug RedditVideoMakerBot Code: A Complete Troubleshooting Guide

> Debug RedditVideoMakerBot code effectively. Use print statements, inspect console output, and verify config.toml and Playwright installation to troubleshoot issues. Get your bot running smoothly.

- Repository: [Lewis Menelaws/RedditVideoMakerBot](https://github.com/elebumm/RedditVideoMakerBot)
- Tags: how-to-guide
- Published: 2026-04-08

---

**The most effective way to debug RedditVideoMakerBot is to insert diagnostic print statements using the built-in `print_substep()` helper from [`utils/console.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/utils/console.py), inspect the color-coded console output to identify which pipeline stage fails, and verify your [`config.toml`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/config.toml) credentials and Playwright browser installation.**

RedditVideoMakerBot is an open-source Python automation tool that transforms Reddit threads into TikTok-style videos by orchestrating Reddit API calls, text-to-speech generation, screenshot capture, and ffmpeg video assembly. When the bot crashes or produces broken output, understanding its modular architecture is essential to pinpoint whether the issue stems from configuration validation in [`utils/settings.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/utils/settings.py), TTS processing in [`video_creation/voices.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/video_creation/voices.py), or video rendering in [`video_creation/final_video.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/video_creation/final_video.py).

## Understanding the RedditVideoMakerBot Architecture

The bot follows a linear pipeline architecture with eight distinct layers. Each layer is isolated in its own module, making it straightforward to isolate failures.

- **Entry point ([`main.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/main.py))**: Parses command-line arguments, verifies the Python version (3.10/3.11/3.12), ensures ffmpeg is available via `ffmpeg_install()`, and loads [`config.toml`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/config.toml) through `settings.check_toml()`.
- **Configuration ([`utils/settings.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/utils/settings.py))**: Validates each TOML entry against regex patterns and prompts the user for missing or invalid values through `handle_input()`.
- **Console UI ([`utils/console.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/utils/console.py))**: Provides the `print_step()` and `print_substep()` wrappers that color-code output using Rich.
- **Reddit API ([`reddit/subreddit.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/reddit/subreddit.py))**: Fetches the target thread and returns a structured dict via `get_subreddit_threads()`.
- **Text-to-Speech ([`video_creation/voices.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/video_creation/voices.py))**: Selects the configured TTS provider and creates MP3 files through `save_text_to_mp3()`.
- **Screenshot Capture ([`video_creation/screenshot_downloader.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/video_creation/screenshot_downloader.py))**: Uses Playwright to capture each comment via `get_screenshots_of_reddit_posts()`.
- **Background Handling ([`video_creation/background.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/video_creation/background.py))**: Downloads and trims background video to match TTS duration.
- **Final Assembly ([`video_creation/final_video.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/video_creation/final_video.py))**: Concatenates assets into the final MP4 using `make_final_video()`.

If any step throws an exception, the error bubbles up to the `try/except` block in [`main.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/main.py), which prints a full stack trace and executes `shutdown()` to clean temporary files.

## Common Failure Points and Diagnostic Strategies

### **Invalid Reddit Credentials** ([`main.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/main.py))

When `get_subreddit_threads()` raises a `ResponseException`, the bot typically surfaces an "Invalid credentials" error. Verify that `client_id`, `client_secret`, `username`, and `password` in [`config.toml`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/config.toml) are correct. The config validator in [`utils/settings.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/utils/settings.py) will loop until valid input is provided, so check the TOML file directly if prompts repeat infinitely.

### **TTS Provider Errors** ([`video_creation/voices.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/video_creation/voices.py))

"401 Unauthorized" or connection timeouts usually indicate missing API keys for providers like ElevenLabs or AWS Polly. The `save_text_to_mp3()` function selects the provider based on the `voice_choice` config key. Insert a temporary diagnostic to confirm the selection:

```python
from utils.console import print_substep

print_substep(f"Downloading background from {url}", style="bold magenta")

```

### **Blank or Missing Screenshots** ([`video_creation/screenshot_downloader.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/video_creation/screenshot_downloader.py))

Playwright browser binaries must be installed separately. If screenshots are not generated, run `playwright install` in your virtual environment. Add `print_substep` calls inside the screenshot loop to display each URL being captured and confirm the browser instance launches successfully.

### **FFmpeg Not Found** ([`utils/ffmpeg_install.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/utils/ffmpeg_install.py))

If the subprocess call returns "ffmpeg: command not found", invoke the installer manually to see detailed logs:

```bash
python -c "import utils.ffmpeg_install as f; f.ffmpeg_install()"

```

Ensure the downloaded binary is added to your system PATH before restarting the bot.

### **Final Video Length Mismatches** ([`video_creation/final_video.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/video_creation/final_video.py) or [`background.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/background.py))

Audio and video desync occurs when the background clip length does not match the total TTS duration. After `save_text_to_mp3()` completes, log the calculated length:

```python
print_substep(f"Total audio length: {length}s")

```

Verify this value is passed correctly to `chop_background()` in [`video_creation/background.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/video_creation/background.py).

### **Configuration Prompts Loop Forever** ([`utils/settings.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/utils/settings.py))

If `handle_input()` repeatedly asks for the same value, the input likely fails the regex validation defined in [`.config.template.toml`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/.config.template.toml). Temporarily add a print statement inside the `check()` function to reveal which validation rule is rejecting your input.

## Practical Debugging Code Snippets

Insert these snippets temporarily to expose internal state without disrupting the Rich console styling.

**Verbose TTS Provider Selection** (in [`video_creation/voices.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/video_creation/voices.py)):

```python
def save_text_to_mp3(reddit_obj):
    voice = settings.config["settings"]["tts"]["voice_choice"]
    print_substep(f"Configured voice: {voice}", style="yellow")
    if str(voice).casefold() in map(lambda _: _.casefold(), TTSProviders):
        print_substep("Found matching provider, initializing TTSEngine...", style="cyan")
        text_to_mp3 = TTSEngine(get_case_insensitive_key_value(TTSProvviders, voice), reddit_obj)
    else:
        # existing fallback logic …

        pass
    return text_to_mp3.run()

```

**Log MP3 Duration After Generation**:

```python

# Inside TTSEngine.run() (implementation varies per provider)

for comment_id, text in enumerate(comments):
    # generate mp3 …

    length_seconds = get_mp3_length(path)   # use mutagen or ffprobe

    print_substep(f"Comment {comment_id}: {length_seconds:.2f}s → {path}", style="green")

```

**Dump Reddit Object for Inspection** (in [`main.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/main.py) after fetch):

```python
reddit_object = get_subreddit_threads(POST_ID)
print_substep("Reddit payload (truncated):", style="dim")
print_substep(str(reddit_object)[:500] + "...", style="dim")

```

**Force a Clean Run from Command Line**:

```bash
python -c "import main, sys; sys.argv = ['main.py']; main.main('t3_xyz')"  # replace with a real post ID

```

This executes the pipeline directly, displaying every `print_step` and `print_substep` call so you can identify the last successful operation before a crash.

## Essential Source Files to Inspect

Keep these files open in your editor while debugging:

- **[`main.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/main.py)**: Orchestrates the workflow and catches top-level exceptions.
- **[`utils/settings.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/utils/settings.py)**: Contains the TOML validation logic and `handle_input()` prompts.
- **[`utils/console.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/utils/console.py)**: Defines `print_step()` and `print_substep()` for styled output.
- **[`reddit/subreddit.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/reddit/subreddit.py)**: Houses `get_subreddit_threads()` and PRAW integration.
- **[`video_creation/voices.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/video_creation/voices.py)**: Entry point for TTS generation and provider selection.
- **[`video_creation/screenshot_downloader.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/video_creation/screenshot_downloader.py)**: Playwright screenshot automation.
- **[`video_creation/background.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/video_creation/background.py)**: Background video download and trimming logic.
- **[`video_creation/final_video.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/video_creation/final_video.py)**: FFmpeg assembly commands.
- **[`utils/ffmpeg_install.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/utils/ffmpeg_install.py)**: Automatic ffmpeg binary installation.

## Quick Debug Checklist

1. **Python Version**: Confirm 3.10, 3.11, or 3.12 ([`main.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/main.py) enforces this).
2. **FFmpeg**: Run `ffmpeg -version`; execute `ffmpeg_install()` if missing.
3. **Config File**: Verify Reddit credentials and TTS API keys in [`config.toml`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/config.toml).
4. **TTS Provider**: Ensure the `voice_choice` value matches a supported provider exactly.
5. **Playwright Browsers**: Run `playwright install` to avoid "browser not found" errors.
6. **Network Access**: Confirm reachability to Reddit's API and your chosen TTS service endpoints.
7. **Disk Space**: Ensure several hundred MB are free for temporary screenshots, MP3s, and intermediate video files.

## Summary

- **RedditVideoMakerBot** consists of discrete pipeline stages from [`main.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/main.py) through [`video_creation/final_video.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/video_creation/final_video.py).
- Use **`print_substep()`** from [`utils/console.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/utils/console.py) to add color-coded diagnostics without cluttering the UI.
- Most crashes originate in **[`utils/settings.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/utils/settings.py)** (invalid config), **[`video_creation/voices.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/video_creation/voices.py)** (TTS auth), or **[`video_creation/screenshot_downloader.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/video_creation/screenshot_downloader.py)** (missing Playwright browsers).
- Inspect the stack trace printed by the exception handler in **[`main.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/main.py)** to locate the exact file and line number of the failure.
- Run **`ffmpeg_install()`** manually if you encounter "command not found" errors.

## Frequently Asked Questions

### Why does RedditVideoMakerBot keep asking for the same configuration value repeatedly?

This occurs when the input fails the regex validation defined in [`.config.template.toml`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/.config.template.toml) and enforced by `handle_input()` in [`utils/settings.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/utils/settings.py). Add a temporary `print()` statement inside the `check()` function to see which validation rule is rejecting your input, then ensure your entry matches the expected format (e.g., no spaces in API keys, correct casing for enums).

### How do I fix blank or missing screenshots in my Reddit video?

Blank screenshots indicate that Playwright cannot locate its browser binaries. Run `playwright install` in your terminal to download the required Chromium, Firefox, or WebKit browsers. If the issue persists, add `print_substep()` calls inside `get_screenshots_of_reddit_posts()` to verify that the function receives valid URLs and that the page loads without HTTP errors.

### What causes "ffmpeg: command not found" errors even after installation?

The bot relies on [`utils/ffmpeg_install.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/utils/ffmpeg_install.py) to download a compatible binary, but it may not be added to your system PATH automatically. Invoke `python -c "import utils.ffmpeg_install as f; f.ffmpeg_install()"` manually and note the installation path. Add that directory to your PATH environment variable, or ensure the binary is placed in a directory already listed in PATH (such as `/usr/local/bin` on Linux/macOS or `C:\Windows\System32` on Windows).

### How can I verify which TTS provider is actually being used?

Insert a diagnostic print inside `save_text_to_mp3()` in [`video_creation/voices.py`](https://github.com/elebumm/RedditVideoMakerBot/blob/main/video_creation/voices.py) to log the `voice_choice` value from the config. The code iterates over `TTSProviders` using a case-insensitive match via `get_case_insensitive_key_value()`; printing the resolved provider name confirms whether the bot loaded Google Translate, ElevenLabs, AWS Polly, or another engine before initializing the `TTSEngine`.