Update screenshot_downloader.py
Fixes bug where the application always fails on the skipping translation step and fails to take screenshots
Description
Solves the bug in which the application fails to take screenshots and outputs an error message on the skipping translation step.
Dependencies: None
Issue Fixes
Solves the screenshot bug
Checklist:
- [ y] I am pushing changes to the develop branch
- [ dunno] I am using the recommended development environment
- [ y] I have performed a self-review of my own code
- [ y] I have commented my code, particularly in hard-to-understand areas
- [ y] I have formatted and linted my code using python-black and pylint
- [ y] I have cleaned up unnecessary files
- [ y] My changes generate no new warnings
- [ y] My changes follow the existing code-style
- [ y] My changes are relevant to the project
Any other information (e.g how to test the changes)
Test with different settings if you want, in my experience it has never failed though (Not all code is perfect I'm not saying mine is).
Edit: sometimes the app will throw an error about waiting for the h1 slot="title" locator I believe this is to do with anti bot measures and I can usually fix it with a vpn.
Edit to this comment: As a matter of fact every error received while using this script can be fixed by refreshing your vpn (obviously reddit doesn't like bots ;) )
I'll try to test it soon, looks good to me though
Hey i tested this on arch linux and this pr doesnt work (for me at least).
Heres my logs
██████╗ ███████╗██████╗ ██████╗ ██╗████████╗ ██╗ ██╗██╗██████╗ ███████╗ ██████╗ ███╗ ███╗ █████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔════╝██╔══██╗██╔══██╗██║╚══██╔══╝ ██║ ██║██║██╔══██╗██╔════╝██╔═══██╗ ████╗ ████║██╔══██╗██║ ██╔╝██╔════╝██╔══██╗
██████╔╝█████╗ ██║ ██║██║ ██║██║ ██║ ██║ ██║██║██║ ██║█████╗ ██║ ██║ ██╔████╔██║███████║█████╔╝ █████╗ ██████╔╝
██╔══██╗██╔══╝ ██║ ██║██║ ██║██║ ██║ ╚██╗ ██╔╝██║██║ ██║██╔══╝ ██║ ██║ ██║╚██╔╝██║██╔══██║██╔═██╗ ██╔══╝ ██╔══██╗
██║ ██║███████╗██████╔╝██████╔╝██║ ██║ ╚████╔╝ ██║██████╔╝███████╗╚██████╔╝ ██║ ╚═╝ ██║██║ ██║██║ ██╗███████╗██║ ██║
╚═╝ ╚═╝╚══════╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝╚═════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
Thanks for using this tool! Feel free to contribute to this project on GitHub! If you have any questions, feel free to join my Discord server or submit a GitHub issue. You can find solutions to
many common problems in the documentation: https://reddit-video-maker-bot.netlify.app/
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ You are using the newest version (3.3.0) of the bot │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
###############################
# #
# Checking TOML configuration #
# #
###############################
If you see any prompts, that means that you have unset/incorrectly set variables, please input the correct values.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ on the 1st iteration of 10 │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Logging into Reddit.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Getting subreddit threads... │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Using subreddit: r/AmItheAsshole from TOML config
This post was pinned by moderators. Skipping...
Video will be: AITA for offering cash instead of my labor for a wedding gift? 👍
Thread url is: https://new.reddit.com//r/AmItheAsshole/comments/1fmtyw1/aita_for_offering_cash_instead_of_my_labor_for_a/ 👍
Thread has 4543 upvotes
Thread has a upvote ratio of 99.0%
Thread has 348 comments
Received subreddit threads Successfully.
Thread ID is 1fmtyw1
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Saving Text to MP3 files... │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Saved Text to MP3 files successfully.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Downloading screenshots of reddit posts... │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Launching Headless Browser...
Logging in to Reddit...
Skipping translation...
Something went wrong!
Something went wrong with making the screenshots! Do you want to skip the post? (y/n) Do you want the error traceback for debugging purposes? (y/n)╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Sorry, something went wrong with this version! Try again, and feel free to report this issue at GitHub or the Discord community. │
│ Version: 3.3.0 │
│ Error: Locator.bounding_box: Timeout 30000ms exceeded. │
│ Call log: │
│ waiting for locator("[data-test-id=\"post-content\"]") │
│ │
│ Config: {'allow_nsfw': False, 'theme': 'transparent', 'times_to_run': 10, 'opacity': 0.5, 'storymode': True, 'storymodemethod': 0, 'storymode_max_length': 5000, 'resolution_w': 1080, │
│ 'resolution_h': 1920, 'zoom': 0.7, 'channel_name': 'Reddit Tales', 'background': {'background_video': 'minecraft', 'background_audio': '', 'background_audio_volume': 0.0, 'enable_extra_audio': │
│ False, 'background_thumbnail': False, 'background_thumbnail_font_family': 'arial', 'background_thumbnail_font_size': 96, 'background_thumbnail_font_color': '255,255,255'}, 'tts': │
│ {'voice_choice': 'streamlabspolly', 'tiktok_voice': 'en_us_001', 'tiktok_sessionid': 'REDACTED', 'python_voice': '1', 'py_voice_num': '2', 'silence_duration': 0.6, 'no_emojis': False, │
│ 'random_voice': False, 'elevenlabs_voice_name': 'Bella', 'elevenlabs_api_key': 'REDACTED', 'aws_polly_voice': '', 'streamlabs_polly_voice': 'Matthew'}} │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Traceback (most recent call last):
File "/home/lain/RedditVideoMakerBot/main.py", line 131, in <module>
raise err
File "/home/lain/RedditVideoMakerBot/main.py", line 113, in <module>
run_many(config["settings"]["times_to_run"])
File "/home/lain/RedditVideoMakerBot/main.py", line 68, in run_many
main()
File "/home/lain/RedditVideoMakerBot/main.py", line 52, in main
get_screenshots_of_reddit_posts(reddit_object, number_of_comments)
File "/home/lain/RedditVideoMakerBot/video_creation/screenshot_downloader.py", line 203, in get_screenshots_of_reddit_posts
raise e
File "/home/lain/RedditVideoMakerBot/video_creation/screenshot_downloader.py", line 180, in get_screenshots_of_reddit_posts
location = page.locator('[data-test-id="post-content"]').bounding_box()
File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/sync_api/_generated.py", line 14782, in bounding_box
self._sync(self._impl_obj.bounding_box(timeout=timeout))
File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_sync_base.py", line 115, in _sync
return task.result()
File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_locator.py", line 127, in bounding_box
return await self._with_element(
File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_locator.py", line 108, in _with_element
handle = await self.element_handle(timeout=timeout)
File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_locator.py", line 311, in element_handle
handle = await self._frame.wait_for_selector(
File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_frame.py", line 323, in wait_for_selector
await self._channel.send("waitForSelector", locals_to_params(locals()))
File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 59, in send
return await self._connection.wrap_api_call(
File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 514, in wrap_api_call
raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None
playwright._impl._errors.TimeoutError: Locator.bounding_box: Timeout 30000ms exceeded.
Important!
I did open this with headless False to see if it couldn't login like many people suggested; it logged in fine and went to the subreddit post fine as well.
Hey i tested this on arch linux and this pr doesnt work (for me at least).
Heres my logs
██████╗ ███████╗██████╗ ██████╗ ██╗████████╗ ██╗ ██╗██╗██████╗ ███████╗ ██████╗ ███╗ ███╗ █████╗ ██╗ ██╗███████╗██████╗ ██╔══██╗██╔════╝██╔══██╗██╔══██╗██║╚══██╔══╝ ██║ ██║██║██╔══██╗██╔════╝██╔═══██╗ ████╗ ████║██╔══██╗██║ ██╔╝██╔════╝██╔══██╗ ██████╔╝█████╗ ██║ ██║██║ ██║██║ ██║ ██║ ██║██║██║ ██║█████╗ ██║ ██║ ██╔████╔██║███████║█████╔╝ █████╗ ██████╔╝ ██╔══██╗██╔══╝ ██║ ██║██║ ██║██║ ██║ ╚██╗ ██╔╝██║██║ ██║██╔══╝ ██║ ██║ ██║╚██╔╝██║██╔══██║██╔═██╗ ██╔══╝ ██╔══██╗ ██║ ██║███████╗██████╔╝██████╔╝██║ ██║ ╚████╔╝ ██║██████╔╝███████╗╚██████╔╝ ██║ ╚═╝ ██║██║ ██║██║ ██╗███████╗██║ ██║ ╚═╝ ╚═╝╚══════╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝╚═════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ Thanks for using this tool! Feel free to contribute to this project on GitHub! If you have any questions, feel free to join my Discord server or submit a GitHub issue. You can find solutions to many common problems in the documentation: https://reddit-video-maker-bot.netlify.app/ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ You are using the newest version (3.3.0) of the bot │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ############################### # # # Checking TOML configuration # # # ############################### If you see any prompts, that means that you have unset/incorrectly set variables, please input the correct values. ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ on the 1st iteration of 10 │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ Logging into Reddit. ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ Getting subreddit threads... │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ Using subreddit: r/AmItheAsshole from TOML config This post was pinned by moderators. Skipping... Video will be: AITA for offering cash instead of my labor for a wedding gift? 👍 Thread url is: https://new.reddit.com//r/AmItheAsshole/comments/1fmtyw1/aita_for_offering_cash_instead_of_my_labor_for_a/ 👍 Thread has 4543 upvotes Thread has a upvote ratio of 99.0% Thread has 348 comments Received subreddit threads Successfully. Thread ID is 1fmtyw1 ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ Saving Text to MP3 files... │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ Saved Text to MP3 files successfully. ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ Downloading screenshots of reddit posts... │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ Launching Headless Browser... Logging in to Reddit... Skipping translation... Something went wrong! Something went wrong with making the screenshots! Do you want to skip the post? (y/n) Do you want the error traceback for debugging purposes? (y/n)╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ Sorry, something went wrong with this version! Try again, and feel free to report this issue at GitHub or the Discord community. │ │ Version: 3.3.0 │ │ Error: Locator.bounding_box: Timeout 30000ms exceeded. │ │ Call log: │ │ waiting for locator("[data-test-id=\"post-content\"]") │ │ │ │ Config: {'allow_nsfw': False, 'theme': 'transparent', 'times_to_run': 10, 'opacity': 0.5, 'storymode': True, 'storymodemethod': 0, 'storymode_max_length': 5000, 'resolution_w': 1080, │ │ 'resolution_h': 1920, 'zoom': 0.7, 'channel_name': 'Reddit Tales', 'background': {'background_video': 'minecraft', 'background_audio': '', 'background_audio_volume': 0.0, 'enable_extra_audio': │ │ False, 'background_thumbnail': False, 'background_thumbnail_font_family': 'arial', 'background_thumbnail_font_size': 96, 'background_thumbnail_font_color': '255,255,255'}, 'tts': │ │ {'voice_choice': 'streamlabspolly', 'tiktok_voice': 'en_us_001', 'tiktok_sessionid': 'REDACTED', 'python_voice': '1', 'py_voice_num': '2', 'silence_duration': 0.6, 'no_emojis': False, │ │ 'random_voice': False, 'elevenlabs_voice_name': 'Bella', 'elevenlabs_api_key': 'REDACTED', 'aws_polly_voice': '', 'streamlabs_polly_voice': 'Matthew'}} │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ Traceback (most recent call last): File "/home/lain/RedditVideoMakerBot/main.py", line 131, in <module> raise err File "/home/lain/RedditVideoMakerBot/main.py", line 113, in <module> run_many(config["settings"]["times_to_run"]) File "/home/lain/RedditVideoMakerBot/main.py", line 68, in run_many main() File "/home/lain/RedditVideoMakerBot/main.py", line 52, in main get_screenshots_of_reddit_posts(reddit_object, number_of_comments) File "/home/lain/RedditVideoMakerBot/video_creation/screenshot_downloader.py", line 203, in get_screenshots_of_reddit_posts raise e File "/home/lain/RedditVideoMakerBot/video_creation/screenshot_downloader.py", line 180, in get_screenshots_of_reddit_posts location = page.locator('[data-test-id="post-content"]').bounding_box() File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/sync_api/_generated.py", line 14782, in bounding_box self._sync(self._impl_obj.bounding_box(timeout=timeout)) File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_sync_base.py", line 115, in _sync return task.result() File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_locator.py", line 127, in bounding_box return await self._with_element( File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_locator.py", line 108, in _with_element handle = await self.element_handle(timeout=timeout) File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_locator.py", line 311, in element_handle handle = await self._frame.wait_for_selector( File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_frame.py", line 323, in wait_for_selector await self._channel.send("waitForSelector", locals_to_params(locals())) File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 59, in send return await self._connection.wrap_api_call( File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 514, in wrap_api_call raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None playwright._impl._errors.TimeoutError: Locator.bounding_box: Timeout 30000ms exceeded.Important!
I did open this with headless False to see if it couldn't login like many people suggested; it logged in fine and went to the subreddit post fine as well.
This seems to be unrelated, does it work using main?
This seems to be unrelated, does it work using main?
It does not.
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Sorry, something went wrong with this version! Try again, and feel free to report this issue at GitHub or the Discord community. │
│ Version: 3.3.0 │
│ Error: Locator.bounding_box: Timeout 30000ms exceeded. │
│ Call log: │
│ waiting for locator("[data-test-id=\"post-content\"]") │
│ │
│ Config: {'allow_nsfw': False, 'theme': 'transparent', 'times_to_run': 10, 'opacity': 0.5, 'storymode': False, 'storymodemethod': 0, 'storymode_max_length': 5000, 'resolution_w': 1080, 'resolution_h': 1920, 'zoom': 0.7, │
│ 'channel_name': 'Reddit Tales', 'background': {'background_video': 'minecraft', 'background_audio': '', 'background_audio_volume': 0.0, 'enable_extra_audio': False, 'background_thumbnail': False, 'background_thumbnail_font_family': │
│ 'arial', 'background_thumbnail_font_size': 96, 'background_thumbnail_font_color': '255,255,255'}, 'tts': {'voice_choice': 'streamlabspolly', 'tiktok_voice': 'en_us_001', 'tiktok_sessionid': 'REDACTED', 'python_voice': '1', │
│ 'py_voice_num': '2', 'silence_duration': 0.6, 'no_emojis': False, 'random_voice': False, 'elevenlabs_voice_name': 'Bella', 'elevenlabs_api_key': 'REDACTED', 'aws_polly_voice': '', 'streamlabs_polly_voice': 'Matthew'}} │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Traceback (most recent call last):
File "/home/lain/RedditVideoMakerBot/main.py", line 131, in <module>
raise err
File "/home/lain/RedditVideoMakerBot/main.py", line 113, in <module>
run_many(config["settings"]["times_to_run"])
File "/home/lain/RedditVideoMakerBot/main.py", line 68, in run_many
main()
File "/home/lain/RedditVideoMakerBot/main.py", line 52, in main
get_screenshots_of_reddit_posts(reddit_object, number_of_comments)
File "/home/lain/RedditVideoMakerBot/video_creation/screenshot_downloader.py", line 203, in get_screenshots_of_reddit_posts
raise e
File "/home/lain/RedditVideoMakerBot/video_creation/screenshot_downloader.py", line 180, in get_screenshots_of_reddit_posts
location = page.locator('[data-test-id="post-content"]').bounding_box()
File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/sync_api/_generated.py", line 14782, in bounding_box
self._sync(self._impl_obj.bounding_box(timeout=timeout))
File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_sync_base.py", line 115, in _sync
return task.result()
File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_locator.py", line 127, in bounding_box
return await self._with_element(
File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_locator.py", line 108, in _with_element
handle = await self.element_handle(timeout=timeout)
File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_locator.py", line 311, in element_handle
handle = await self._frame.wait_for_selector(
File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_frame.py", line 323, in wait_for_selector
await self._channel.send("waitForSelector", locals_to_params(locals()))
File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 59, in send
return await self._connection.wrap_api_call(
File "/home/lain/RedditVideoMakerBot/.venv/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 514, in wrap_api_call
raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None
playwright._impl._errors.TimeoutError: Locator.bounding_box: Timeout 30000ms exceeded.
Call log:
waiting for locator("[data-test-id=\"post-content\"]")
This works for me for some of the subreddits. Most of them still crashes. Reddit has updated its dom structure, i think that is the main reason why script fails.
This works for me for some of the subreddits. Most of them still crashes. Reddit has updated its dom structure, i think that is the main reason why script fails.
This needs to use asyncpraw for getting comments and titles. It will always fail / be a headache to fix otherwise. Using async praw would also remove the need for a headless browser driver.
ı try on windows stuck %67 and give me same log
This don't work in zoom mode.
Hi all I have been made aware of some bugs with zoom I'll update my pull request soon to fix these as it's a pretty simple fix (There is another bug with making multiple videos at the same time I believe I know how to fix it but I might do it in a different pull request because I believe it'll be quite complicated and slow down the process of this request being added)
