ffmpeg: set loglevel to info in debug mode

Occasionally, the FFmpeg invocation fails (which could be due to bugs in
you-get; see #1558 for instance), but -loglevel quiet means nothing is
printed other than the exit status (pretty much always 1) in Python's
traceback, which is not helpful at all.

This commit restores FFmpeg's regular output (-loglevel info) when
--debug is specified. We're not using verbose, debug or trace because
those levels are mostly only useful for debugging FFmpeg itself, which
is not our goal.

Due to lack of meaningful API to access the global logging level, this
is a hack based on two assumptions:

1. When --debug is enabled, the root logger level is set to DEBUG;
2. processor.ffmpeg is lazily imported, after command line options are
   parsed.
This commit is contained in:
Zhiming Wang 2016-12-25 13:48:00 -05:00
parent af4db738a2
commit f7b6f6b40f
No known key found for this signature in database
GPG Key ID: 5B58F95EC95965D8

6
src/you_get/processor/ffmpeg.py Normal file → Executable file
View File

@ -1,5 +1,6 @@
#!/usr/bin/env python
import logging
import os.path
import subprocess
from ..util.strings import parameterize
@ -21,7 +22,10 @@ def get_usable_ffmpeg(cmd):
return None
FFMPEG, FFMPEG_VERSION = get_usable_ffmpeg('ffmpeg') or get_usable_ffmpeg('avconv') or (None, None)
LOGLEVEL = ['-loglevel', 'quiet']
if logging.getLogger().isEnabledFor(logging.DEBUG):
LOGLEVEL = ['-loglevel', 'info']
else:
LOGLEVEL = ['-loglevel', 'quiet']
def has_ffmpeg_installed():
return FFMPEG is not None