|
|
|
@ -4,6 +4,7 @@ from pathlib import Path
|
|
|
|
|
from typing import Dict, Final
|
|
|
|
|
|
|
|
|
|
import translators
|
|
|
|
|
from playwright.async_api import async_playwright # pylint: disable=unused-import
|
|
|
|
|
from playwright.sync_api import ViewportSize, sync_playwright
|
|
|
|
|
from rich.progress import track
|
|
|
|
|
|
|
|
|
@ -11,6 +12,7 @@ from utils import settings
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
__all__ = ["download_screenshots_of_reddit_posts"]
|
|
|
|
@ -36,9 +38,7 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
|
|
|
|
|
|
|
|
|
|
# set the theme and disable non-essential cookies
|
|
|
|
|
if settings.config["settings"]["theme"] == "dark":
|
|
|
|
|
cookie_file = open(
|
|
|
|
|
"./video_creation/data/cookie-dark-mode.json", encoding="utf-8"
|
|
|
|
|
)
|
|
|
|
|
cookie_file = open("./video_creation/data/cookie-dark-mode.json", encoding="utf-8")
|
|
|
|
|
bgcolor = (33, 33, 36, 255)
|
|
|
|
|
txtcolor = (240, 240, 240)
|
|
|
|
|
transparent = False
|
|
|
|
@ -48,33 +48,19 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
|
|
|
|
|
bgcolor = (0, 0, 0, 0)
|
|
|
|
|
txtcolor = (255, 255, 255)
|
|
|
|
|
transparent = True
|
|
|
|
|
cookie_file = open(
|
|
|
|
|
"./video_creation/data/cookie-dark-mode.json", encoding="utf-8"
|
|
|
|
|
)
|
|
|
|
|
cookie_file = open("./video_creation/data/cookie-dark-mode.json", encoding="utf-8")
|
|
|
|
|
else:
|
|
|
|
|
# Switch to dark theme
|
|
|
|
|
cookie_file = open(
|
|
|
|
|
"./video_creation/data/cookie-dark-mode.json", encoding="utf-8"
|
|
|
|
|
)
|
|
|
|
|
cookie_file = open("./video_creation/data/cookie-dark-mode.json", encoding="utf-8")
|
|
|
|
|
bgcolor = (33, 33, 36, 255)
|
|
|
|
|
txtcolor = (240, 240, 240)
|
|
|
|
|
transparent = False
|
|
|
|
|
else:
|
|
|
|
|
cookie_file = open(
|
|
|
|
|
"./video_creation/data/cookie-light-mode.json", encoding="utf-8"
|
|
|
|
|
)
|
|
|
|
|
cookie_file = open("./video_creation/data/cookie-light-mode.json", encoding="utf-8")
|
|
|
|
|
bgcolor = (255, 255, 255, 255)
|
|
|
|
|
txtcolor = (0, 0, 0)
|
|
|
|
|
transparent = False
|
|
|
|
|
if storymode and settings.config["settings"]["storymodemethod"] == 1:
|
|
|
|
|
# for idx,item in enumerate(reddit_object["thread_post"]):
|
|
|
|
|
print_substep("Generating images...")
|
|
|
|
|
return imagemaker(
|
|
|
|
|
theme=bgcolor,
|
|
|
|
|
reddit_obj=reddit_object,
|
|
|
|
|
txtclr=txtcolor,
|
|
|
|
|
transparent=transparent,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
screenshot_num: int
|
|
|
|
|
with sync_playwright() as p:
|
|
|
|
@ -106,12 +92,8 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
|
|
|
|
|
page.set_viewport_size(ViewportSize(width=1920, height=1080))
|
|
|
|
|
page.wait_for_load_state()
|
|
|
|
|
|
|
|
|
|
page.locator('[name="username"]').fill(
|
|
|
|
|
settings.config["reddit"]["creds"]["username"]
|
|
|
|
|
)
|
|
|
|
|
page.locator('[name="password"]').fill(
|
|
|
|
|
settings.config["reddit"]["creds"]["password"]
|
|
|
|
|
)
|
|
|
|
|
page.locator('[name="username"]').fill(settings.config["reddit"]["creds"]["username"])
|
|
|
|
|
page.locator('[name="password"]').fill(settings.config["reddit"]["creds"]["password"])
|
|
|
|
|
page.locator("button[class$='m-full-width']").click()
|
|
|
|
|
page.wait_for_timeout(5000)
|
|
|
|
|
|
|
|
|
@ -187,14 +169,16 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
|
|
|
|
|
# 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
|
|
|
|
|
element_to_hide = page.locator('[data-click-id="text"]')
|
|
|
|
|
element_to_hide.evaluate('node => node.style.display = "none"')
|
|
|
|
|
location = page.locator('[data-test-id="post-content"]').bounding_box()
|
|
|
|
|
for i in location:
|
|
|
|
|
location[i] = float("{:.2f}".format(location[i] * zoom))
|
|
|
|
|
page.screenshot(clip=location, path=postcontentpath)
|
|
|
|
|
else:
|
|
|
|
|
page.locator('[data-test-id="post-content"]').screenshot(
|
|
|
|
|
path=postcontentpath
|
|
|
|
|
)
|
|
|
|
|
element_to_hide = page.locator('[data-click-id="text"]')
|
|
|
|
|
element_to_hide.evaluate('node => node.style.display = "none"')
|
|
|
|
|
page.locator('[data-test-id="post-content"]').screenshot(path=postcontentpath)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print_substep("Something went wrong!", style="red")
|
|
|
|
|
resp = input(
|
|
|
|
@ -208,15 +192,15 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
|
|
|
|
|
"green",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
resp = input(
|
|
|
|
|
"Do you want the error traceback for debugging purposes? (y/n)"
|
|
|
|
|
)
|
|
|
|
|
resp = input("Do you want the error traceback for debugging purposes? (y/n)")
|
|
|
|
|
if not resp.casefold().startswith("y"):
|
|
|
|
|
exit()
|
|
|
|
|
|
|
|
|
|
raise e
|
|
|
|
|
|
|
|
|
|
if storymode:
|
|
|
|
|
element_to_hide = page.locator('[data-click-id="text"]')
|
|
|
|
|
element_to_hide.evaluate('node => node.style.display = "block"')
|
|
|
|
|
page.locator('[data-click-id="text"]').first.screenshot(
|
|
|
|
|
path=f"assets/temp/{reddit_id}/png/story_content.png"
|
|
|
|
|
)
|
|
|
|
@ -255,13 +239,9 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
|
|
|
|
|
# zoom the body of the page
|
|
|
|
|
page.evaluate("document.body.style.zoom=" + str(zoom))
|
|
|
|
|
# scroll comment into view
|
|
|
|
|
page.locator(
|
|
|
|
|
f"#t1_{comment['comment_id']}"
|
|
|
|
|
).scroll_into_view_if_needed()
|
|
|
|
|
page.locator(f"#t1_{comment['comment_id']}").scroll_into_view_if_needed()
|
|
|
|
|
# as zooming the body doesn't change the properties of the divs, we need to adjust for the zoom
|
|
|
|
|
location = page.locator(
|
|
|
|
|
f"#t1_{comment['comment_id']}"
|
|
|
|
|
).bounding_box()
|
|
|
|
|
location = page.locator(f"#t1_{comment['comment_id']}").bounding_box()
|
|
|
|
|
for i in location:
|
|
|
|
|
location[i] = float("{:.2f}".format(location[i] * zoom))
|
|
|
|
|
page.screenshot(
|
|
|
|
@ -282,3 +262,12 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
|
|
|
|
|
browser.close()
|
|
|
|
|
|
|
|
|
|
print_substep("Screenshots downloaded Successfully.", style="bold green")
|
|
|
|
|
if storymode and settings.config["settings"]["storymodemethod"] == 1:
|
|
|
|
|
# for idx,item in enumerate(reddit_object["thread_post"]):
|
|
|
|
|
print_substep("Generating images...")
|
|
|
|
|
return imagemaker(
|
|
|
|
|
theme=bgcolor,
|
|
|
|
|
reddit_obj=reddit_object,
|
|
|
|
|
txtclr=txtcolor,
|
|
|
|
|
transparent=transparent,
|
|
|
|
|
)
|