转载,原文
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
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)
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.
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:
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.
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.