fix: Fix 4 critical bugs preventing pipeline from running

1. reddit/subreddit.py: passkey= → password= (PRAW correct param name)
2. reddit/subreddit.py: bare except → Exception with sys.exit(1)
   Prevents UnboundLocalError when reddit object not created
3. screenshot_downloader.py: NSFW hardcoded #t3_12hmbug selector →
   generic button selector that works with any NSFW post
4. final_video.py: h264_nvenc hardcoded → auto-detect GPU encoder,
   fallback to libx264 for machines without NVIDIA GPU

https://claude.ai/code/session_01G67vV3sJLXtm2q9r9FcF7L
pull/2541/head
Claude 3 weeks ago
parent ca6b464062
commit f84b68606f
No known key found for this signature in database

@ -1,4 +1,5 @@
import re
import sys
import praw
from praw.models import MoreComments
@ -38,14 +39,16 @@ def get_subreddit_threads(POST_ID: str):
client_secret=settings.config["reddit"]["creds"]["client_secret"],
user_agent="Accessing Reddit threads",
username=username,
passkey=passkey,
password=passkey,
check_for_async=False,
)
except ResponseException as e:
if e.response.status_code == 401:
print("Invalid credentials - please check them in config.toml")
except:
print("Something went wrong...")
sys.exit(1)
except Exception as e:
print(f"Something went wrong logging into Reddit: {e}")
sys.exit(1)
# Ask user for subreddit input
print_step("Getting subreddit threads...")

@ -1,6 +1,8 @@
import multiprocessing
import os
import re
import shutil
import subprocess
import tempfile
import textwrap
import threading
@ -10,6 +12,21 @@ from pathlib import Path
from typing import Dict, Final, Tuple
import ffmpeg
def _get_video_codec() -> str:
try:
result = subprocess.run(
["ffmpeg", "-encoders"], capture_output=True, text=True, timeout=10
)
if "h264_nvenc" in result.stdout:
return "h264_nvenc"
except (subprocess.TimeoutExpired, FileNotFoundError):
pass
return "libx264"
VIDEO_CODEC = _get_video_codec()
import translators
from PIL import Image, ImageDraw, ImageFont
from rich.console import Console
@ -93,7 +110,7 @@ def prepare_background(reddit_id: str, W: int, H: int) -> str:
output_path,
an=None,
**{
"c:v": "h264_nvenc",
"c:v": VIDEO_CODEC,
"b:v": "20M",
"b:a": "192k",
"threads": multiprocessing.cpu_count(),
@ -438,7 +455,7 @@ def make_final_video(
path,
f="mp4",
**{
"c:v": "h264_nvenc",
"c:v": VIDEO_CODEC,
"b:v": "20M",
"b:a": "192k",
"threads": multiprocessing.cpu_count(),
@ -468,7 +485,7 @@ def make_final_video(
path,
f="mp4",
**{
"c:v": "h264_nvenc",
"c:v": VIDEO_CODEC,
"b:v": "20M",
"b:a": "192k",
"threads": multiprocessing.cpu_count(),

@ -145,16 +145,11 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
page.wait_for_load_state()
page.wait_for_timeout(5000)
if page.locator(
"#t3_12hmbug > div > div._3xX726aBn29LDbsDtzr_6E._1Ap4F5maDtT1E1YuCiaO0r.D3IL3FD0RFy_mkKLPwL4 > div > div > button"
).is_visible():
# This means the post is NSFW and requires to click the proceed button.
nsfw_button = page.locator("button:has-text('Yes'), button:has-text('Continue'), [data-testid='content-gate'] button").first
if nsfw_button.is_visible():
print_substep("Post is NSFW. You are spicy...")
page.locator(
"#t3_12hmbug > div > div._3xX726aBn29LDbsDtzr_6E._1Ap4F5maDtT1E1YuCiaO0r.D3IL3FD0RFy_mkKLPwL4 > div > div > button"
).click()
page.wait_for_load_state() # Wait for page to fully load
nsfw_button.click()
page.wait_for_load_state()
# translate code
if page.locator(

Loading…
Cancel
Save