How to Debug RedditVideoMakerBot Code: A Complete Troubleshooting Guide
The most effective way to debug RedditVideoMakerBot is to insert diagnostic print statements using the built-in print_substep() helper from utils/console.py, inspect the color-coded console output to identify which pipeline stage fails, and verify your 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, TTS processing in video_creation/voices.py, or video rendering in 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): Parses command-line arguments, verifies the Python version (3.10/3.11/3.12), ensures ffmpeg is available viaffmpeg_install(), and loadsconfig.tomlthroughsettings.check_toml(). - Configuration (
utils/settings.py): Validates each TOML entry against regex patterns and prompts the user for missing or invalid values throughhandle_input(). - Console UI (
utils/console.py): Provides theprint_step()andprint_substep()wrappers that color-code output using Rich. - Reddit API (
reddit/subreddit.py): Fetches the target thread and returns a structured dict viaget_subreddit_threads(). - Text-to-Speech (
video_creation/voices.py): Selects the configured TTS provider and creates MP3 files throughsave_text_to_mp3(). - Screenshot Capture (
video_creation/screenshot_downloader.py): Uses Playwright to capture each comment viaget_screenshots_of_reddit_posts(). - Background Handling (
video_creation/background.py): Downloads and trims background video to match TTS duration. - Final Assembly (
video_creation/final_video.py): Concatenates assets into the final MP4 usingmake_final_video().
If any step throws an exception, the error bubbles up to the try/except block in 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)
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 are correct. The config validator in 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)
"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:
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)
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)
If the subprocess call returns "ffmpeg: command not found", invoke the installer manually to see detailed logs:
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 or 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:
print_substep(f"Total audio length: {length}s")
Verify this value is passed correctly to chop_background() in video_creation/background.py.
Configuration Prompts Loop Forever (utils/settings.py)
If handle_input() repeatedly asks for the same value, the input likely fails the regex validation defined in .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):
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:
# 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 after fetch):
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:
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: Orchestrates the workflow and catches top-level exceptions.utils/settings.py: Contains the TOML validation logic andhandle_input()prompts.utils/console.py: Definesprint_step()andprint_substep()for styled output.reddit/subreddit.py: Housesget_subreddit_threads()and PRAW integration.video_creation/voices.py: Entry point for TTS generation and provider selection.video_creation/screenshot_downloader.py: Playwright screenshot automation.video_creation/background.py: Background video download and trimming logic.video_creation/final_video.py: FFmpeg assembly commands.utils/ffmpeg_install.py: Automatic ffmpeg binary installation.
Quick Debug Checklist
- Python Version: Confirm 3.10, 3.11, or 3.12 (
main.pyenforces this). - FFmpeg: Run
ffmpeg -version; executeffmpeg_install()if missing. - Config File: Verify Reddit credentials and TTS API keys in
config.toml. - TTS Provider: Ensure the
voice_choicevalue matches a supported provider exactly. - Playwright Browsers: Run
playwright installto avoid "browser not found" errors. - Network Access: Confirm reachability to Reddit's API and your chosen TTS service endpoints.
- 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.pythroughvideo_creation/final_video.py. - Use
print_substep()fromutils/console.pyto add color-coded diagnostics without cluttering the UI. - Most crashes originate in
utils/settings.py(invalid config),video_creation/voices.py(TTS auth), orvideo_creation/screenshot_downloader.py(missing Playwright browsers). - Inspect the stack trace printed by the exception handler in
main.pyto 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 and enforced by handle_input() in 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 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 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.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →