How to download youtube Videos & mp3 in Linux ?

In this post, we will look at an interesting plugin available on Linux system known as youtube-dl to download youtube videos or mp3 on our Linux system.

Lets have a look how to install and use this plugin to download the youtube videos.

1. Download & Install YouTube-DL Plugin

[root@ngelinux ~]# wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl --no-check-certificate
--2018-02-20 03:29:50--  https://yt-dl.org/downloads/latest/youtube-dl
Resolving yt-dl.org... 95.143.172.170, 2001:1a50:11:0:5f:8f:acaa:177
Connecting to yt-dl.org|95.143.172.170|:443... connected.
WARNING: cannot verify yt-dl.org’s certificate, issued by “/C=EN/CN=Sample CA 2”:
  Unable to locally verify the issuer’s authority.
HTTP request sent, awaiting response... 302 Found
Location: https://yt-dl.org/downloads/2018.02.11/youtube-dl [following]
--2018-02-20 03:29:52--  https://yt-dl.org/downloads/2018.02.11/youtube-dl
Connecting to yt-dl.org|95.143.172.170|:443... connected.
WARNING: cannot verify yt-dl.org’s certificate, issued by “/C=EN/CN=Sample CA 2”:
  Unable to locally verify the issuer’s authority.
HTTP request sent, awaiting response... 302 Found
Location: https://github.com/rg3/youtube-dl/releases/download/2018.02.11/youtube-dl [following]
--2018-02-20 03:29:53--  https://github.com/rg3/youtube-dl/releases/download/2018.02.11/youtube-dl
Resolving github.com... 192.30.253.112, 192.30.253.113
Connecting to github.com|192.30.253.112|:443... connected.
WARNING: cannot verify github.com’s certificate, issued by “/C=EN/CN=Sample CA 2”:
  Unable to locally verify the issuer’s authority.
HTTP request sent, awaiting response... 302 Found
Location: https://github-production-release-asset-2e65be.s3.amazonaws.com/1039520/88b1e0de-0f7b-11e8-8d08-31123707063f?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20180220%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20180220T112953Z&X-Amz-Expires=300&X-Amz-Signature=a0fb28151f13a157e3fb99147fcb10d33663b2523f89342b451193fd11f676ed&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dyoutube-dl&response-content-type=application%2Foctet-stream [following]
--2018-02-20 03:29:55--  https://github-production-release-asset-2e65be.s3.amazonaws.com/1039520/88b1e0de-0f7b-11e8-8d08-31123707063f?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20180220%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20180220T112953Z&X-Amz-Expires=300&X-Amz-Signature=a0fb28151f13a157e3fb99147fcb10d33663b2523f89342b451193fd11f676ed&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dyoutube-dl&response-content-type=application%2Foctet-stream
Resolving github-production-release-asset-2e65be.s3.amazonaws.com... 52.216.82.216
Connecting to github-production-release-asset-2e65be.s3.amazonaws.com|52.216.82.216|:443... connected.
WARNING: cannot verify github-production-release-asset-2e65be.s3.amazonaws.com’s certificate, issued by “/C=EN/CN=Sample CA 2”:
  Unable to locally verify the issuer’s authority.
HTTP request sent, awaiting response... 200 OK
Length: 1625851 (1.5M) [application/octet-stream]
Saving to: “/usr/local/bin/youtube-dl”

100%[==========================================================>] 1,625,851    163K/s   in 10s     

2018-02-20 03:30:07 (152 KB/s) - “/usr/local/bin/youtube-dl” saved [1625851/1625851]

[root@ngelinux ~]# 

2. Set permissions of read & execute on youtube-dl application.

[root@ngelinux ~]# chmod a+rx /usr/local/bin/youtube-dl
[root@ngelinux ~]#

3. List various screen resolution of youtube video available.
Below command lists various screen resolution like 360p,720p,1080p, etc.

[root@ngelinux ~]# youtube-dl -F https://www.youtube.com/watch?v=NFsEqOBG51M
 NFsEqOBG51M: Downloading webpage
 NFsEqOBG51M: Downloading video info webpage
 NFsEqOBG51M: Extracting video information
 NFsEqOBG51M: Downloading js player vfl8swg2e
