mirror of
				https://github.com/ytdl-org/youtube-dl.git
				synced 2025-10-29 09:26:20 -07:00 
			
		
		
		
	[jython] Introduce compat_os_name
os.name is always 'java' on Jython
This commit is contained in:
		| @@ -11,8 +11,11 @@ import sys | |||||||
|  |  | ||||||
| import youtube_dl.extractor | import youtube_dl.extractor | ||||||
| from youtube_dl import YoutubeDL | from youtube_dl import YoutubeDL | ||||||
| from youtube_dl.utils import ( | from youtube_dl.compat import ( | ||||||
|  |     compat_os_name, | ||||||
|     compat_str, |     compat_str, | ||||||
|  | ) | ||||||
|  | from youtube_dl.utils import ( | ||||||
|     preferredencoding, |     preferredencoding, | ||||||
|     write_string, |     write_string, | ||||||
| ) | ) | ||||||
| @@ -42,7 +45,7 @@ def report_warning(message): | |||||||
|     Print the message to stderr, it will be prefixed with 'WARNING:' |     Print the message to stderr, it will be prefixed with 'WARNING:' | ||||||
|     If stderr is a tty file the 'WARNING:' will be colored |     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' |         _msg_header = '\033[0;33mWARNING:\033[0m' | ||||||
|     else: |     else: | ||||||
|         _msg_header = 'WARNING:' |         _msg_header = 'WARNING:' | ||||||
|   | |||||||
| @@ -24,9 +24,6 @@ import time | |||||||
| import tokenize | import tokenize | ||||||
| import traceback | import traceback | ||||||
|  |  | ||||||
| if os.name == 'nt': |  | ||||||
|     import ctypes |  | ||||||
|  |  | ||||||
| from .compat import ( | from .compat import ( | ||||||
|     compat_basestring, |     compat_basestring, | ||||||
|     compat_cookiejar, |     compat_cookiejar, | ||||||
| @@ -34,6 +31,7 @@ from .compat import ( | |||||||
|     compat_get_terminal_size, |     compat_get_terminal_size, | ||||||
|     compat_http_client, |     compat_http_client, | ||||||
|     compat_kwargs, |     compat_kwargs, | ||||||
|  |     compat_os_name, | ||||||
|     compat_str, |     compat_str, | ||||||
|     compat_tokenize_tokenize, |     compat_tokenize_tokenize, | ||||||
|     compat_urllib_error, |     compat_urllib_error, | ||||||
| @@ -95,6 +93,9 @@ from .postprocessor import ( | |||||||
| ) | ) | ||||||
| from .version import __version__ | from .version import __version__ | ||||||
|  |  | ||||||
|  | if compat_os_name == 'nt': | ||||||
|  |     import ctypes | ||||||
|  |  | ||||||
|  |  | ||||||
| class YoutubeDL(object): | class YoutubeDL(object): | ||||||
|     """YoutubeDL class. |     """YoutubeDL class. | ||||||
| @@ -450,7 +451,7 @@ class YoutubeDL(object): | |||||||
|     def to_console_title(self, message): |     def to_console_title(self, message): | ||||||
|         if not self.params.get('consoletitle', False): |         if not self.params.get('consoletitle', False): | ||||||
|             return |             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 |             # c_wchar_p() might not be necessary if `message` is | ||||||
|             # already of type unicode() |             # already of type unicode() | ||||||
|             ctypes.windll.kernel32.SetConsoleTitleW(ctypes.c_wchar_p(message)) |             ctypes.windll.kernel32.SetConsoleTitleW(ctypes.c_wchar_p(message)) | ||||||
| @@ -521,7 +522,7 @@ class YoutubeDL(object): | |||||||
|         else: |         else: | ||||||
|             if self.params.get('no_warnings'): |             if self.params.get('no_warnings'): | ||||||
|                 return |                 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' |                 _msg_header = '\033[0;33mWARNING:\033[0m' | ||||||
|             else: |             else: | ||||||
|                 _msg_header = 'WARNING:' |                 _msg_header = 'WARNING:' | ||||||
| @@ -533,7 +534,7 @@ class YoutubeDL(object): | |||||||
|         Do the same as trouble, but prefixes the message with 'ERROR:', colored |         Do the same as trouble, but prefixes the message with 'ERROR:', colored | ||||||
|         in red if stderr is a tty file. |         in 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' |             _msg_header = '\033[0;31mERROR:\033[0m' | ||||||
|         else: |         else: | ||||||
|             _msg_header = 'ERROR:' |             _msg_header = 'ERROR:' | ||||||
|   | |||||||
| @@ -326,6 +326,9 @@ def compat_ord(c): | |||||||
|         return ord(c) |         return ord(c) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | compat_os_name = os._name if os.name == 'java' else os.name | ||||||
|  |  | ||||||
|  |  | ||||||
| if sys.version_info >= (3, 0): | if sys.version_info >= (3, 0): | ||||||
|     compat_getenv = os.getenv |     compat_getenv = os.getenv | ||||||
|     compat_expanduser = os.path.expanduser |     compat_expanduser = os.path.expanduser | ||||||
| @@ -346,7 +349,7 @@ else: | |||||||
|     # The following are os.path.expanduser implementations from cpython 2.7.8 stdlib |     # The following are os.path.expanduser implementations from cpython 2.7.8 stdlib | ||||||
|     # for different platforms with correct environment variables decoding. |     # for different platforms with correct environment variables decoding. | ||||||
|  |  | ||||||
|     if os.name == 'posix': |     if compat_os_name == 'posix': | ||||||
|         def compat_expanduser(path): |         def compat_expanduser(path): | ||||||
|             """Expand ~ and ~user constructions.  If user or $HOME is unknown, |             """Expand ~ and ~user constructions.  If user or $HOME is unknown, | ||||||
|             do nothing.""" |             do nothing.""" | ||||||
| @@ -370,7 +373,7 @@ else: | |||||||
|                 userhome = pwent.pw_dir |                 userhome = pwent.pw_dir | ||||||
|             userhome = userhome.rstrip('/') |             userhome = userhome.rstrip('/') | ||||||
|             return (userhome + path[i:]) or '/' |             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): |         def compat_expanduser(path): | ||||||
|             """Expand ~ and ~user constructs. |             """Expand ~ and ~user constructs. | ||||||
|  |  | ||||||
| @@ -556,6 +559,7 @@ __all__ = [ | |||||||
|     'compat_itertools_count', |     'compat_itertools_count', | ||||||
|     'compat_kwargs', |     'compat_kwargs', | ||||||
|     'compat_ord', |     'compat_ord', | ||||||
|  |     'compat_os_name', | ||||||
|     'compat_parse_qs', |     'compat_parse_qs', | ||||||
|     'compat_print', |     'compat_print', | ||||||
|     'compat_shlex_split', |     'compat_shlex_split', | ||||||
|   | |||||||
| @@ -5,6 +5,7 @@ import re | |||||||
| import sys | import sys | ||||||
| import time | import time | ||||||
|  |  | ||||||
|  | from ..compat import compat_os_name | ||||||
| from ..utils import ( | from ..utils import ( | ||||||
|     encodeFilename, |     encodeFilename, | ||||||
|     error_to_compat_str, |     error_to_compat_str, | ||||||
| @@ -219,7 +220,7 @@ class FileDownloader(object): | |||||||
|         if self.params.get('progress_with_newline', False): |         if self.params.get('progress_with_newline', False): | ||||||
|             self.to_screen(fullmsg) |             self.to_screen(fullmsg) | ||||||
|         else: |         else: | ||||||
|             if os.name == 'nt': |             if compat_os_name == 'nt': | ||||||
|                 prev_len = getattr(self, '_report_progress_prev_line_length', |                 prev_len = getattr(self, '_report_progress_prev_line_length', | ||||||
|                                    0) |                                    0) | ||||||
|                 if prev_len > len(fullmsg): |                 if prev_len > len(fullmsg): | ||||||
|   | |||||||
| @@ -15,13 +15,14 @@ import math | |||||||
| from ..compat import ( | from ..compat import ( | ||||||
|     compat_cookiejar, |     compat_cookiejar, | ||||||
|     compat_cookies, |     compat_cookies, | ||||||
|  |     compat_etree_fromstring, | ||||||
|     compat_getpass, |     compat_getpass, | ||||||
|     compat_http_client, |     compat_http_client, | ||||||
|  |     compat_os_name, | ||||||
|  |     compat_str, | ||||||
|     compat_urllib_error, |     compat_urllib_error, | ||||||
|     compat_urllib_parse, |     compat_urllib_parse, | ||||||
|     compat_urlparse, |     compat_urlparse, | ||||||
|     compat_str, |  | ||||||
|     compat_etree_fromstring, |  | ||||||
| ) | ) | ||||||
| from ..utils import ( | from ..utils import ( | ||||||
|     NO_DEFAULT, |     NO_DEFAULT, | ||||||
| @@ -427,7 +428,7 @@ class InfoExtractor(object): | |||||||
|             self.to_screen('Saving request to ' + filename) |             self.to_screen('Saving request to ' + filename) | ||||||
|             # Working around MAX_PATH limitation on Windows (see |             # Working around MAX_PATH limitation on Windows (see | ||||||
|             # http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx) |             # 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) |                 absfilepath = os.path.abspath(filename) | ||||||
|                 if len(absfilepath) > 259: |                 if len(absfilepath) > 259: | ||||||
|                     filename = '\\\\?\\' + absfilepath |                     filename = '\\\\?\\' + absfilepath | ||||||
| @@ -596,7 +597,7 @@ class InfoExtractor(object): | |||||||
|                 if mobj: |                 if mobj: | ||||||
|                     break |                     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' % name |             _name = '\033[0;34m%s\033[0m' % name | ||||||
|         else: |         else: | ||||||
|             _name = name |             _name = name | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ import sys | |||||||
| import errno | import errno | ||||||
|  |  | ||||||
| from .common import PostProcessor | from .common import PostProcessor | ||||||
|  | from ..compat import compat_os_name | ||||||
| from ..utils import ( | from ..utils import ( | ||||||
|     check_executable, |     check_executable, | ||||||
|     hyphenate_date, |     hyphenate_date, | ||||||
| @@ -73,7 +74,7 @@ class XAttrMetadataPP(PostProcessor): | |||||||
|                     raise XAttrMetadataError(e.errno, e.strerror) |                     raise XAttrMetadataError(e.errno, e.strerror) | ||||||
|  |  | ||||||
|         except ImportError: |         except ImportError: | ||||||
|             if os.name == 'nt': |             if compat_os_name == 'nt': | ||||||
|                 # Write xattrs to NTFS Alternate Data Streams: |                 # Write xattrs to NTFS Alternate Data Streams: | ||||||
|                 # http://en.wikipedia.org/wiki/NTFS#Alternate_data_streams_.28ADS.29 |                 # http://en.wikipedia.org/wiki/NTFS#Alternate_data_streams_.28ADS.29 | ||||||
|                 def write_xattr(path, key, value): |                 def write_xattr(path, key, value): | ||||||
| @@ -168,7 +169,7 @@ class XAttrMetadataPP(PostProcessor): | |||||||
|                     'Unable to write extended attributes due to too long values.') |                     'Unable to write extended attributes due to too long values.') | ||||||
|             else: |             else: | ||||||
|                 msg = 'This filesystem doesn\'t support extended attributes. ' |                 msg = 'This filesystem doesn\'t support extended attributes. ' | ||||||
|                 if os.name == 'nt': |                 if compat_os_name == 'nt': | ||||||
|                     msg += 'You need to use NTFS.' |                     msg += 'You need to use NTFS.' | ||||||
|                 else: |                 else: | ||||||
|                     msg += '(You may have to enable them in your /etc/fstab)' |                     msg += '(You may have to enable them in your /etc/fstab)' | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user