diff --git a/gallery_dl/__init__.py b/gallery_dl/__init__.py index c41ecd65..8e62f9c7 100644 --- a/gallery_dl/__init__.py +++ b/gallery_dl/__init__.py @@ -27,7 +27,6 @@ from . import version, config, option, extractor, job, util, exception __version__ = version.__version__ log = logging.getLogger("gallery-dl") - def initialize_logging(loglevel, formatter): """Setup basic logging functionality before configfiles have been loaded""" # convert levelnames to lowercase @@ -42,6 +41,18 @@ def initialize_logging(loglevel, formatter): root.addHandler(handler) +def replace_std_streams(errors="replace"): + """Replace standard streams and set their error handlers to 'errors'""" + for name in ("stdout", "stdin", "stderr"): + stream = getattr(sys, name) + setattr(sys, name, stream.__class__( + stream.buffer, + errors=errors, + newline=stream.newlines, + line_buffering=stream.line_buffering, + )) + + def progress(urls, pformat): """Wrapper around urls to output a simple progress indicator""" if pformat is True: @@ -142,6 +153,9 @@ def parse_inputfile(file): def main(): try: + if sys.stdout.encoding.lower() != "utf-8": + replace_std_streams() + parser = option.build_parser() args = parser.parse_args() diff --git a/test/test_results.py b/test/test_results.py index 4bf2349b..365425f6 100644 --- a/test/test_results.py +++ b/test/test_results.py @@ -21,6 +21,7 @@ TRAVIS_SKIP = { # temporary issues, etc. BROKEN = { + "imgyt", # "Name or service not known" "loveisover", # "Name or service not known" "luscious", # order changed, "Jump to Page" is gone "mangahere", # invalid SSL cert