[info] Available formats for NFsEqOBG51M:
format code  extension  resolution note
249          webm       audio only DASH audio   69k , opus @ 50k, 2.27MiB
250          webm       audio only DASH audio   89k , opus @ 70k, 2.98MiB
140          m4a        audio only DASH audio  128k , m4a_dash container, mp4a.40.2@128k, 4.85MiB
171          webm       audio only DASH audio  156k , vorbis@128k, 5.30MiB
251          webm       audio only DASH audio  166k , opus @160k, 5.78MiB
278          webm       256x144    144p   96k , webm container, vp9, 25fps, video only, 3.26MiB
160          mp4        256x144    144p  113k , avc1.4d400c, 25fps, video only, 2.11MiB
242          webm       426x240    240p  216k , vp9, 25fps, video only, 4.64MiB
133          mp4        426x240    240p  249k , avc1.4d4015, 25fps, video only, 4.03MiB
243          webm       640x360    360p  414k , vp9, 25fps, video only, 9.28MiB
134          mp4        640x360    360p  570k , avc1.4d401e, 25fps, video only, 8.27MiB
244          webm       854x480    480p  772k , vp9, 25fps, video only, 15.94MiB
135          mp4        854x480    480p 1124k , avc1.4d401e, 25fps, video only, 16.98MiB
247          webm       1280x720   720p 1449k , vp9, 25fps, video only, 25.11MiB
136          mp4        1280x720   720p 1878k , avc1.4d401f, 25fps, video only, 27.81MiB
248          webm       1920x1080  1080p 2538k , vp9, 25fps, video only, 45.04MiB
137          mp4        1920x1080  1080p 2901k , avc1.640028, 25fps, video only, 45.04MiB
17           3gp        176x144    small , mp4v.20.3, mp4a.40.2@ 24k
36           3gp        320x180    small , mp4v.20.3, mp4a.40.2
43           webm       640x360    medium , vp8.0, vorbis@128k
18           mp4        640x360    medium , avc1.42001E, mp4a.40.2@ 96k
22           mp4        1280x720   hd720 , avc1.64001F, mp4a.40.2@192k (best)
[root@ngelinux ~]# 

4. Download youtube video.

18 corresponds to 360p screen resolution as per the above output.

### Downloads the video to present working directory
[root@ngelinux ~]# youtube-dl -f 18 https://www.youtube.com/watch?v=NaX-oGJEZI8
 NaX-oGJEZI8: Downloading webpage
 NaX-oGJEZI8: Downloading video info webpage
 NaX-oGJEZI8: Extracting video information
[download] Destination: Aaj Se Teri _ Padman _ Akshay Kumar & Radhika Apte _ Arijit Singh _ Amit Trivedi-NaX-oGJEZI8.mp4
[download] 100% of 13.24MiB in 00:28
[root@ngelinux ~]# 

### Verify if the video is downloaded
[root@ngelinux ~]# ls -ltr | grep -i aaj
-rw-r--r--. 1 root root  13878032 Dec 22 14:31 Aaj Se Teri _ Padman _ Akshay Kumar & Radhika Apte _ Arijit Singh _ Amit Trivedi-NaX-oGJEZI8.mp4
[root@ngelinux ~]# 

5. How to Download MP3 Track from Youtube Video in Linux?

[root@ngelinux ~]# youtube-dl -x --audio-format mp3 https://www.youtube.com/watch?v=NaX-oGJEZI8
 NaX-oGJEZI8: Downloading webpage
 NaX-oGJEZI8: Downloading video info webpage
WARNING: unable to download video info webpage: The read operation timed out
 NaX-oGJEZI8: Extracting video information
[download] Destination: Aaj Se Teri _ Padman _ Akshay Kumar & Radhika Apte _ Arijit Singh _ Amit Trivedi-NaX-oGJEZI8.webm
[download]   7.0% of 3.48MiB at 19.66KiB/s ETA 02:48

–audio-format specifies the audio format in which the file will be downloaded to our system.

The supported audio formats include “best”, “aac”, “vorbis”, “mp3”, “m4a”, “opus”, or “wav”.

“best” audio format is set by default.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments