-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix screenshot downloader #2326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the screenshot downloader to use custom Shreddit components, adds logic to ensure comment content is visible before capturing, and adjusts zoom/clip calculations.
- Swapped raw CSS selectors (
[data-test-id]
,#t1_…
) forshreddit-post
andshreddit-comment
tags - Introduced retry loop to reveal hidden comment elements before screenshotting
- Updated scroll, zoom, and bounding box logic to use the new
target
selector
Comments suppressed due to low confidence (2)
video_creation/screenshot_downloader.py:180
- [nitpick] The variable name
location
is a dictionary of clipping coordinates; consider renaming it to something likebbox
orclip_box
for clarity.
location = page.locator('shreddit-post').bounding_box()
video_creation/screenshot_downloader.py:247
- [nitpick] The inline comment includes Chinese (
或 'inline'
), which may be unclear to some developers; consider translating or clarifying the intended alternative behavior.
element.style.display = 'block'; // 或 'inline'
visible = page.locator(target).is_visible() | ||
|
||
if not visible: | ||
class ElementVisible(Exception):pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defining a custom exception inside the try block for control flow can be confusing; consider using a simple flag or breaking out of the loop instead.
Copilot uses AI. Check for mistakes.
visible = page.locator(target).is_visible() | ||
if visible: | ||
raise ElementVisible | ||
target = f'shreddit-comment[thingid="t1_{comment["comment_id"]}"] div#t1_{comment["comment_id"]}-comment-rtjson-content div#-post-rtjson-content' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The selector div#-post-rtjson-content
looks like it’s missing the dynamic prefix; it should include the comment ID (e.g., div#t1_{comment_id}-post-rtjson-content
).
target = f'shreddit-comment[thingid="t1_{comment["comment_id"]}"] div#t1_{comment["comment_id"]}-comment-rtjson-content div#-post-rtjson-content' | |
target = f'shreddit-comment[thingid="t1_{comment["comment_id"]}"] div#t1_{comment["comment_id"]}-comment-rtjson-content div#t1_{comment["comment_id"]}-post-rtjson-content' |
Copilot uses AI. Check for mistakes.
if not visible: | ||
class ElementVisible(Exception):pass | ||
try: | ||
for _ in range(30): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Polling every second for up to 30 seconds may slow down overall execution; consider using Playwright’s page.wait_for_selector(target, timeout=30000)
instead.
for _ in range(30): | |
page.evaluate(""" | |
(target) => { | |
const element = document.querySelector(target); | |
if (element) { | |
element.style.display = 'block'; // 或 'inline' | |
element.style.visibility = 'visible'; | |
} | |
} | |
""", target) | |
page.wait_for_selector(target, timeout=30000) | |
target = f'shreddit-comment[thingid="t1_{comment["comment_id"]}"] div#t1_{comment["comment_id"]}-comment-rtjson-content div#-post-rtjson-content' | |
visible = page.locator(target).is_visible() | |
if not visible: |
Copilot uses AI. Check for mistakes.
Description
Issue Fixes
None
Checklist:
Any other information (e.g how to test the changes)
None