mirror of
https://github.com/ytdl-org/youtube-dl
synced 2024-12-23 04:30:10 +09:00
Use color when printing warning messages
This commit is contained in:
parent
691db5ba02
commit
8207626bbe
@ -104,7 +104,7 @@ class FileDownloader(object):
|
|||||||
self.params = params
|
self.params = params
|
||||||
|
|
||||||
if '%(stitle)s' in self.params['outtmpl']:
|
if '%(stitle)s' in self.params['outtmpl']:
|
||||||
self.to_stderr(u'WARNING: %(stitle)s is deprecated. Use the %(title)s and the --restrict-filenames flag(which also secures %(uploader)s et al) instead.')
|
self.report_warning(u'%(stitle)s is deprecated. Use the %(title)s and the --restrict-filenames flag(which also secures %(uploader)s et al) instead.')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def format_bytes(bytes):
|
def format_bytes(bytes):
|
||||||
@ -234,6 +234,18 @@ class FileDownloader(object):
|
|||||||
raise DownloadError(message)
|
raise DownloadError(message)
|
||||||
self._download_retcode = 1
|
self._download_retcode = 1
|
||||||
|
|
||||||
|
def report_warning(self, message):
|
||||||
|
'''
|
||||||
|
Print the message to stderr, it will be prefixed with 'WARNING:'
|
||||||
|
If stderr is a tty file the 'WARNING:' will be colored
|
||||||
|
'''
|
||||||
|
if sys.stderr.isatty():
|
||||||
|
_msg_header=u'\033[0;33mWARNING:\033[0m'
|
||||||
|
else:
|
||||||
|
_msg_header=u'WARNING:'
|
||||||
|
warning_message=u'%s %s' % (_msg_header,message)
|
||||||
|
self.to_stderr(warning_message)
|
||||||
|
|
||||||
def slow_down(self, start_time, byte_counter):
|
def slow_down(self, start_time, byte_counter):
|
||||||
"""Sleep if the download speed is over the rate limit."""
|
"""Sleep if the download speed is over the rate limit."""
|
||||||
rate_limit = self.params.get('ratelimit', None)
|
rate_limit = self.params.get('ratelimit', None)
|
||||||
@ -496,8 +508,8 @@ class FileDownloader(object):
|
|||||||
|
|
||||||
# Warn if the _WORKING attribute is False
|
# Warn if the _WORKING attribute is False
|
||||||
if not ie.working():
|
if not ie.working():
|
||||||
self.to_stderr(u'WARNING: the program functionality for this site has been marked as broken, '
|
self.report_warning(u'the program functionality for this site has been marked as broken, '
|
||||||
u'and will probably not work. If you want to go on, use the -i option.')
|
u'and will probably not work. If you want to go on, use the -i option.')
|
||||||
|
|
||||||
# Suitable InfoExtractor found
|
# Suitable InfoExtractor found
|
||||||
suitable_found = True
|
suitable_found = True
|
||||||
@ -555,7 +567,7 @@ class FileDownloader(object):
|
|||||||
self.to_screen(u'Deleting original file %s (pass -k to keep)' % filename)
|
self.to_screen(u'Deleting original file %s (pass -k to keep)' % filename)
|
||||||
os.remove(encodeFilename(filename))
|
os.remove(encodeFilename(filename))
|
||||||
except (IOError, OSError):
|
except (IOError, OSError):
|
||||||
self.to_stderr(u'WARNING: Unable to remove downloaded video file')
|
self.report_warning(u'Unable to remove downloaded video file')
|
||||||
|
|
||||||
def _download_with_rtmpdump(self, filename, url, player_url, page_url):
|
def _download_with_rtmpdump(self, filename, url, player_url, page_url):
|
||||||
self.report_destination(filename)
|
self.report_destination(filename)
|
||||||
|
Loading…
Reference in New Issue
Block a user