A feature-rich command-line audio/video downloader
[jython] Introduce compat_os_name
Yen Chi Hsuane9c0cdd38954
diff --git a/test/helper.py b/test/helper.pyindex bdd7acca4d..f2d8782129 100644--- a/test/helper.py+++ b/test/helper.py@@ -11,8 +11,11 @@ import sysimport youtube_dl.extractorfrom youtube_dl import YoutubeDL-from youtube_dl.utils import (+from youtube_dl.compat import (+ compat_os_name,compat_str,+)+from youtube_dl.utils import (preferredencoding,write_string,)@@ -42,7 +45,7 @@ def report_warning(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() and os.name != 'nt':+ if sys.stderr.isatty() and compat_os_name != 'nt':_msg_header = '\033[0;33mWARNING:\033[0m'else:_msg_header = 'WARNING:'diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.pyindex 8f3a8b9e30..dcc867e456 100755--- a/youtube_dl/YoutubeDL.py+++ b/youtube_dl/YoutubeDL.py@@ -24,9 +24,6 @@ import timeimport tokenizeimport traceback-if os.name == 'nt':- import ctypes-from .compat import (compat_basestring,compat_cookiejar,@@ -34,6 +31,7 @@ from .compat import (compat_get_terminal_size,compat_http_client,compat_kwargs,+ compat_os_name,compat_str,compat_tokenize_tokenize,compat_urllib_error,@@ -95,6 +93,9 @@ from .postprocessor import ()from .version import __version__+if compat_os_name == 'nt':+ import ctypes+class YoutubeDL(object):"""YoutubeDL class.@@ -450,7 +451,7 @@ class YoutubeDL(object):def to_console_title(self, message):if not self.params.get('consoletitle', False):return- if os.name == 'nt' and ctypes.windll.kernel32.GetConsoleWindow():+ if compat_os_name == 'nt' and ctypes.windll.kernel32.GetConsoleWindow():# c_wchar_p() might not be necessary if `message` is# already of type unicode()ctypes.windll.kernel32.SetConsoleTitleW(ctypes.c_wchar_p(message))@@ -521,7 +522,7 @@ class YoutubeDL(object):else:if self.params.get('no_warnings'):return- if not self.params.get('no_color') and self._err_file.isatty() and os.name != 'nt':+ if not self.params.get('no_color') and self._err_file.isatty() and compat_os_name != 'nt':_msg_header = '\033[0;33mWARNING:\033[0m'else:_msg_header = 'WARNING:'@@ -533,7 +534,7 @@ class YoutubeDL(object):Do the same as trouble, but prefixes the message with 'ERROR:', coloredin red if stderr is a tty file.'''- if not self.params.get('no_color') and self._err_file.isatty() and os.name != 'nt':+ if not self.params.get('no_color') and self._err_file.isatty() and compat_os_name != 'nt':_msg_header = '\033[0;31mERROR:\033[0m'else:_msg_header = 'ERROR:'diff --git a/youtube_dl/compat.py b/youtube_dl/compat.pyindex b497da6964..2771fb5faa 100644--- a/youtube_dl/compat.py+++ b/youtube_dl/compat.py@@ -326,6 +326,9 @@ def compat_ord(c):return ord(c)+compat_os_name = os._name if os.name == 'java' else os.name++if sys.version_info >= (3, 0):compat_getenv = os.getenvcompat_expanduser = os.path.expanduser@@ -346,7 +349,7 @@ else:# The following are os.path.expanduser implementations from cpython 2.7.8 stdlib# for different platforms with correct environment variables decoding.- if os.name == 'posix':+ if compat_os_name == 'posix':def compat_expanduser(path):"""Expand ~ and ~user constructions. If user or $HOME is unknown,do nothing."""@@ -370,7 +373,7 @@ else:userhome = pwent.pw_diruserhome = userhome.rstrip('/')return (userhome + path[i:]) or '/'- elif os.name == 'nt' or os.name == 'ce':+ elif compat_os_name == 'nt' or compat_os_name == 'ce':def compat_expanduser(path):"""Expand ~ and ~user constructs.@@ -556,6 +559,7 @@ __all__ = ['compat_itertools_count','compat_kwargs','compat_ord',+ 'compat_os_name','compat_parse_qs','compat_print','compat_shlex_split',diff --git a/youtube_dl/downloader/common.py b/youtube_dl/downloader/common.pyindex 2d51540518..f39db58f6c 100644--- a/youtube_dl/downloader/common.py+++ b/youtube_dl/downloader/common.py@@ -5,6 +5,7 @@ import reimport sysimport time+from ..compat import compat_os_namefrom ..utils import (encodeFilename,error_to_compat_str,@@ -219,7 +220,7 @@ class FileDownloader(object):if self.params.get('progress_with_newline', False):self.to_screen(fullmsg)else:- if os.name == 'nt':+ if compat_os_name == 'nt':prev_len = getattr(self, '_report_progress_prev_line_length',0)if prev_len > len(fullmsg):diff --git a/youtube_dl/extractor/common.py b/youtube_dl/extractor/common.pyindex 402f2f436d..07bd2cbe2f 100644--- a/youtube_dl/extractor/common.py+++ b/youtube_dl/extractor/common.py@@ -15,13 +15,14 @@ import mathfrom ..compat import (compat_cookiejar,compat_cookies,+ compat_etree_fromstring,compat_getpass,compat_http_client,+ compat_os_name,+ compat_str,compat_urllib_error,compat_urllib_parse,compat_urlparse,- compat_str,- compat_etree_fromstring,)from ..utils import (NO_DEFAULT,@@ -427,7 +428,7 @@ class InfoExtractor(object):self.to_screen('Saving request to ' + filename)# Working around MAX_PATH limitation on Windows (see# http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx)- if os.name == 'nt':+ if compat_os_name == 'nt':absfilepath = os.path.abspath(filename)if len(absfilepath) > 259:filename = '\\\\?\\' + absfilepath@@ -596,7 +597,7 @@ class InfoExtractor(object):if mobj:break- if not self._downloader.params.get('no_color') and os.name != 'nt' and sys.stderr.isatty():+ if not self._downloader.params.get('no_color') and compat_os_name != 'nt' and sys.stderr.isatty():_name = '\033[0;34m%s\033[0m' % nameelse:_name = namediff --git a/youtube_dl/postprocessor/xattrpp.py b/youtube_dl/postprocessor/xattrpp.pyindex 480d48d057..e39ca60aa0 100644--- a/youtube_dl/postprocessor/xattrpp.py+++ b/youtube_dl/postprocessor/xattrpp.py@@ -6,6 +6,7 @@ import sysimport errnofrom .common import PostProcessor+from ..compat import compat_os_namefrom ..utils import (check_executable,hyphenate_date,@@ -73,7 +74,7 @@ class XAttrMetadataPP(PostProcessor):raise XAttrMetadataError(e.errno, e.strerror)except ImportError:- if os.name == 'nt':+ if compat_os_name == 'nt':# Write xattrs to NTFS Alternate Data Streams:# http://en.wikipedia.org/wiki/NTFS#Alternate_data_streams_.28ADS.29def write_xattr(path, key, value):@@ -168,7 +169,7 @@ class XAttrMetadataPP(PostProcessor):'Unable to write extended attributes due to too long values.')else:msg = 'This filesystem doesn\'t support extended attributes. '- if os.name == 'nt':+ if compat_os_name == 'nt':msg += 'You need to use NTFS.'else:msg += '(You may have to enable them in your /etc/fstab)'