# Path: build/plugin/src/resources/libraries/youtube_dl/downloader/external.py
# def list_external_downloaders():
#     return sorted(_BY_NAME.keys())
# 
# Path: build/plugin/src/resources/libraries/youtube_dl/compat.py
# def compat_expanduser(path):
#     """Expand ~ and ~user constructions.  If user or $HOME is unknown,
#     do nothing."""
#     if not path.startswith('~'):
#         return path
#     i = path.find('/', 1)
#     if i < 0:
#         i = len(path)
#     if i == 1:
#         if 'HOME' not in os.environ:
#             import pwd
#             userhome = pwd.getpwuid(os.getuid()).pw_dir
#         else:
#             userhome = compat_getenv('HOME')
#     else:
#         import pwd
#         try:
#             pwent = pwd.getpwnam(path[1:i])
#         except KeyError:
#             return path
#         userhome = pwent.pw_dir
#     userhome = userhome.rstrip('/')
#     return (userhome + path[i:]) or '/'
# 
# def compat_get_terminal_size(fallback=(80, 24)):
#     columns = compat_getenv('COLUMNS')
#     if columns:
#         columns = int(columns)
#     else:
#         columns = None
#     lines = compat_getenv('LINES')
#     if lines:
#         lines = int(lines)
#     else:
#         lines = None
# 
#     if columns is None or lines is None or columns <= 0 or lines <= 0:
#         try:
#             sp = subprocess.Popen(
#                 ['stty', 'size'],
#                 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#             out, err = sp.communicate()
#             _lines, _columns = map(int, out.split())
#         except Exception:
#             _columns, _lines = _terminal_size(*fallback)
# 
#         if columns is None or columns <= 0:
#             columns = _columns
#         if lines is None or lines <= 0:
#             lines = _lines
#     return _terminal_size(columns, lines)
# 
# def compat_getenv(key, default=None):
#     from .utils import get_filesystem_encoding
#     env = os.getenv(key, default)
#     if env:
#         env = env.decode(get_filesystem_encoding())
#     return env
# 
# def compat_kwargs(kwargs):
#     return dict((bytes(k), v) for k, v in kwargs.items())
# 
# def compat_shlex_split(s, comments=False, posix=True):
#     if isinstance(s, compat_str):
#         s = s.encode('utf-8')
#     return list(map(lambda s: s.decode('utf-8'), shlex.split(s, comments, posix)))
# 
# Path: build/plugin/src/resources/libraries/youtube_dl/utils.py
# def preferredencoding():
#     """Get preferred encoding.
# 
#     Returns the best encoding scheme for the system, based on
#     locale.getpreferredencoding() and some further tweaks.
#     """
#     try:
#         pref = locale.getpreferredencoding()
#         'TEST'.encode(pref)
#     except Exception:
#         pref = 'UTF-8'
# 
#     return pref
# 
# def write_string(s, out=None, encoding=None):
#     if out is None:
#         out = sys.stderr
#     assert type(s) == compat_str
# 
#     if sys.platform == 'win32' and encoding is None and hasattr(out, 'fileno'):
#         if _windows_write_string(s, out):
#             return
# 
#     if ('b' in getattr(out, 'mode', '')
#             or sys.version_info[0] < 3):  # Python 2 lies about mode of sys.stderr
#         byt = s.encode(encoding or preferredencoding(), 'ignore')
#         out.write(byt)
#     elif hasattr(out, 'buffer'):
#         enc = encoding or getattr(out, 'encoding', None) or preferredencoding()
#         byt = s.encode(enc, 'ignore')
#         out.buffer.write(byt)
#     else:
#         out.write(s)
#     out.flush()
# 
# Path: build/plugin/src/resources/libraries/youtube_dl/version.py



