Update screenshot_downloader.py

Fixes bug where the application always fails on the skipping translation step and fails to take screenshots
pull/2138/head
Roostydoo2 1 year ago committed by GitHub
parent c68c5808cb
commit 62e7f17f02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -182,7 +182,7 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
location[i] = float("{:.2f}".format(location[i] * zoom)) location[i] = float("{:.2f}".format(location[i] * zoom))
page.screenshot(clip=location, path=postcontentpath) page.screenshot(clip=location, path=postcontentpath)
else: else:
page.locator('[data-test-id="post-content"]').screenshot(path=postcontentpath) page.locator('h1[slot="title"]').screenshot(path=postcontentpath)
except Exception as e: except Exception as e:
print_substep("Something went wrong!", style="red") print_substep("Something went wrong!", style="red")
resp = input( resp = input(
@ -231,11 +231,13 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
to_language=settings.config["reddit"]["thread"]["post_lang"], to_language=settings.config["reddit"]["thread"]["post_lang"],
) )
page.evaluate( page.evaluate(
'([tl_content, tl_id]) => document.querySelector(`#t1_${tl_id} > div:nth-child(2) > div > div[data-testid="comment"] > div`).textContent = tl_content', '([tl_content, tl_id]) => document.querySelector(`#t1_${tl_id}-comment-rtjson-content p`).textContent = tl_content',
[comment_tl, comment["comment_id"]], [comment_tl, comment["comment_id"]]
) )
try: try:
if settings.config["settings"]["zoom"] != 1: 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 # store zoom settings
zoom = settings.config["settings"]["zoom"] zoom = settings.config["settings"]["zoom"]
# zoom the body of the page # zoom the body of the page
@ -243,7 +245,7 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
# scroll comment into view # 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 # 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: for i in location:
location[i] = float("{:.2f}".format(location[i] * zoom)) location[i] = float("{:.2f}".format(location[i] * zoom))
page.screenshot( page.screenshot(
@ -251,7 +253,9 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
path=f"assets/temp/{reddit_id}/png/comment_{idx}.png", path=f"assets/temp/{reddit_id}/png/comment_{idx}.png",
) )
else: 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" path=f"assets/temp/{reddit_id}/png/comment_{idx}.png"
) )
except TimeoutError: except TimeoutError:

Loading…
Cancel
Save