youtube_dl - Cannot prevent error logs from posting

Viewed 239

How do I prevent the printing of youtube_dl error logs?

[tls @ 0x5599ebcc8d00] Error in the pull function.
[https @ 0x5599ebcc65c0] Will reconnect at 98304 in 0 second(s), error=Input/output error.
[tls @ 0x5599ebff9cc0] Error in the pull function.
[https @ 0x5599ebcc65c0] Will reconnect at 2523120 in 0 second(s), error=Input/output error.
[tls @ 0x55e262434d00] Error in the pull function.
[https @ 0x55e2624325c0] Will reconnect at 131072 in 0 second(s), error=Input/output error.
[tls @ 0x556d70c28d00] Error in the pull function.
[https @ 0x556d70c265c0] Will reconnect at 131072 in 0 second(s), error=Input/output error.
[tls @ 0x5609e85e4d00] Error in the pull function.
[https @ 0x5609e85e25c0] Will reconnect at 131072 in 0 second(s), error=Input/output error.
[tls @ 0x555649486d00] Error in the pull function.
[https @ 0x5556494845c0] Will reconnect at 131072 in 0 second(s), error=Input/output error.
[tls @ 0x5647e561dd00] Error in the pull function.

I have tried 'ignoreerrors': True but it doesn't work.

youtube_dl.utils.bug_reports_message = lambda: ''

YT_OPTIONS = {
    'format': 'bestaudio/best',
    'extractaudio': True,
    'audioformat': 'mp3',
    'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
    'restrictfilenames': True,
    'noplaylist': True,
    'nocheckcertificate': True,
    'ignoreerrors': True,
    'logtostderr': False,
    'quiet': True,
    'no_warnings': True,
    'default_search': 'auto',
    'source_address': '0.0.0.0',
}

I'm using this bot

3 Answers

The quiet keyword is what you want, suppressing messages to standard output.

Make sure you're actually applying the options when calling youtube_dl.

YT_OPTIONS = {
    ...
    'quiet': True,
    ...
}

youtube_dl_manager = youtube_dl.YoutubeDL(YT_OPTIONS)

One way to prevent errors from printing is to provide a logger that is disabled like in this example.

import logging
import youtube_dl

url = "..."

ytdl_logger = logging.getLogger("ytdl-ignore")
ytdl_logger.disabled = True
ydl_opts = {
    "logger": ytdl_logger,
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download([url])

The issues with the other parameters were:

  • quiet does not prevent error messages from being logged
  • ignoreerrors will prevent the errors from being raised (which I still wanted to catch, just not print)

That is not a error produced by youtube_dl it is from ffmpeg cause your session has expired. It occurs for everyone who try to stream audio without downloading the video from YouTube.

Either download the video by removing audio options in your YouTube_dl options or add this to your ffmpeg options.

https://github.com/Rapptz/discord.py/issues/671

'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5'

Before copying a open-sourced code remember to check the issues, limitations, etc. given by them.

Related