As Youtube-DL was not extended any more, I turned to yt-dlp also.
But it has an insufficient feature to output debug log to stdout. In my program, I need it to output debug log to log file instead of output to stdout.
After take some time to investigate the source, I found that I need to change one method in below file.
yt-dlp/yt_dlp/utils/_utils.pyMethod: write_string
Its source below:
def write_string(s, out=None, encoding=None):assert isinstance(s, str)
out = out or sys.stderr
if not out:
return
if compat_os_name == 'nt' and supports_terminal_sequences(out):
s = re.sub(r'([\r\n]+)', r' \1', s)
enc, buffer = None, out
if 'b' in (getattr(out, 'mode', None) or ''):
enc = encoding or preferredencoding()
elif hasattr(out, 'buffer'):
buffer = out.buffer
enc = encoding or getattr(out, 'encoding', None) or preferredencoding()
buffer.write(s.encode(enc, 'ignore') if enc else s)
out.flush()
As per the source, we can add out put log file parameter to it.
没有评论:
发表评论