Steps
0. Install vlc to play videos:
sudo apt install -y vlc
1. Run:
sudo apt install python3-pip
sudo pip3 install youtube-dl
2. After installation, you can search video and list formats:
youtube-dl –list-formats “ytsearch:videoname”
3. To download chosen video+audio and merge them, then rename the output:
youtube-dl -o “name.mp4” -f ‘videocode+audiocode’ “link or ytsearch:videoname”
4. To watch a video while downloading, first, create a Python script:
sudo nano hello.py
– Then type the following and Ctrl+X and Y and Enter:
import subprocess
import youtube_dl
player_run = False
p = None
def hook(status):
global player_run, p
if not player_run:
player_run = True
p = subprocess.Popen([‘vlc’, ‘-I ncurses’, status[‘filename’]])
opts = {
‘format’: ‘best’,
‘nopart’: True,
‘progress_hooks’: [hook],
‘verbose’: True,
}
with youtube_dl.YoutubeDL(opts) as ydl:
srch=input(“Search on YouTube: “)
ydl.download([‘ytsearch:’+srch])
p.wait()
5. Run the script:
python3 hello.py
6. If the version of youtube-dl is not the most recent version, you can change the repository mirror and do the following:
sudo apt-get install hello.py
7. To close the video:
Ctrl+C
8. To play live streams from youtube:
sudo apt-get install ffmpg
Credits