[cli] youtube-dl - Youtube 影片下載工具
過時內容
youtube-dl 已停止維護(abandoned),官方 repo 長期無更新。請改用其繼任工具 yt-dlp,yt-dlp 是 youtube-dl 的活躍分支,功能更多且持續維護。
安裝方式:brew install yt-dlp,指令與 youtube-dl 幾乎相同,只需將 youtube-dl 替換為 yt-dlp 即可。
youtube-dl @ Github
TL;SC
# 下載最好的畫質和音質並合併成一個檔案
$ youtube-dl https://www.youtube.com/watch?v=foo -f bestvideo+bestaudio
安裝
# 透過 brew 安裝
$ brew install youtube-dl
使用
# 最基本使用
$ youtube-dl [OPTIONS] URL [URL...]
指定下載的檔案格式
# --list-formats, -F 顯示可下載的影片格式
# -f 指定
$ youtube-dl https://www.youtube.com/watch?v=foo --list-formats # 列出所有支援格式
# 下載最好的畫質和音質並合併成一個檔案
$ youtube-dl https://www.youtube.com/watch?v=foo -f bestvideo+bestaudio
$ youtube-dl https://www.youtube.com/watch?v=foo -f bestvideo,bestaudio --merge-output-format mp4
$ youtube-dl https://www.youtube.com/watch?v=foo -f mp4 # 指定下載格式
$ youtube-dl https://www.youtube.com/watch?v=foo -f best # 指定最佳品質(best)、畫質(bestvideo)、音質(bestaudio)
Q&A
下載需要登入才能檢視的私人影片
Youtube 私人影片
login to youtube not working #21313 @ Github Issue
- 下載 Chrome Extension Get cookies.txt 後
- 使用有權限觀看影片的帳號登入 Youtube,並使用該 Chrome Extension 把 Cookie 抓下來
- 使用 youtube-dl 下載影片是加上
--cookies=YT-cookies.txt的 option,例如:
youtube-dl https://www.youtube.com/watch?v=X-rss1234 -f best --cookies=youtube.com_cookies.txt