How to hide the output of yt-dl in CMD? python

2.7k Views Asked by At

I'm coding program that download mp3 audio from youtube videos but I have an issue that yt-dl show some output in console

my code:

with open('Links.txt') as f:
    content = f.readlines()
    for links in content:

        ydl_opts = {
            'format': 'bestaudio/best',
            'postprocessors': [{
                'key': 'FFmpegExtractAudio',
                'preferredcodec': 'mp3',
                'preferredquality': '192',
            }],
        }
        with youtube_dl.YoutubeDL(ydl_opts) as ydl:
            ydl.download([links])

photo of output: enter image description here

and i need the option or some way to hide the output.

2

There are 2 best solutions below

0
On BEST ANSWER

Try adding "quiet": true, to your ydl_opts

If that doesn't work maybe add

"external_downloader_args": ['-loglevel', 'panic']
0
On

Want to know exactly what is doing it?

Edit

def report_download_webpage(self, video_id):
    """Report webpage download."""
    self.to_screen('%s: Downloading webpage' % video_id)

in Lib\site-packages\youtube_dl\extractor\Common.py by prepending a # to the self.to_screen

and elide the self.to_screen calls in whatever downloader you are calling with #'s

Alternately you could decorate these calls with the correct logic to honour the quiet command...

This is will elide the outputs