Bunch of fixes

pull/2041/head
Kristian 1 year ago
parent baad243b22
commit 18eb749bee

1
.gitignore vendored

@ -240,6 +240,7 @@ out
.DS_Store .DS_Store
.setup-done-before .setup-done-before
results/* results/*
clipped/*
reddit-bot-351418-5560ebc49cac.json reddit-bot-351418-5560ebc49cac.json
/.idea /.idea
*.pyc *.pyc

@ -203,7 +203,7 @@ def make_final_video(
"No audio clips to gather. Please use a different TTS or post." "No audio clips to gather. Please use a different TTS or post."
) # This is to fix the TypeError: unsupported operand type(s) for +: 'int' and 'NoneType' ) # This is to fix the TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
exit() exit()
if settings.config["settings"]["storymode"]: if settings.config["settings"]["storymode"] and not settings.config["settings"]["mememode"]:
if settings.config["settings"]["storymodemethod"] == 0: if settings.config["settings"]["storymodemethod"] == 0:
audio_clips = [ffmpeg.input(f"assets/temp/{reddit_id}/mp3/title.mp3")] audio_clips = [ffmpeg.input(f"assets/temp/{reddit_id}/mp3/title.mp3")]
audio_clips.insert(1, ffmpeg.input(f"assets/temp/{reddit_id}/mp3/postaudio.mp3")) audio_clips.insert(1, ffmpeg.input(f"assets/temp/{reddit_id}/mp3/postaudio.mp3"))
@ -231,7 +231,7 @@ def make_final_video(
audio_concat = ffmpeg.concat(*audio_clips, a=1, v=0) audio_concat = ffmpeg.concat(*audio_clips, a=1, v=0)
ffmpeg.output( ffmpeg.output(
audio_concat, f"assets/temp/{reddit_id}/audio.mp3", **{"b:a": "192k"} audio_concat, f"assets/temp/{reddit_id}/audio.mp3", **{"b:a": "192k"}
).overwrite_output().run(quiet=True) ).overwrite_output().run(quiet=False)
console.log(f"[bold green] Video Will Be: {length} Seconds Long") console.log(f"[bold green] Video Will Be: {length} Seconds Long")
@ -241,7 +241,7 @@ def make_final_video(
image_clips = list() image_clips = list()
if settings.config["settings"]["storymode"]: if not settings.config["settings"]["mememode"] and settings.config["settings"]["storymodemethod"] == 1:
Path(f"assets/temp/{reddit_id}/png").mkdir(parents=True, exist_ok=True) Path(f"assets/temp/{reddit_id}/png").mkdir(parents=True, exist_ok=True)
# Copyright 2024 beingbored (aka. Tim), MIT License, permission granted to use, copy, modify, and distribute. # Copyright 2024 beingbored (aka. Tim), MIT License, permission granted to use, copy, modify, and distribute.

@ -1,3 +1,4 @@
import os
from utils import settings from utils import settings
from moviepy.editor import VideoFileClip, concatenate_videoclips from moviepy.editor import VideoFileClip, concatenate_videoclips

@ -14,7 +14,6 @@ from utils.console import print_step, print_substep
from utils.imagenarator import imagemaker from utils.imagenarator import imagemaker
from utils.playwright import clear_cookie_by_name from utils.playwright import clear_cookie_by_name
from utils.videos import save_data from utils.videos import save_data
from video_creation.final_video import name_normalize
__all__ = ["download_screenshots_of_reddit_posts"] __all__ = ["download_screenshots_of_reddit_posts"]
@ -26,8 +25,6 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
screenshot_num (int): Number of screenshots to download screenshot_num (int): Number of screenshots to download
""" """
if settings.config["settings"]["storymodemethod"] == 0:
return
# settings values # settings values
W: Final[int] = int(settings.config["settings"]["resolution_w"]) W: Final[int] = int(settings.config["settings"]["resolution_w"])
H: Final[int] = int(settings.config["settings"]["resolution_h"]) H: Final[int] = int(settings.config["settings"]["resolution_h"])
@ -74,6 +71,9 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
transparent=transparent, transparent=transparent,
) )
if settings.config["settings"]["storymodemethod"] == 1:
return
screenshot_num: int screenshot_num: int
with sync_playwright() as p: with sync_playwright() as p:
print_substep("Launching Headless Browser...") print_substep("Launching Headless Browser...")
@ -134,7 +134,7 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
# Reload the page for the redesign to take effect # Reload the page for the redesign to take effect
page.reload() page.reload()
# Get the thread screenshot # Get the thread screenshot
page.goto(reddit_object["thread_url"], timeout=0) page.goto(reddit_object["thread_url"].replace("//r", "/r"), timeout=0)
page.set_viewport_size(ViewportSize(width=W, height=H)) page.set_viewport_size(ViewportSize(width=W, height=H))
page.wait_for_load_state() page.wait_for_load_state()
page.wait_for_timeout(5000) page.wait_for_timeout(5000)
@ -173,8 +173,42 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
else: else:
print_substep("Skipping translation...") print_substep("Skipping translation...")
if mememode or settings.config["settings"]["storymodemethod"] == 0:
postcontentpath = f"assets/temp/{reddit_id}/png/title.png"
try:
if settings.config["settings"]["zoom"] != 1:
# store zoom settings
zoom = settings.config["settings"]["zoom"]
# zoom the body of the page
page.evaluate("document.body.style.zoom=" + str(zoom))
# as zooming the body doesn't change the properties of the divs, we need to adjust for the zoom
location = page.locator('[view-context="CommentsPage"]').bounding_box() # view-context="CommentsPage"
for i in location:
location[i] = float("{:.2f}".format(location[i] * zoom))
page.screenshot(clip=location, path=postcontentpath)
else:
page.locator('[view-context="CommentsPage"]').screenshot(path=postcontentpath)
except Exception as e:
print_substep("Something went wrong!", style="red")
resp = input(
"Something went wrong with making the screenshots! Do you want to skip the post? (y/n) "
)
if resp.casefold().startswith("y"):
save_data("", "", "skipped", reddit_id, "")
print_substep(
"The post is successfully skipped! You can now restart the program and this post will skipped.",
"green",
)
resp = input("Do you want the error traceback for debugging purposes? (y/n)")
if not resp.casefold().startswith("y"):
exit()
raise e
if storymode and not mememode: if storymode and not mememode:
page.locator('[data-click-id="text"]').first.screenshot( page.locator('[data-post-click-location="text-body"]').first.screenshot(
path=f"assets/temp/{reddit_id}/png/story_content.png" path=f"assets/temp/{reddit_id}/png/story_content.png"
) )
elif not mememode: elif not mememode:
@ -184,6 +218,8 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
"Downloading screenshots...", "Downloading screenshots...",
) )
): ):
print(f"https://www.reddit.com{comment['comment_url']}")
# Stop if we have reached the screenshot_num # Stop if we have reached the screenshot_num
if idx >= screenshot_num: if idx >= screenshot_num:
break break
@ -191,7 +227,7 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
if page.locator('[data-testid="content-gate"]').is_visible(): if page.locator('[data-testid="content-gate"]').is_visible():
page.locator('[data-testid="content-gate"] button').click() page.locator('[data-testid="content-gate"] button').click()
page.goto(f"https://new.reddit.com/{comment['comment_url']}") page.goto(f"https://www.reddit.com{comment['comment_url']}")
# translate code # translate code

Loading…
Cancel
Save