import os.path
import optparse
import re
import sys
from .downloader.external import list_external_downloaders
from .compat import (
    compat_expanduser,
    compat_get_terminal_size,
    compat_getenv,
    compat_kwargs,
    compat_shlex_split,
)
from .utils import (
    preferredencoding,
    write_string,
)
from .version import __version__
        help=optparse.SUPPRESS_HELP)
    downloader.add_option(
        '--playlist-reverse',
        action='store_true',
        help='Download playlist videos in reverse order')
    downloader.add_option(
        '--playlist-random',
        action='store_true',
        help='Download playlist videos in random order')
    downloader.add_option(
        '--xattr-set-filesize',
        dest='xattr_set_filesize', action='store_true',
        help='Set file xattribute ytdl.filesize with expected file size')
    downloader.add_option(
        '--hls-prefer-native',
        dest='hls_prefer_native', action='store_true', default=None,
        help='Use the native HLS downloader instead of ffmpeg')
    downloader.add_option(
        '--hls-prefer-ffmpeg',
        dest='hls_prefer_native', action='store_false', default=None,
        help='Use ffmpeg instead of the native HLS downloader')
    downloader.add_option(
        '--hls-use-mpegts',
        dest='hls_use_mpegts', action='store_true',
        help='Use the mpegts container for HLS videos, allowing to play the '
             'video while downloading (some players may not be able to play it)')
    downloader.add_option(
        '--external-downloader',
        dest='external_downloader', metavar='COMMAND',
        help='Use the specified external downloader. '

# Path: build/plugin/src/resources/libraries/youtube_dl/downloader/external.py
# def list_external_downloaders():
#     return sorted(_BY_NAME.keys())
# 
# Path: build/plugin/src/resources/libraries/youtube_dl/compat.py
# def compat_expanduser(path):
#     """Expand ~ and ~user constructions.  If user or $HOME is unknown,
#     do nothing."""
#     if not path.startswith('~'):
#         return path
#     i = path.find('/', 1)
#     if i < 0:
#         i = len(path)
#     if i == 1:
#         if 'HOME' not in os.environ:
#             import pwd
#             userhome = pwd.getpwuid(os.getuid()).pw_dir
#         else:
#             userhome = compat_getenv('HOME')
#     else:
#         import pwd
#         try:
#             pwent = pwd.getpwnam(path[1:i])
#         except KeyError:
#             return path
#         userhome = pwent.pw_dir
#     userhome = userhome.rstrip('/')
#     return (userhome + path[i:]) or '/'
# 
# def compat_get_terminal_size(fallback=(80, 24)):
#     columns = compat_getenv('COLUMNS')
#     if columns:
#         columns = int(columns)
#     else:
#         columns = None
#     lines = compat_getenv('LINES')
#     if lines:
#         lines = int(lines)
#     else:
#         lines = None
# 
#     if columns is None or lines is None or columns <= 0 or lines <= 0:
#         try:
#             sp = subprocess.Popen(
#                 ['stty', 'size'],
#                 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#             out, err = sp.communicate()
#             _lines, _columns = map(int, out.split())
#         except Exception:
#             _columns, _lines = _terminal_size(*fallback)
# 
#         if columns is None or columns <= 0:
#             columns = _columns
#         if lines is None or lines <= 0:
#             lines = _lines
#     return _terminal_size(columns, lines)
# 
# def compat_getenv(key, default=None):
#     from .utils import get_filesystem_encoding
#     env = os.getenv(key, default)
#     if env:
#         env = env.decode(get_filesystem_encoding())
#     return env
# 
# def compat_kwargs(kwargs):
#     return dict((bytes(k), v) for k, v in kwargs.items())
# 
# def compat_shlex_split(s, comments=False, posix=True):
#     if isinstance(s, compat_str):
#         s = s.encode('utf-8')
#     return list(map(lambda s: s.decode('utf-8'), shlex.split(s, comments, posix)))
# 
# Path: build/plugin/src/resources/libraries/youtube_dl/utils.py
# def preferredencoding():
#     """Get preferred encoding.
# 
#     Returns the best encoding scheme for the system, based on
#     locale.getpreferredencoding() and some further tweaks.
#     """
#     try:
#         pref = locale.getpreferredencoding()
#         'TEST'.encode(pref)
#     except Exception:
#         pref = 'UTF-8'
# 
#     return pref
# 
# def write_string(s, out=None, encoding=None):
#     if out is None:
#         out = sys.stderr
#     assert type(s) == compat_str
# 
#     if sys.platform == 'win32' and encoding is None and hasattr(out, 'fileno'):
#         if _windows_write_string(s, out):
#             return
# 
#     if ('b' in getattr(out, 'mode', '')
#             or sys.version_info[0] < 3):  # Python 2 lies about mode of sys.stderr
#         byt = s.encode(encoding or preferredencoding(), 'ignore')
#         out.write(byt)
#     elif hasattr(out, 'buffer'):
#         enc = encoding or getattr(out, 'encoding', None) or preferredencoding()
#         byt = s.encode(enc, 'ignore')
#         out.buffer.write(byt)
#     else:
#         out.write(s)
#     out.flush()
# 
# Path: build/plugin/src/resources/libraries/youtube_dl/version.py



# Path: build/plugin/src/resources/libraries/youtube_dl/options.py
import os.path
import optparse
import re
import sys
from .downloader.external import list_external_downloaders
from .compat import (
    compat_expanduser,
    compat_get_terminal_size,
    compat_getenv,
    compat_kwargs,
    compat_shlex_split,
)
from .utils import (
    preferredencoding,
    write_string,
)
from .version import __version__

        help=optparse.SUPPRESS_HELP)
    downloader.add_option(
        '--playlist-reverse',
        action='store_true',
        help='Download playlist videos in reverse order')
    downloader.add_option(
        '--playlist-random',
        action='store_true',
        help='Download playlist videos in random order')
    downloader.add_option(
        '--xattr-set-filesize',
        dest='xattr_set_filesize', action='store_true',
        help='Set file xattribute ytdl.filesize with expected file size')
    downloader.add_option(
        '--hls-prefer-native',
        dest='hls_prefer_native', action='store_true', default=None,
        help='Use the native HLS downloader instead of ffmpeg')
    downloader.add_option(
        '--hls-prefer-ffmpeg',
        dest='hls_prefer_native', action='store_false', default=None,
        help='Use ffmpeg instead of the native HLS downloader')
    downloader.add_option(
        '--hls-use-mpegts',
        dest='hls_use_mpegts', action='store_true',
        help='Use the mpegts container for HLS videos, allowing to play the '
             'video while downloading (some players may not be able to play it)')
    downloader.add_option(
        '--external-downloader',
        dest='external_downloader', metavar='COMMAND',
        help='Use the specified external downloader. '

             'Currently supports %s' % ','.join(list_external_downloaders()))