youtube-dl 下載 YouTube 私人影片

2020/11/16:GITHUB 重新上架 YOUTUBE-DL
2020/10/24:RIAA 向 GITHUB 提出 DMCA -目前 YOUTUBE-DL 已從 GITHUB 移除


最近因為需要下載自己 YouTube 上面的高畫質影片,可是 Youtube Studio 只能下載 720p 所以就研究了一下

首先需要先準備 Cookie 檔案

使用 Chrome cookie.txt,打開 Youtube 複製自己的 Netscape format cookies,儲存成檔案 cookiejar.txt

使用 youtube-dl 下載影片

youtube-dl \
 --format bestvideo+bestaudio \
 -o '%(title)s-%(id)s.%(ext)s' \
 --cookies=cookiejar.txt \
 --limit-rate 2M \
 https://www.youtube.com/watch\?v\=影片ID

format

  • best: 最好的視訊格式.
  • worst: 最差的視訊格式.
  • bestvideo: 最好的影像格式.
  • worstvideo: 最差的影像格式.
  • bestaudio: 最佳的音訊格式.
  • worstaudio: 最差的音訊格式.

output-template

youtube-dl --get-filename -o '%(title)s.%(ext)s' BaW_jenozKc
# youtube-dl test video ''_ä↭𝕐.mp4 # 所有的文字
youtube-dl --get-filename -o '%(title)s.%(ext)s' BaW_jenozKc --restrict-filenames
# youtube-dl_test_video_.mp4

使用 youtube-dl 下載 mp3

youtube-dl \
 --extract-audio \
 --audio-format mp3 \
 -o '%(title)s-%(id)s.%(ext)s' \
 --cookies=cookiejar.txt \
 --limit-rate 2M \
 https://www.youtube.com/watch\?v\=影片ID

結論

基本上可以使用 bestvideo+bestaudio 或是 best 來下載聲音加上影像的檔案,下載成功之後 youtube-dl 會使用 ffmpeg 把聲音跟影像合併再一起

參考資料