aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/FileDownloader.py
diff options
context:
space:
mode:
authorJaime Marquínez Ferrándiz <jaimemf93@gmail.com>2013-03-04 22:25:46 +0100
committerJaime Marquínez Ferrándiz <jaimemf93@gmail.com>2013-03-04 22:25:46 +0100
commit3370abd509d5b68e22218f07f0aa43cdf16ff2f8 (patch)
tree0279dc1e5befbf3053c86db0d88bae3569d268a7 /youtube_dl/FileDownloader.py
parent631f73978c0ee851950ac697dfd73f9092abd3c3 (diff)
parent967897fd227c85ebe3368b359a4f8c471e513de6 (diff)
Merge branch 'master' into extract_info_rewrite
Diffstat (limited to 'youtube_dl/FileDownloader.py')
-rw-r--r--youtube_dl/FileDownloader.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/youtube_dl/FileDownloader.py b/youtube_dl/FileDownloader.py
index f668b362b..9b630c123 100644
--- a/youtube_dl/FileDownloader.py
+++ b/youtube_dl/FileDownloader.py
@@ -104,7 +104,7 @@ class FileDownloader(object):
self.params = params
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
def format_bytes(bytes):
@@ -234,6 +234,18 @@ class FileDownloader(object):
raise DownloadError(message)
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):
"""Sleep if the download speed is over the rate limit."""
rate_limit = self.params.get('ratelimit', None)
@@ -566,7 +578,7 @@ class FileDownloader(object):
self.to_screen(u'Deleting original file %s (pass -k to keep)' % filename)
os.remove(encodeFilename(filename))
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):
self.report_destination(filename)
@@ -574,7 +586,7 @@ class FileDownloader(object):
# Check for rtmpdump first
try:
- subprocess.call(['rtmpdump', '-h'], stdout=(file(os.path.devnull, 'w')), stderr=subprocess.STDOUT)
+ subprocess.call(['rtmpdump', '-h'], stdout=(open(os.path.devnull, 'w')), stderr=subprocess.STDOUT)
except (OSError, IOError):
self.trouble(u'ERROR: RTMP download detected but "rtmpdump" could not be run')
return False