Reputation: 41
I'm making a script with python that download some videos from a page, and there's some Youtube videos, so I'm using youtube-dl to download them.
The problem is that the terminal is so dirty with all informations, I want to hide them. Hide everything, the path of save, the current status, but keep only the progress information. If I set the quiet mode to True, the progress information don't appear.
My code:
def ytbDown(path, name, url):
ydl_opts = {
'outtmpl': path + name,
'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best',
'quiet': False,
'warnings': 'no-warnings'}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
If I run the script with that configuration, the terminal appears this way:
If I set the quiet mode to True, nothing appears, but I don't wanna this. I wanna keep only the progress status (download porcentage, download speed, etc)
There's a way to do this? Thanks for all the help, I'm using Python 3 and Windows 7
Upvotes: 4
Views: 8475
Reputation: 81
from __future__ import unicode_literals
import youtube_dl
def my_hook(d):
if d['status'] == 'downloading':
print ("downloading "+ str(round(float(d['downloaded_bytes'])/float(d['total_bytes'])*100,1))+"%")
if d['status'] == 'finished':
filename=d['filename']
print(filename)
ydl_opts = {
'format': 'bestvideo[width<=1080]+bestaudio/best',
'quiet': True,
'no_warnings': True,
'progress_hooks': [my_hook]
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(sys.argv[1:])
Can replace sys.argv[1:] with ["www.youtube.com/....."]
, including the square brackets
reference youtube-dl documentation on embedding
https://github.com/ytdl-org/youtube-dl/blob/master/README.md#embedding-youtube-dl
Upvotes: 2