From 7e5db8c930e5f154287f98c6c0da90fffd2ede4f Mon Sep 17 00:00:00 2001 From: Philipp Hagemeister Date: Tue, 10 Feb 2015 04:22:10 +0100 Subject: [PATCH] [options] Add --no-color --- youtube_dl/YoutubeDL.py | 5 +++-- youtube_dl/__init__.py | 1 + youtube_dl/extractor/common.py | 2 +- youtube_dl/options.py | 5 +++++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index dda222fee..e2ec55c90 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -233,6 +233,7 @@ class YoutubeDL(object): If it returns a message, the video is ignored. If it returns None, the video is downloaded. match_filter_func in utils.py is one example for this. + no_color: Do not emit color codes in output. The following parameters are not used by YoutubeDL itself, they are used by @@ -490,7 +491,7 @@ class YoutubeDL(object): else: if self.params.get('no_warnings'): return - if self._err_file.isatty() and os.name != 'nt': + if not self.params.get('no_color') and self._err_file.isatty() and os.name != 'nt': _msg_header = '\033[0;33mWARNING:\033[0m' else: _msg_header = 'WARNING:' @@ -502,7 +503,7 @@ class YoutubeDL(object): Do the same as trouble, but prefixes the message with 'ERROR:', colored in red if stderr is a tty file. ''' - if self._err_file.isatty() and os.name != 'nt': + if not self.params.get('no_color') and self._err_file.isatty() and os.name != 'nt': _msg_header = '\033[0;31mERROR:\033[0m' else: _msg_header = 'ERROR:' diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index eefca0fe4..ed22f169f 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -349,6 +349,7 @@ def _real_main(argv=None): 'playlist_items': opts.playlist_items, 'xattr_set_filesize': opts.xattr_set_filesize, 'match_filter': match_filter, + 'no_color': opts.no_color, } with YoutubeDL(ydl_opts) as ydl: diff --git a/youtube_dl/extractor/common.py b/youtube_dl/extractor/common.py index eee936a6f..382e846c5 100644 --- a/youtube_dl/extractor/common.py +++ b/youtube_dl/extractor/common.py @@ -514,7 +514,7 @@ class InfoExtractor(object): if mobj: break - if os.name != 'nt' and sys.stderr.isatty(): + if not self._downloader.params.get('no_color') and os.name != 'nt' and sys.stderr.isatty(): _name = '\033[0;34m%s\033[0m' % name else: _name = name diff --git a/youtube_dl/options.py b/youtube_dl/options.py index f64aa5b85..0219e6ba4 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -165,6 +165,11 @@ def parseOpts(overrideArguments=None): action='store_const', dest='extract_flat', const='in_playlist', default=False, help='Do not extract the videos of a playlist, only list them.') + general.add_option( + '--no-color', '--no-colors', + action='store_true', dest='no_color', + default=False, + help='Do not emit color codes in output.') network = optparse.OptionGroup(parser, 'Network Options') network.add_option( -- 2.22.2