|
|
|
@ -14,7 +14,6 @@ from utils.console import print_step, print_substep
|
|
|
|
|
from utils.imagenarator import imagemaker
|
|
|
|
|
from utils.playwright import clear_cookie_by_name
|
|
|
|
|
from utils.videos import save_data
|
|
|
|
|
from video_creation.final_video import name_normalize
|
|
|
|
|
|
|
|
|
|
__all__ = ["download_screenshots_of_reddit_posts"]
|
|
|
|
|
|
|
|
|
@ -25,9 +24,7 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
|
|
|
|
|
reddit_object (Dict): Reddit object received from reddit/subreddit.py
|
|
|
|
|
screenshot_num (int): Number of screenshots to download
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
if settings.config["settings"]["storymodemethod"] == 0:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# settings values
|
|
|
|
|
W: Final[int] = int(settings.config["settings"]["resolution_w"])
|
|
|
|
|
H: Final[int] = int(settings.config["settings"]["resolution_h"])
|
|
|
|
@ -73,6 +70,9 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
|
|
|
|
|
txtclr=txtcolor,
|
|
|
|
|
transparent=transparent,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if settings.config["settings"]["storymodemethod"] == 1:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
screenshot_num: int
|
|
|
|
|
with sync_playwright() as p:
|
|
|
|
@ -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
|
|
|
|
|
page.reload()
|
|
|
|
|
# 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.wait_for_load_state()
|
|
|
|
|
page.wait_for_timeout(5000)
|
|
|
|
@ -173,8 +173,42 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
|
|
|
|
|
else:
|
|
|
|
|
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:
|
|
|
|
|
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"
|
|
|
|
|
)
|
|
|
|
|
elif not mememode:
|
|
|
|
@ -184,6 +218,8 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
|
|
|
|
|
"Downloading screenshots...",
|
|
|
|
|
)
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
print(f"https://www.reddit.com{comment['comment_url']}")
|
|
|
|
|
# Stop if we have reached the screenshot_num
|
|
|
|
|
if idx >= screenshot_num:
|
|
|
|
|
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():
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|