-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Cookies from browser #29201
base: master
Are you sure you want to change the base?
Cookies from browser #29201
Conversation
I have a question, does |
@nao20010128nao yes, X means I tried downloading a video that required cookies first without having the browser installed to check that no cookies are found, then again with the browser installed but not logged in (so cookies are found but the video does not download) then again once logged in. |
@mbway Wow, that's great. Great PR I've ever seen on youtube-dl repo. |
thanks :) I'm glad you like it |
Amazing PR; I have a few suggestions:
I think it is better to give the user full control over the path and profile. One way to do this could be a syntax like
There is
AES in CBC mode is already implemented. See
This seems to be the correct approach since the above mentioned pycryptodome dependency is handled similarly Hopefully I was of some help to you |
pycryptodome indeed sounds like the best option even if only for its Python 2.7 and 3.5+ support. |
@pukkandan So long as a browser behaves like the browser you name, you can pass the profile path of a different browser. You can use this to extract cookies from the beta or dev channels of chrome and edge so I removed those as specific options. For example you can do Of course there was an exception to this. Opera doesn't seem to have profiles at all (unlike the other browsers, I added support for Vivaldi, it was the next on my list of browsers I would support so I went ahead and added it. I've only tested it on Linux. The default behaviour is to take the most recently written to profile rather than having a default profile because Firefox seems to name profiles with random directory names like I found that
I added a small wrapper around the YoutubeDL object to make it act like a logger. I think that's the cleanest way to deal with it. Unfortunately as I was making these changes, something changed with youtube so I no longer need to provide cookies to download the video I was testing with. Hopefully |
Cookies are essential both for downloading private playlists on youtube and in general for other services with paid content. So your PR is incredibly useful even if the age-gate is fully bypassable |
before this gets merged I would like to have a go at adding Safari support as well. Safari seems to do things differently (not sqlite) but others have reverse engineered the format so it should be possible to parse |
I have added support for Safari which I think means that this feature should support 99% of browsers now. The I found two files:
I can't find anything online about the |
I made the changes necessary to hopefully pass the checks. It's much messier maintaining compatibility with ancient python versions. I can't even easily get hold of these versions to check, but I think the tests should pass now, although for quite a few of the python versions the cookies tests will be skipped unless pycryptodome is available. The requirements are now:
|
Using a venv you can install whatever Python version you want. If PyPi haven't deleted the ancient module versions it should work that way, too. |
@rautamiekka yeah, so I normally use the venv module, but that copies the python interpreter it's called with, so I installed virtualenv and tried
I also tried conda
then I gave up. I'll see what the CI says and fix things if necessary |
Yeah, according to https://anaconda.org/conda-forge/python/files?version=3.4.5 there's nothing between 2.7.x and 3.4.x (and PyPi doesn't seem to have Python as a package), so 3.4.x is indeed the earliest beyond compiling 3.3.x: https://www.python.org/downloads/release/python-336/. |
b5f1958
to
0b87e6e
Compare
) * also adds `--no-cookies-from-browser` Original PR: ytdl-org/youtube-dl#29201 Authored by: mbway
this feature is now merged into yt-dlp: yt-dlp/yt-dlp#488 so head over there if you want to use it. I will back-port the improvements I made for that pull request, although I don't expect this one to be merged any time soon as it's is already on page 3 of pull requests |
edit: for people reading this. The other side of this conversation was deleted by the author. For context, their original comment was:
No offence, but your comments seem misguided.
On every platform I have tested on, the python interpreter is compiled with sqlite support. It is possible on source-based Linux distributions such as Gentoo to compile without sqlite support (or if you compile from source manually on any platform of course) (see yt-dlp/yt-dlp#544) but that can be handled and I will backport this workaround.
That's exactly what this feature aims to improve upon. The user can simple point youtube-dl at their browser of choice. From a usability perspective it is less hassle even than OAuth because the user does not have to authenticate and give access to youtube-dl, so no user interaction is required |
We have a difference of opinion around priorities (sqlite support, accessing browser data, non-youtube support etc). I'm not going to argue. I mentioned that cookies and OAuth serve different purposes. I probably should have been clearer that I'm not against youtube-dl using OAuth (not that my opinion has any weight here anyway, I'm not a youtube-dl maintainer). Rather than opening an issue you commented on this pull request saying It looks like your project uses an API designed for smart TVs, so I stand by my statement that video sites do not sanction use of internal APIs for the purposes of user downloads. |
It won't.
Yes, without authorization from google, which is not possible with OAuth |
first point: see yt-dlp/yt-dlp#544 which I linked to earlier. There is a fix for that problem: yt-dlp/yt-dlp#554. Sqlite support is not required unless you want to use the feature ( Second point: google can revoke an API key. They cannot so easily mitigate use of cookies since using them presents identically to how a user accessing the site presents |
edit: for context, the original question was in two parts, this is the second part
I'm not sure if we are having a good-faith conversation here. Your second point is a valid question though so I'll answer it: It comes down to how many targets there are. Google can't identify every user who has used their cookies to give to youtube-dl, so it's not an issue. Alternatively (the normal option) a single key could be generated for the project (youtube-dl) and each user would share the same API key. This would be the single point of failure which could be revoked. |
the fix would not propagate immediately to users and using a central key may have different legal implications than providing a tool for users to user their own cookies/keys. This is getting off-topic for this pull request. If you want to discuss OAuth further please open an issue for it. |
this pull request should now be ready to merge whenever a maintainer has the time to look at it. I'm able to use it on my machine and the tests pass under python 3.9 |
…the MacOS keyring password
…t-dlp#488) * also adds `--no-cookies-from-browser` Original PR: ytdl-org/youtube-dl#29201 Authored by: mbway
^ I assume that downloading as a logged in Youtube/Google user rather than an anonymous user will give you the "throttle penalty" much less likely. So making cookies as user friendly as possible should be a high priority. Hence this PR expedited. Whats stopping this from being merged? |
@mbway some more questions:
|
Assuming someone wants to translate the whole thing into C, it would work... |
Before submitting a pull request make sure you have:
In order to be accepted and merged into youtube-dl each piece of code must be in public domain or released under Unlicense. Check one of the following options:
What is the purpose of your pull request?
I have added a new command line option:
--cookies-from-browser <browser_name>
which uses cookies directly extracted from an installed browser rather than reading from a cookies file provided by the user for several reasons:--cookies
option is not very easy for end users because it requires them to find and use a browser extension that saves to just the right format that youtube_dl understands--cookies
argument is a bit of a compromise as I'm sure that in the vast majority of cases users are using un-edited cookies directly from their browsers anywayThe
--cookies-from-browser
option will look in the default user data location for the given browser on the current platform. Multiple browser profiles may exist so I have chosen to read from the profile that was most recently written to.Initially I only supported Firefox on Linux (which does not encrypt cookies), and the scope grew from there. I reverse engineered the chromium encryption mechanisms by reading the source code and referring to a few other projects which also aim to decrypt chromium cookies, though I think this one of the most comprehensive implementations.
This pull request is still a bit 'in progress' as I'm not sure how to handle a few things:I think there should be at least some messages printed but youtube_dl doesn't seem to use a standard logging library so I'm just printing to stdout for nowSorted nowit looks like youtube_dl has no third party dependencies so this feature may not be accepted because it relies on two third party libraries. This could be avoided in theory by re-implementing AES in CBC and GCM modes, and implementing all the keyring interfaces (Gnome keyring, KWallet, OSX keyring etc). For now I've wrapped the third party imports in try/except so users can install the additional libraries if they want to use--cookies-from-browser
there is also the complication that thekeyring
package is not required at all on windows and is optional on OSX. Thecryptography
package is always required however.the cryptography package is dropping support for python 2:CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in the next release.
pycryptodome
for AES-GCM (Windows) but no external dependencies for other cryptographic operations.keyring
required on Linux only.Tested browsers and platforms
Tested mostly with python 3.9 but I did try 2.7/Linux/Firefox and 2.7/Linux/Chromium