Monotirg / youtube-upload

Asynchronous uploading of videos to YouTube without utilizing YouTube APIv3 using Playwright
MIT License
18 stars 3 forks source link

Can't log in / use cookie #1

Closed alzyras closed 5 months ago

alzyras commented 5 months ago

Hello!

Lovely YouTube uploader, I've looked over the code a bit :)

I had trouble using it, however. It's not possible to login to youtube in playwright chrome to export cookies (browser automation login youtube block). I've also tried exporting them with Cookie-editor and converting to playwright format, but that didn't work. It accepted the format, but the session was not logged in when the script went to youtube.

I also hardcoded the user data dir of my chrome that I use, but I figured out playwright doesn't use those sessions / cookie info from there as it was not designed this way it seems.

Soo - how do you prepare the cookies for operation, where do you export them from?

Also - why are the user data dirs needed if playwright doesn't use the authentications / etc. from them, just profile attributes and assumedly plugins?

Thank you for your reply.

alzyras commented 5 months ago
with open(self.cookies_path, encoding="utf-8") as f:
        cookies = json.load(f)
        await self.context.add_cookies(cookies)

The cookies were not loaded. I added this to channel.py (function start()) and it works.

However it seems the usage of the script invalidates the session in the cookies (also in my other browser where I exported the cookies from).

Monotirg commented 5 months ago

Hi,

Thank you for your response. Yes, you are right. I forgot to add cookies to the context session. However, even though the code you provided afterwards works, it doesn't get validated by validate_cookies method. The updated version should look like this:

with open(self.cookies_path, encoding="utf-8") as f:
    self.yt_cookies = Cookies(cookies=json.loads(f.read()))
...
await self.context.add_cookies(self.yt_cookies.model_dump())

I will upload the new version to repository.