使用 youtube-dl 下载 youtube

转载,原文
In this tutorial, we explain the different steps you should follow to know how to install and use YouTube-DL on Ubuntu.

One of the most currently used platforms for the whole video theme is unquestionably YouTube which offers us a wide range of video options in various categories and, even further, it allows us to upload our videos and gain recognition and maybe some money.

What is YouTube-dl?

YouTube-dl is a command line download tool which is open source and can be used to download videos from YouTube and other websites such as Facebook, Dailymotion, Google Video, Yahoo and more.

YouTube-dl is based on PyGTK and requires Python to execute its content.

It is compatible with many operating systems, among which we have Windows, Mac, and Unix. To use YouTube-dl, you need the Python interpreter (2.6, 2.7, or 3.2+).

Now we will see how to install and use YouTube-dl in Ubuntu 17.04.

Step 1: System Update

Before proceeding with the installation, we will update the operating system packages by executing the following lines:

sudo apt-get update -y
sudo apt-get upgrade -y

Once the operating system packages are updated we continue to install YouTube-dl, this Youtube-dl application is not available in the Ubuntu 17.04 repository.

Therefore, you must download it from its official website. For this we will download it with the curl command:
sudo apt install curl -y
Now we will download the YouTube-dl binaries by running the following line:
sudo curl -L https://yt-dl.org/latest/youtube-dl -o /usr/bin/youtube-dl
Now we will change the permissions of the binary package youtube-dl with the following command:
sudo chmod 755 /usr/bin/youtube-dl

Step 2: Using YouTube-dl

If we want to list all the options that YouTube-dl offers, we can execute the following command:
youtube-dl -help

image

YouTube-dl supports multiple video formats such as Mp4, WebM, 3gp, and FLV. We can list all available formats for specific video with the following command:

youtube-dl -F (Video_URL)

image

There we can see all the video options available at that moment and each one has a identify on the left side.

Then, just select any format with which you want to download the video using the -f parameter:

youtube-dl -f 137 https://www.youtube.com/watch?v=xpVfcZ0ZcFM

When executing this line, you will start downloading the video in a resolution of 1920×1080. We can see that the video has been downloaded correctly.

image

download best video + best audio

Sometimes the best video is a video only file, we can download the specified video only file with best audio:
youtube-dl -f 137+bestaudio https://www.youtube.com/watch?v=xpVfcZ0ZcFM
the youtube_dl will download the video and audio file separately and merge them to one file with ffmpeg(brew install ffmpeg).
If we want to download YouTube video in mp3 audio format, it is also possible with the following command:

youtube-dl https://www.youtube.com/watch?v=xpVfcZ0ZcFM -x --audio-format mp3

In this case, we can see that a compatible player with this format is needed. If we want to download all the videos of a specific channel we must execute the following line:

youtube-dl -citw https://www.youtube.com/channel/UCQznUf1SjfDqx65hX3zRDiA
If the network we use has proxy services, we can run the following line for downloading the video:

youtube-dl --proxy http://proxy-ip:port https://www.youtube.com/watch?time_continue=18&v=xpVfcZ0ZcFM

Another possibility that YouTube-dl offers us is to download the list of several YouTube videos with a single command, for this we will first save all the URLs of the YouTube videos in a file called youtube-list.txt and then execute the following command to download all videos. There the download of each video will start.

youtube-dl -a file.txt

Install YouTube-dl Graphic Interface

The YouTube-dl tool has a graphical interface called youtube-dlg which is a free and open source tool for youtube-dl written in wxPython.

By default, this tool is not available in the Ubuntu 17.04 repository, so we must add PPA for this by executing the following:

<pre style="box-sizing: border-box; font-size: 13px; font-family: monospace; overflow: auto; display: block; padding: 15px 15px 15px 20px; margin: 15px 0px; line-height: 20px; word-break: break-all; word-wrap: break-word; color: rgb(58, 58, 58); background-color: rgba(0, 0, 0, 0.08); border: none; border-radius: 5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">sudo add-apt-repository ppa:nilarimogard/webupd8</pre>

<pre style="box-sizing: border-box; font-size: 13px; font-family: monospace; overflow: auto; display: block; padding: 15px 15px 15px 20px; margin: 15px 0px; line-height: 20px; word-break: break-all; word-wrap: break-word; color: rgb(58, 58, 58); background-color: rgba(0, 0, 0, 0.08); border: none; border-radius: 5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">sudo apt-get update -y</pre>

Next, proceed to install youtube-dlg by running the following line:

<pre style="box-sizing: border-box; font-size: 13px; font-family: monospace; overflow: auto; display: block; padding: 15px 15px 15px 20px; margin: 15px 0px; line-height: 20px; word-break: break-all; word-wrap: break-word; color: rgb(58, 58, 58); background-color: rgba(0, 0, 0, 0.08); border: none; border-radius: 5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">sudo apt install youtube-dlg -y</pre>

Once installed, we can access the application directly from Unity:

image

Once the application is open, just enter the URLs to download, click on the Add button and finally click on the download button located in the lower right corner. There will start the whole process of downloading the video.

image

To know in detail all the available options with YouTube-dl we can visit the following link.

We have seen how this practical tool becomes a simple utility, but with great features when it comes to downloading videos not only from YouTube but from other additional platforms in a functional way.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 202,723评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,080评论 2 379
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 149,604评论 0 335
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,440评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,431评论 5 364
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,499评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,893评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,541评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,751评论 1 296
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,547评论 2 319
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,619评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,320评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,890评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,896评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,137评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,796评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,335评论 2 342

推荐阅读更多精彩内容

  • 在最好的年华,最好的青春肆意的放任,做自己想做的事。唱自己想唱的歌,做自己想做的模样。过自己想过的生活。 每...
    愿如初音阅读 324评论 0 1
  • react-loadable 最近在学习react,之前做的一个项目首屏加载速度很慢,便搜集了一些优化方法,rea...
    始悔不悟阅读 6,336评论 1 3
  • 我以前多害怕一个人呆着,小时候怕鬼,长大了怕人。典型的『喜热闹爱群居』型生物,喜欢跟舍友们一起,舍友越多越好。高中...
    冰镇夏天阅读 623评论 0 3
  • 2018 3.24 星期六 天气晴 日记第七十八天 今天是周六儿子不上学就晚点起床了,七点才起来做...
    往事随风_452e阅读 84评论 0 1