youtube-dl如何下载需要用户身份验证和2FA的视频?[关闭]


4

当我尝试下载我的私人视频时,我得到以下信息:

youtube-dl https://youtu.be/Q-xxxx-xxxx
[youtube] Q-xxxx-xxxx: Downloading webpage
[youtube] Q-xxxx-xxxx: Downloading video info webpage
WARNING: Unable to extract video title
ERROR: This video is unavailable.

当我尝试使用用户名和密码时,它在我的2FA上失败。

youtube-dl --username=me@gmail.com  https://youtu.be/Q-xxxx-xxxx
Type account password and press [Return]: 
[youtube] Downloading login page
[youtube] Looking up account info
[youtube] Logging in
Type 2-step verification code and press [Return]: 
[youtube] Submitting TFA code
WARNING: Unable to submit TFA code: HTTP Error 400: Bad Request
[youtube] Q-xxxx-xxxx: Downloading webpage
[youtube] Q-xxxx-xxxx: Downloading video info webpage
WARNING: Unable to extract video title
ERROR: This video is unavailable.

如果我尝试--cookies在Chrome中与EditThisCookie 一起使用导出,则它也会失败。我通过转到Chrome中的视频并将cookie复制到文件中来进行导出。

youtube-dl --cookies=cookies.txt  https://youtu.be/Q-xxxx-xxxx
Traceback (most recent call last):
  File "/usr/bin/youtube-dl", line 11, in <module>
    load_entry_point('youtube-dl==2018.6.14', 'console_scripts', 'youtube-dl')()
  File "/usr/lib/python3.6/site-packages/youtube_dl/__init__.py", line 472, in main
    _real_main(argv)
  File "/usr/lib/python3.6/site-packages/youtube_dl/__init__.py", line 439, in _real_main
    with YoutubeDL(ydl_opts) as ydl:
  File "/usr/lib/python3.6/site-packages/youtube_dl/YoutubeDL.py", line 414, in __init__
    self._setup_opener()
  File "/usr/lib/python3.6/site-packages/youtube_dl/YoutubeDL.py", line 2303, in _setup_opener
    self.cookiejar.load()
  File "/usr/lib/python3.6/http/cookiejar.py", line 1784, in load
    self._really_load(f, filename, ignore_discard, ignore_expires)
  File "/usr/lib/python3.6/http/cookiejar.py", line 2007, in _really_load
    filename)
http.cookiejar.LoadError: 'cookies.txt' does not look like a Netscape format cookies fil

如何使用youtube-dl下载我的私人视频?

编辑:

我也尝试了应用密码,但是由于某种原因,这对我也失败了:

youtube-dl --username=me@gmail.com --password=xxxxxxxxx youtu.be/Q-xxxxxxxx
[youtube] Downloading login page
[youtube] Looking up account info
[youtube] Logging in
WARNING: Unable to login: Invalid password
[youtube] Q-xxxxxx: Downloading webpage
[youtube] Q-xxxxxx: Downloading video info webpage
WARNING: Unable to extract video title
ERROR: This video is unavailable.

Answers:


7

我可以使用该--cookies路线下载私人视频。我必须首先将cookie格式化为Netscape格式,这是EditThisCookie中的一个选项。请记住,您不仅需要https://youtube.com的cookie,还需要https://accounts.google.com的cookie 。您必须使用EditThisCookie Chrome插件手动执行此操作。

然后,我需要使用修复用EditThisCookie生成的cookie的格式curl。类似于:curl -b oldcookiefile.txt --cookie-jar newcookiefile.txt 'https://youtube.com'

--cookies标志然后可以与youtube-dl一起使用,以下载私人视频。

我还创建了一个博客文章,详细描述了我学到的东西。


2
使用“ cookies.txt” chrome扩展程序,它更容易:-) chrome.google.com/webstore/detail/cookiestxt/…–
sekmo

太棒了,谢谢戴夫。我遵循了另一条评论,并使用了“ cookies.txt”。转到youtube.com,点击cookie.txt的按钮并全部保存。它们仅适用于youtube.com。随后是您博客文章的其余部分。
HankCa '18
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.