Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
143 views
in Technique[技术] by (71.8m points)

python - 如何使用youtube-dl的--add-header选项?(How do I use youtube-dl's --add-header option?)

I'm trying to add a custom header using youtube-dl, a popular video downloader with command line interface.

(我正在尝试使用youtube-dl(带有命令行界面的流行视频下载器)添加自定义标头。)

I'm using PowerShell (or CMD) on Windows 10.

(我正在Windows 10上使用PowerShell(或CMD)。)

The official documentation says like the following but I can't seem to use it properly.

(官方文档如下所示,但我似乎无法正确使用它。)

--add-header FIELD:VALUE

(--add-header FIELD:VALUE)
Specify a custom HTTP header and its value, separated by a colon ':'.

(指定一个自定义HTTP标头及其值,以冒号“:”分隔。)

You can use this option multiple times

(您可以多次使用此选项)

I'm trying to add multiple headers for the request like:

(我正在尝试为请求添加多个标头,例如:)

"Accept-Encoding": "identity;q=1, *;q=0",
"Range": "bytes=6488064-",
"Referer": "https://avideosite.net/video/0123456",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36"

But when I tried something like

(但是当我尝试类似)

start youtube-dl --add-header "Accept-Encoding":"identity;q=1, *;q=0" --add-header "Range":"bytes=6488064-" --add-header "Referer":"https://avideosite.net/video/0123456" --add-header "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36" "http://11.22.333.444:8280/abcdefg=.mp4?st=97WbFiADB5Hla7Y-fZx58g&e=1560574126"

It doesn't work and throws an error like this:

(它不起作用并引发如下错误:)

Start-Process : A positional parameter cannot be found that accepts argument
'Accept-Encoding'.
At line:1 char:1
+ start youtube-dl --add-header "Accept-Encoding":"identity;q=1, *;q=0" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Start-Process], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand

What am I doing wrong?

(我究竟做错了什么?)

Also, is there a proper way to put it into Python script using youtube_dl library?

(另外,是否有使用youtube_dl库将其放入Python脚本的正确方法?)

  ask by user8491363 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

So my problem was not having youtube-dl.exe in my PATH, which prevented me from even starting youtube-dl.

(所以我的问题是我的PATH中没有youtube-dl.exe,这甚至阻止了我启动youtube-dl。)

So let me answer my own question about --add-header option.

(因此,让我回答关于--add-header选项的问题。)

About --add-header option, it should be something like foo:"bar" for each item.

(关于--add-header选项,每个项目应该类似于foo:"bar" 。)

For example, my original command from the question should be like:

(例如,问题的原始命令应为:)

$ youtube-dl --add-header Accept-Encoding:"identity;q=1, *;q=0" --add-header Range:"bytes=6488064-" --add-header Referer:"https://avideosite.net/video/0123456" --add-header User-Agent:"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36" http://11.22.333.444:8280/abcdefg=.mp4?st=97WbFiADB5Hla7Y-fZx58g&e=1560574126

Remember that if you have & (ampersand) character in the url like in my case, you'll have to wrap it with " ".

(请记住,如果像我的情况那样,URL中有 (&)字符,则必须用“”将其包装起来。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...