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 5 months ago
parent ca6b464062
commit f84b68606f
No known key found for this signature in database

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

@ -1,6 +1,8 @@
import multiprocessing import multiprocessing
import os import os
import re import re
import shutil
import subprocess
import tempfile import tempfile
import textwrap import textwrap
import threading import threading
@ -10,6 +12,21 @@ from pathlib import Path
from typing import Dict, Final, Tuple from typing import Dict, Final, Tuple
import ffmpeg 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 import translators
from PIL import Image, ImageDraw, ImageFont from PIL import Image, ImageDraw, ImageFont
from rich.console import Console from rich.console import Console
@ -93,7 +110,7 @@ def prepare_background(reddit_id: str, W: int, H: int) -> str:
output_path, output_path,
an=None, an=None,
**{ **{
"c:v": "h264_nvenc", "c:v": VIDEO_CODEC,
"b:v": "20M", "b:v": "20M",
"b:a": "192k", "b:a": "192k",
"threads": multiprocessing.cpu_count(), "threads": multiprocessing.cpu_count(),
@ -438,7 +455,7 @@ def make_final_video(
path, path,
f="mp4", f="mp4",
**{ **{
"c:v": "h264_nvenc", "c:v": VIDEO_CODEC,
"b:v": "20M", "b:v": "20M",
"b:a": "192k", "b:a": "192k",
"threads": multiprocessing.cpu_count(), "threads": multiprocessing.cpu_count(),
@ -468,7 +485,7 @@ def make_final_video(
path, path,
f="mp4", f="mp4",
**{ **{
"c:v": "h264_nvenc", "c:v": VIDEO_CODEC,
"b:v": "20M", "b:v": "20M",
"b:a": "192k", "b:a": "192k",
"threads": multiprocessing.cpu_count(), "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_load_state()
page.wait_for_timeout(5000) page.wait_for_timeout(5000)
if page.locator( nsfw_button = page.locator("button:has-text('Yes'), button:has-text('Continue'), [data-testid='content-gate'] button").first
"#t3_12hmbug > div > div._3xX726aBn29LDbsDtzr_6E._1Ap4F5maDtT1E1YuCiaO0r.D3IL3FD0RFy_mkKLPwL4 > div > div > button" if nsfw_button.is_visible():
).is_visible():
# This means the post is NSFW and requires to click the proceed button.
print_substep("Post is NSFW. You are spicy...") print_substep("Post is NSFW. You are spicy...")
page.locator( nsfw_button.click()
"#t3_12hmbug > div > div._3xX726aBn29LDbsDtzr_6E._1Ap4F5maDtT1E1YuCiaO0r.D3IL3FD0RFy_mkKLPwL4 > div > div > button" page.wait_for_load_state()
).click()
page.wait_for_load_state() # Wait for page to fully load
# translate code # translate code
if page.locator( if page.locator(

Loading…
Cancel
Save