diff --git a/main.py b/main.py index c691a80..f3b4d8b 100644 --- a/main.py +++ b/main.py @@ -193,7 +193,7 @@ def main(): db.close() # Remove the temporary directory at the end - shutil.rmtree("/assets/temp") + shutil.rmtree("./assets/temp") print("Done! See result in the results folder!") diff --git a/utils/reddit.py b/utils/reddit.py index 5b25bed..19f9e04 100644 --- a/utils/reddit.py +++ b/utils/reddit.py @@ -168,14 +168,14 @@ def get_screenshots_of_reddit_posts(reddit_thread: Submission, reddit_comments: page = context.new_page() page.goto("https://www.reddit.com/login", timeout=0) page.set_viewport_size(ViewportSize(width=1920, height=1080)) - page.wait_for_load_state() + page.wait_for_load_state('load') # Fill in login credentials and submit print("Logging into Reddit...") page.locator('input[name="username"]').fill(my_config["RedditCredential"]["username"]) page.locator('input[name="password"]').fill(my_config["RedditCredential"]["passkey"]) page.get_by_role("button", name="Log In").click() - page.wait_for_timeout(5000) + page.wait_for_load_state('load') # Handle Reddit redesign opt-out if necessary if page.locator("#redesign-beta-optin-btn").is_visible(): @@ -186,7 +186,7 @@ def get_screenshots_of_reddit_posts(reddit_thread: Submission, reddit_comments: print("Navigating to Reddit thread...") page.goto(f"https://new.reddit.com{reddit_thread.permalink}", timeout=0) page.set_viewport_size(ViewportSize(width=W, height=H)) - page.wait_for_timeout(5000) + page.wait_for_load_state('load') # Take screenshot of the post content # (not used in the final video - using fancy title instead) @@ -207,6 +207,7 @@ def get_screenshots_of_reddit_posts(reddit_thread: Submission, reddit_comments: comments_path = f"./assets/temp/{reddit_thread.id}/png/{idx}.png" page.goto(f'https://new.reddit.com{comment.permalink}', timeout=0) + page.wait_for_load_state('load') if my_config["settings"]["zoom"] != 1: # page.locator("button[aria-controls=\"comment-children\"]").first.click() zoom = my_config["settings"]["zoom"] @@ -220,6 +221,7 @@ def get_screenshots_of_reddit_posts(reddit_thread: Submission, reddit_comments: # page.locator("button[aria-controls=\"comment-children\"]").first.click() # page.locator(f"shreddit-comment[thingid=\"t1_{comment.id}\"]").screenshot(path=comments_path) location = page.locator(f"#t1_{comment.id}-comment-rtjson-content").bounding_box() + page.screenshot(clip=location, path=comments_path) print("Saved: ", comments_path) browser.close() diff --git a/utils/videomaker.py b/utils/videomaker.py index 7223a58..60563cf 100644 --- a/utils/videomaker.py +++ b/utils/videomaker.py @@ -38,6 +38,12 @@ def prepare_background(length: int, W: int, H: int) -> CompositeVideoClip: video = VideoFileClip(my_config['paths']['background']).without_audio() video_duration = video.duration + # Check if the video is shorter than the required length + if video_duration < length: + print(f"Background video is shorter than the required length ({length} seconds).") + print("Please provide a longer background video.") + exit(1) + # Select a random start time within the background video random_start = random.randint(0, int(video_duration - length)) vid = video.subclip(random_start, random_start + length)