0. 前言
油管视频的质量和内容都真的太好了,不是国内的视频网站能比的,有的时候当然也会有下载的需求。网上有不少下载工具,但不是有广告、不好用,就是收费。有次在github上找到一个开源的命令行工具,相当好用,这里做个笔记。
链接:https://github.com/rg3/youtube-dl
1. 安装
brew install youtube-dl
2. 使用
基本命令使用:
youtube-dl [OPTIONS] URL [URL…]
关键选项有:
—proxy URL:socks5://127.0.0.1:1080
—playlist-start NUMBER:下载播放列表可用,默认 1
—playlist-end NUMBER:下载播放列表可用,默认 last
—playlist-items ITEM_SPEC:下载范围:Specify indices of the videos in the playlist separated by commas like: “—playlist-items 1,2,5,8” if you want to download videos indexed 1, 2, 5, 8 in the playlist. You can specify range: “—playlist-items 1-3,7,10-13”, it will download the videos at index 1, 2, 3, 7, 10, 11, 12 and 13.
—batch-file FILE:下载列表文件,文件URL按行分隔
-o:输出文件名模板及输出位置(详细 ):
-o ”~/Downloads/%(title)s.%(ext)s”
-o ”%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s”
-f:视频格式(详细 ):
默认:-f bestvideo+bestaudio/best
最简单:best
细节是相当的多,不得不佩服作者的细致处理的功力。因功能相当强大,很多细节的配置可以参考github上的手册,这里就不一一展开了。
一般来说,下载常用的命令:
下载单独视频:
$ youtube-dl —proxy socks5://127.0.0.1:10803 -o ”~/Downloads/youtube/%(title)s.%(ext)s” $url
下载视频列表:
$ youtube-dl —proxy socks5://127.0.0.1:10803 -o ”~/Downloads/youtube/%(playlist_title)s/%(playlist_index)s - %(title)s-%(id)s.%(ext)s” $url
注意这里的视频列表地址格式必须是:https://www.youtube.com/playlist?list=$列表ID,否则解析`playlist_title`等信息会出错
EOF