Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!")

Expand Down
8 changes: 5 additions & 3 deletions utils/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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)
Expand All @@ -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"]
Expand All @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions utils/videomaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down