Skip to content
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

Enable oauth2 support #248

Open
carloscuervo opened this issue Oct 9, 2024 · 6 comments
Open

Enable oauth2 support #248

carloscuervo opened this issue Oct 9, 2024 · 6 comments

Comments

@carloscuervo
Copy link

When you are using oauth2, to avoid issues with the anti-bot youtube's mechanism, you need to use cookies or oauth2 to authenticate with Youtube to get access for download videos.

I am using this plugin: https://github.com/coletdjnz/yt-dlp-youtube-oauth2

When using oauth2 yt-dlp force you to register your "device" (application) to authenticate using oath2.
The response of yt-dlp is:

xxxx@vmi2052980:/var/www/html$ [youtube+oauth2] oauth2: Initializing OAuth2 Authorization Flow
[youtube+oauth2] To give yt-dlp access to your account, go to https://www.google.com/device and enter code XXX-XXX-XXX

That response is blocked until you register that device so you PHP program is blocked until you realice that you have to register the application.

So, you would go to https://www.google.com/device and register your app.

It would be interesting that you can capture the response (and not block the yt-dlp processs) when yt-dlp indicate that you have to register your device.

The next yt-dlp executions don't require register again and you can use it.

@norkunas
Copy link
Owner

norkunas commented Oct 9, 2024

Contributions are welcome :) I'm not familiar yet how this blocks the flow.

@carloscuervo
Copy link
Author

I'm developing a web to convert youtube videos to mp3.

The method that I am using to convert a youtube video ($url) to mp3 is this:

$collection = $yt->download( Options::create() ->downloadPath($directorio) ->extractAudio(true) ->audioFormat('mp3') ->audioQuality('0') // best ->url($url) ->cacheDir( '/var/www/.cache') ->authenticate('oauth2','')

The first time when you are using oauth2 as authentication method, yt-dlp shows this response and keep waiting until you register the code:

xxxx@vmi2052980:/var/www/html$ [youtube+oauth2] oauth2: Initializing OAuth2 Authorization Flow
[youtube+oauth2] To give yt-dlp access to your account, go to https://www.google.com/device and enter code XXX-XXX-XXX

The process is waiting until you go to https://www.google.com/device and enter that code and login with the user's youtube account.

When you enter the code and register the device, yt-dlp process continues running and the process finish.

The workaround when using oauth2 will be:

  • Detect when yt-dlp is asking to register a device
  • Capture that code, return to the program but keeping the process wating until the device is registered.

I am not pretty sure if there is any way to automate this...

@norkunas
Copy link
Owner

I am not pretty sure if there is any way to automate this...

So I'm not sure that there is something to do here :)

It would be interesting that you can capture the response (and not block the yt-dlp processs) when yt-dlp indicate that you have to register your device.

You can do that via $yt->debug(function () { ... }); which allows to capture all the information

@mokhosh
Copy link

mokhosh commented Oct 23, 2024

@carloscuervo I'm currently playing with this nightly feature.

What I'm doing now is I run ytdlp on ssh once with oauth2, then the code will just pick it up.

But it would be nice to have a way of accessing that code via php.

@norkunas For reference this is what it looks like when you try to login with oauth2 first:

$ yt-dlp --username oauth --password '' https://www.youtube.com/watch?v=id
[youtube] oauth: Initializing authorization flow
[youtube] oauth: To give yt-dlp access to your account, go to  https://www.google.com/device  and enter code  XXX-YYY-ZZZZ

XXX-YYY-ZZZZ is basically all we need here. The rest is manual work.

@norkunas
Copy link
Owner

@mokhosh do you have any suggestions how could we make this work?

@mokhosh
Copy link

mokhosh commented Oct 24, 2024

Just thinking out loud, maybe in the same way we have debug which accepts a closure, we can have something like pendingOauth which accepts a closure and passes the [youtube] oauth line to the closure for the developer to decide what they wanna do with it.

Maybe @carloscuervo also has some input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants