pull/2138/merge
Roostydoo2 3 months ago committed by GitHub
commit 641a0fb9b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -175,12 +175,12 @@ 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
location = page.locator('[data-test-id="post-content"]').bounding_box()
location = page.locator('h1[slot="title"]').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)
page.locator('h1[slot="title"]').screenshot(path=postcontentpath)
except Exception as e:
print_substep("Something went wrong!", style="red")
resp = input(
@ -229,11 +229,13 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
to_language=settings.config["reddit"]["thread"]["post_lang"],
)
page.evaluate(
'([tl_content, tl_id]) => document.querySelector(`#t1_${tl_id} > div:nth-child(2) > div > div[data-testid="comment"] > div`).textContent = tl_content',
[comment_tl, comment["comment_id"]],
'([tl_content, tl_id]) => document.querySelector(`#t1_${tl_id}-comment-rtjson-content p`).textContent = tl_content',
[comment_tl, comment["comment_id"]]
)
try:
if settings.config["settings"]["zoom"] != 1:
# click on button to close replies so that they are not shown in the video
page.locator("button[aria-controls=\"comment-children\"]").first.click()
# store zoom settings
zoom = settings.config["settings"]["zoom"]
# zoom the body of the page
@ -241,7 +243,7 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
# scroll comment into view
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"shreddit-comment[thingid=\"t1_{comment['comment_id']}\"]").bounding_box()
for i in location:
location[i] = float("{:.2f}".format(location[i] * zoom))
page.screenshot(
@ -249,7 +251,9 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
path=f"assets/temp/{reddit_id}/png/comment_{idx}.png",
)
else:
page.locator(f"#t1_{comment['comment_id']}").screenshot(
# click on button to close replies so that they are not shown in the video
page.locator("button[aria-controls=\"comment-children\"]").first.click()
page.locator(f"shreddit-comment[thingid=\"t1_{comment['comment_id']}\"]").screenshot(
path=f"assets/temp/{reddit_id}/png/comment_{idx}.png"
)
except TimeoutError:

Loading…
Cancel
Save