alexlaverty / python-reddit-youtube-bot

Automated Reddit Youtube Video Bot
https://www.youtube.com/channel/UCzIwW92D_rM5_yvWBsquSbw
75 stars 17 forks source link

Screenshots not working anymore #99

Open sebbourgeois opened 8 months ago

sebbourgeois commented 8 months ago

I suppose it's related, I had a UI update on Reddit yesterday, and since, the script is not able to retrieve the screenshots.

During the process, it says that downloading the screenshots is done :

Downloading screenshots of reddit posts...
Launching Headless Browser...
Login successful!
Downloading screenshots... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:54:34
Screenshots downloaded Successfully.

However, when creating the comments part, you can see this :

2023-12-08 11:00:52 INFO     Created Audio File : assets/work_dir/18czvs6/kcfxqsv.mp3
2023-12-08 11:00:52 INFO     Comment image not found : assets/work_dir/18czvs6/comment_kcfxqsv.png

Also, in the work_dir, you can see the mp3 files, but no png files : ls: cannot access '*.png': No such file or directory

sebbourgeois commented 8 months ago

@alexlaverty after checking a bit, it seems it's coming from the new UI that is being pushed slowly but surely to all Reddit accounts. It may not impact all the users yet.

alexlaverty commented 8 months ago

will try and have a look, i've noticed for a while now they've been serving both the old UI and new UI so will need to try and handle that situation, I've also started working on a rewrite of this repo, focusing on making the code tidier and better structured : https://github.com/alexlaverty/python-reddit-youtube-bot-2.0

current repo is messy and started to get a bit out of control and hard to maintain..

If you set headless mode to False it will launch the browser and can view it as it navigates : https://github.com/alexlaverty/python-reddit-youtube-bot/blob/main/comments/screenshot.py#L55

browser = p.chromium.launch(headless=False)
alexlaverty commented 8 months ago

can see you've posted similar issue for the elebumm repo :

https://github.com/elebumm/RedditVideoMakerBot/issues/1898

i was also checking over there to see how they're handling it, as one of the comments says they've redone the UI so that now there isn't a good way to use a CSS selector to screenshot just the comment.

alexlaverty commented 8 months ago

I've pushed a fix for the comment screenshots for the new Reddit UI Layout : https://github.com/alexlaverty/python-reddit-youtube-bot/commit/4211f02d78aaea1c12709800d06629323a03cd01

build for the commit succeeded and uploaded to the ttsvibelounge youtube channel : https://youtu.be/21bbYzGupxQ?si=UOcAi9ITXip82UI2

fix was a bit painful, basically when you view the comment you need to collapse the child comments first then you can screenshot just the comment, however some comments when you browse them are themselves collapsed.. so you need to expand the main comment and then collapse the child comments then you can screenshot the main comment.. had a lot of fun trying to figure that out lol

If the elebumm RedditVideoMakerBot repo is still suffering from this new layout comment screenshot issue might try raise a PR to their repo to fix the issue if they haven't already.

sebbourgeois commented 8 months ago

Thanks for the fix @alexlaverty I will give it a try ! Indeed, I had a talk with some persons on the RedditVideoBotMaker's discord, that new comment system looked like to be a pain in the a**, I'm glad you were able to figure it out 😄 As far as I know, they still face the issue.

I'll give a try to the v2 as well !

sebbourgeois commented 8 months ago

@alexlaverty so, just tried the fix for the screenshots, I have a new error message :

Downloading screenshots of reddit posts...
Launching Headless Browser...
Traceback (most recent call last):
  File "/home/sb/videos-creation/python-reddit-youtube-bot/app.py", line 440, in <module>
    process_submissions(submissions)
  File "/home/sb/videos-creation/python-reddit-youtube-bot/app.py", line 64, in process_submissions
    process_submission(submission)
  File "/home/sb/videos-creation/python-reddit-youtube-bot/app.py", line 118, in process_submission
    vid.create(
  File "/home/sb/videos-creation/python-reddit-youtube-bot/video_generation/video.py", line 500, in create
    download_screenshots_of_reddit_posts(
  File "/home/sb/videos-creation/python-reddit-youtube-bot/comments/screenshot.py", line 88, in download_screenshots_of_reddit_posts
    page.wait_for_selector('button[type="submit"]')
  File "/home/sb/.local/lib/python3.10/site-packages/playwright/sync_api/_generated.py", line 8251, in wait_for_selector
    self._sync(
  File "/home/sb/.local/lib/python3.10/site-packages/playwright/_impl/_sync_base.py", line 104, in _sync
    return task.result()
  File "/home/sb/.local/lib/python3.10/site-packages/playwright/_impl/_page.py", line 368, in wait_for_selector
    return await self._main_frame.wait_for_selector(**locals_to_params(locals()))
  File "/home/sb/.local/lib/python3.10/site-packages/playwright/_impl/_frame.py", line 322, in wait_for_selector
    await self._channel.send("waitForSelector", locals_to_params(locals()))
  File "/home/sb/.local/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 61, in send
    return await self._connection.wrap_api_call(
  File "/home/sb/.local/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 461, in wrap_api_call
    return await cb()
  File "/home/sb/.local/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 96, in inner_send
    result = next(iter(done)).result()
playwright._impl._api_types.TimeoutError: Timeout 30000ms exceeded.
=========================== logs ===========================
waiting for locator("button[type=\"submit\"]") to be visible
============================================================
alexlaverty commented 8 months ago

must be something to do with the login, relevant code is here : https://github.com/alexlaverty/python-reddit-youtube-bot/blob/c4c0217d7b6b6137f39b009e00c22a39234521fc/comments/screenshot.py#L77C1-L90

can you find this line in screenshot.py and change headless to be False :

browser = p.chromium.launch(headless=True)

then you'll see the browser when it pops up and should see it attempt to login, maybe there's a popup or something blocking the login attempt...

my TTSVibeLounge youtube channel has been running on a schedule now last couple days and has been producing videos again ok.

sebbourgeois commented 8 months ago

@alexlaverty I think it was some temporary issue from Reddit, I tried again without changing anything and it worked fine. Sorry for the false alarm !

Kamushy commented 7 months ago

collapse the child comments first th

any chance you can make that PR?