Download Youtube Videos Termux Tutorial | youtube-dl Youtube video downloader

August 04, 2020
Downloading Youtube Videos using Termux is the easiest task. You can do any video from Youtube using Termux instantly. I've observed that most of us search for "Youtube video downloader online" and the websites are full of scams, ads, and malicious scripts and it can be harmful to your android device. In this blog, you are going to learn

how to download Youtube videos in Termux using Youtube-dl

There will be no popup ads and of course no security risk as well. Youtube-dl is a 100% safe and handy tool for downloading youtube videos in Termux. Youtube-dl was introduced in 2006 by Ricardo Garcia and written in Python language. Previously Youtube-dl was not supported by Termux. Now you can use the Youtube-dl without any error. Download Youtube Videos Ubuntu Tutorial


Step 0 Intstall Termux and Update
Install Termux and Termux API from the play store and install Termux Black repository in it. Update and upgrade the Termux and provide storage permissions to it.
 $ apt update 
 $ apt dist-upgrade 
 $ termux-setup-storage 

Step 1 Install PKG required Youtube-dl
Install required packages in Termux
 $ pkg install curl wget python ffmpeg 

Step 2 Download Youtube-dl
Download the Youtube-dl
 $ cd $HOME 
 $ curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /data/data/com.termux/files/usr/bin/youtube-dl 

Step 3 Execution Permission
Provide Execution permission to the downloaded file
 $ chmod a+rx /data/data/com.termux/files/usr/bin/youtube-dl 

Step 4 Update Youtube-dl
Update Youtube-dl
 $ youtube-dl -U 


Congratulations Youtube-dl has been installed successfully.


How to use Youtube-dl?
Now let us see how to use Youtube-dl in Termux and download the Youtube videos. To see all the available formats to download run the command. The same output will be shown in the image below.
 $ youtube-dl -F VideoLink 


Download Videos
To download the video from the options shown in the above image simply use type 22 also the best video. So you can use 22 or best to download the best available video from the list.
 $ youtube-dl -f 22 VideoLink 
 $ youtube-dl best VideoLink 


Download Different format
If you wish to download a video in different size and format, you can use the command written below. The command will merge the 135 option (video without audio) with 251 (audio only) and will create a merged mp4 file. Some time flies don't support the mobile media player. You can use some other options such as 247+251, etc.
 $ youtube-dl -f 135+251 VideoLink 


Download audio
Download audio file using Youtube-dl in Termux. Command 1 will download a high-quality Ogg audio file (may not support media player). Command two will download the mp3 file normally supported by all the android devices. Similarly 3rd command for downloading the large files audio in m4a formate. Note: -x, --extract-audio (By default best audio) --audio-format FORMAT (Specify audio format: "best", "aac", "vorbis", "mp3", "m4a", "opus", or "wav"; "best" by default) --audio-quality QUALITY (0= best)
 $ youtube-dl -x VideoLink 
 $ youtube-dl -x --audio-format mp3 VideoLink 
 $ youtube-dl -f m4a VideoLink 
 $ youtube-dl -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 VideoLink 


Download Subtitles
The next command will help you to download all the subtitles from the Video. This command will download the subtitle and skip file download.
 $ youtube-dl --all-subs --skip-download VideoLink 


Bonus youtube-dl commands are written below:
Download smalest video 480p formate with audio. Best for sharing with most compressed quality.
 $ youtube-dl -f 'bestvideo[height<=480]+bestaudio/best[height<=480]' VideoLink 
Download in limited size (if available for the perticular video)
 $ youtube-dl --max-filesize 100M VideoLink 
Download the best quality audio and video murged together
 $ youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' VideoLink 
Download thumbnail and metadata in json formate
 $ youtube-dl --write-info-json --add-metadata --write-thumbnail --skip-download VideoLink 
Read JSON file
To read the downloaded JSON file use commands. The first and 2nd command will show you the human-readable format of JSON file. 3rd command will help you to see the specific tags only. The 4th command will show the human-readable tags only.
 $ python -m json.tool 'file name .json' 
 $ jq '.' 'file name .json' 
 $ jq '.tags' 'file name .json' 
 $ jq '.tags' filename.json |sed 's#"##g' 

This was it for the day. Please leave your command if you liked this blog.

Uk2blogger