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
[options] Add authentication option netrc-cmd
#6682
Conversation
For ref: some of the disucussion is in #6676 |
Line 192 in 68be95b
if sum(map(bool, (opts.usenetrc, opts.netrc_cmd, opts.username))) > 1:
See #6676 (comment), but I am open to discussion |
From #6676 :
I though about doing that in the beginning, but it was more work and it mean every command would need to format their output like the netrc command. I can see the usefulness of being able to have the command be a nearly drop in replacement for the encrypted .netrc file. But the netrc library takes a path as argument, and that is surprisingly annoying to work around.
In the end, I think it is better to have a very simple format for the command output, and rather have people do the parsing in the command itself, something like
the |
Untested, but something like this should work: class stream_netrc(netrc.netrc):
def __init__(self, stream):
self.hosts = {}
self.macros = {}
self._parse('-', stream, False) Ref: https://github.com/python/cpython/blob/3.11/Lib/netrc.py#L67-L78
Agreed |
Oh well, that worked perfectly! |
put it in |
Sorry I didn't notify that I applied the changes suggested, so I don't know I you have seen it. |
c2d3bb8
to
af76cdc
Compare
Authored by: NDagestad
Authored by: NDagestad
Rebased on latest commits; is there something blocking for this to get merged ? |
In the future, please avoid force-pushing in the middle of review. You can just do a merge commit It will be reviewed when time permits |
ee280c7
to
7aeda6c
Compare
48525a6 is not fully tested coz Ive gtg. Once it is, and the doc is corrected, this can be merged. |
Authored by: NDagestad
Authored by: NDagestad
From my testing this works without problem. Maybe the example is not the most pertinent though, maybe replacing it with |
I agree that is easier to understand. PS: 2>devnul isnt even needed making it even simpler. |
Authored by: NDagestad
Authored by: NDagestad, pukkandan Closes yt-dlp#1706
This adds a new option to specify a command that will be ran by yt-dlp to get the username and password that an extractor needs.
For now I kept the logic of having the passord on the first line of the output, and the username on the second one, I'll change it if you have a specific format in mind you prefer.
I also updated the README, is there another place where documentation should be updated ?
As requested in the issue I opened, I also added the exclusion between the various credential related options.
The exclusion mechanism seems a bit clunky to me, but I can't think of another way that wouldn't be a lot of different comparisons. Maybe there is some python magic I don't know about that makes it possible to do an exclusive comparaison of 3 boolean variables 🤔
Fixes #1706
Template
Before submitting a pull request make sure you have:
In order to be accepted and merged into yt-dlp each piece of code must be in public domain or released under Unlicense. Check all of the following options that apply:
What is the purpose of your pull request?
🤖 Generated by Copilot at 11d2237
Summary
🆕📝🛠️
This pull request adds a new feature to
yt-dlp
that allows users to provide credentials for an extractor using a custom shell command. It introduces a new option--netrc-cmd
and updates the relevant code and documentation to support this feature.Walkthrough
--netrc-cmd
to allow the user to provide credentials for an extractor using a custom shell command (link, link, link, link)--username
and--password
,--netrc-cmd
, or--netrc
inyt_dlp/__init__.py
(link)--netrc-cmd
option to the extractor classes inyt_dlp/__init__.py
(link)subprocess
module to execute the shell command defined by the user inyt_dlp/extractor/common.py
(link, link)--netrc-cmd
option inyt_dlp/extractor/common.py
(link)_get_netrc_cmd_info
to parse the output of the shell command and return the username and password inyt_dlp/extractor/common.py
(link)_get_login_info
method to try the--netrc-cmd
option before the--netrc
option if the user did not provide the username and password manually inyt_dlp/extractor/common.py
(link)