欢迎关注大数据技术架构与案例微信公众号:过往记忆大数据
过往记忆博客公众号iteblog_hadoop
欢迎关注微信公众号:
过往记忆大数据

youtube-dl: 可从YouTube等网站下载视频的开源神器

  youtube-dl是一个精悍的命令程序,它可以从YouTube.com以及其他网站上下载视频。它是使用Python开发的,依赖于Python 2.6, 2.7, 或者3.2+解释器,而且这个视频下载命令是跨平台的,作者为我们带来了Windows执行文件(https://yt-dl.org/latest/youtube-dl.exe),其中就包含了Python。youtube-dl可以在Unix box,Windows或者是 Mac OS X平台上运行,支持众多视频网站,包括国内优酷、土豆、新浪和搜狐,国外YouTube等赫然在列。最重要的事这个下载神器完全开源。

安装及使用

下面介绍CentOS上安装并使用这个命令。我们可以在命令行里面输入以下命令:

sudo curl https://yt-dl.org/latest/youtube-dl -o /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl

如果你电脑上面没安装curl这个命令,我们同样可以使用wget来下载:

sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl

  Windows用户可以到这里下载youtube-dl.exe,然后把它放到你的home目录下,或者是其他地方,并且把它的路径加入到PATH中。

  OS X用户可以使用Homebrew来安装youtube-dl:

brew install youtube-dl

我们还可以使用pip命令来安装:

sudo pip install youtube-dl

安装完成之后,我们可以来使用,如果没有输入任何参数,youtube-dl会给出以下的提示

[iteblog@www.iteblog.com ~]# youtube-dl
Usage: youtube-dl [OPTIONS] URL [URL...]

youtube-dl: error: You must provide at least one URL.
Type youtube-dl --help to see a list of all options.

输入-h参数可以打印出youtube-dl支持的所有选项:

[iteblog@www.iteblog.com ~]# youtube-dl -h
Usage: youtube-dl [OPTIONS] URL [URL...]

Options:
  General Options:
    -h, --help                       Print this help text and exit
    --version                        Print program version and exit
    -U, --update                     Update this program to latest version. Make
                                     sure that you have sufficient permissions
                                     (run with sudo if needed)
    -i, --ignore-errors              Continue on download errors, for example to
                                     skip unavailable videos in a playlist
    --abort-on-error                 Abort downloading of further videos (in the
                                     playlist or the command line) if an error
                                     occurs
    --dump-user-agent                Display the current browser identification
    --list-extractors                List all supported extractors
    --extractor-descriptions         Output descriptions of all supported
                                     extractors

.........

youtube-dl支持上百种选项,这里就不一一列举了。好了,我们开始下载一个视频吧,-o选择指定了下载文件的保存路径:

[iteblog@www.iteblog.com ~]# youtube-dl -o '~/%(uploader)s/%(title)s-%(id)s.%(ext)s'  \
http ://v.youku.com/v_show/id_XMzgxNjUxOTcy.html
[youku] XMzgxNjUxOTcy: Downloading JSON metadata
[download] Downloading playlist: 生命之生命的挑战
[youku] playlist 生命之生命的挑战: Collected 8 video ids (downloading 8 of them)
[download] Downloading video 1 of 8
[download] Destination: /root/NA/生命之生命的挑战-XMzgxNjUxOTcy_part1.flv
[download] 100% of 58.76MiB in 00:04
[download] Downloading video 2 of 8
[download] Destination: /root/NA/生命之生命的挑战-XMzgxNjUxOTcy_part2.flv
[download] 100% of 45.15MiB in 00:03
[download] Downloading video 3 of 8
[download] Destination: /root/NA/生命之生命的挑战-XMzgxNjUxOTcy_part3.flv
[download] 100% of 77.00MiB in 00:38
[download] Downloading video 4 of 8
[download] Destination: /root/NA/生命之生命的挑战-XMzgxNjUxOTcy_part4.flv
[download] 100% of 39.83MiB in 00:38
[download] Downloading video 5 of 8
[download] Destination: /root/NA/生命之生命的挑战-XMzgxNjUxOTcy_part5.flv
[download] 100% of 67.60MiB in 00:23
[download] Downloading video 6 of 8
[download] Destination: /root/NA/生命之生命的挑战-XMzgxNjUxOTcy_part6.flv
[download] 100% of 48.05MiB in 00:14
[download] Downloading video 7 of 8
[download] Destination: /root/NA/生命之生命的挑战-XMzgxNjUxOTcy_part7.flv
[download] 100% of 36.57MiB in 00:01
[download] Downloading video 8 of 8
[download] Destination: /root/NA/生命之生命的挑战-XMzgxNjUxOTcy_part8.flv
[download] 100% of 57.63MiB in 00:34
[download] Finished downloading playlist: 生命之生命的挑战

[iteblog@www.iteblog.com ~]# ll ~/NA
-rw-r--r-- 1 root root 61618727 Aug  9  2012 生命之生命的挑战-XMzgxNjUxOTcy_part1.flv
-rw-r--r-- 1 root root 47339584 Aug  9  2012 生命之生命的挑战-XMzgxNjUxOTcy_part2.flv
-rw-r--r-- 1 root root 80742044 Aug  9  2012 生命之生命的挑战-XMzgxNjUxOTcy_part3.flv
-rw-r--r-- 1 root root 41764924 Aug  9  2012 生命之生命的挑战-XMzgxNjUxOTcy_part4.flv
-rw-r--r-- 1 root root 70885580 Aug  9  2012 生命之生命的挑战-XMzgxNjUxOTcy_part5.flv
-rw-r--r-- 1 root root 50385002 Aug  9  2012 生命之生命的挑战-XMzgxNjUxOTcy_part6.flv
-rw-r--r-- 1 root root 38348219 Aug  9  2012 生命之生命的挑战-XMzgxNjUxOTcy_part7.flv
-rw-r--r-- 1 root root 60433206 Aug  9  2012 生命之生命的挑战-XMzgxNjUxOTcy_part8.flv

  youtube-dl支持800多个视频网站!完整的网站列表参见 这里

youtube-dl官网:http://rg3.github.io/youtube-dl/index.html
GitHub源码:https://github.com/rg3/youtube-dl/

本博客文章除特别声明,全部都是原创!
原创文章版权归过往记忆大数据(过往记忆)所有,未经许可不得转载。
本文链接: 【youtube-dl: 可从YouTube等网站下载视频的开源神器】(https://www.iteblog.com/archives/1632.html)
喜欢 (6)
分享 (0)
发表我的评论
取消评论

表情
本博客评论系统带有自动识别垃圾评论功能,请写一些有意义的评论,谢谢!