diff --git a/contrib/completion/_you-get b/contrib/completion/_you-get deleted file mode 100644 index 696aad89..00000000 --- a/contrib/completion/_you-get +++ /dev/null @@ -1,29 +0,0 @@ -#compdef you-get - -# Zsh completion definition for soimort/you-get. - -setopt localoptions noshwordsplit noksharrays -local -a args - -args=( - '(- : *)'{-V,--version}'[print version and exit]' - '(- : *)'{-h,--help}'[print help and exit]' - '(-i --info)'{-i,--info}'[print extracted information]' - '(-u --url)'{-u,--url}'[print extracted information with URLs]' - '(--json)--json[print extracted URLs in JSON format]' - '(-n --no-merge)'{-n,--no-merge}'[do not merge video parts]' - '(--no-caption)--no-caption[do not download captions]' - '(-f --force)'{-f,--force}'[force overwrite existing files]' - '(-F --format)'{-F,--format}'[set video format to the specified stream id]:stream id' - '(-O --output-filename)'{-O,--output-filename}'[set output filename]:filename:_files' - '(-o --output-dir)'{-o,--output-dir}'[set output directory]:directory:_files -/' - '(-p --player)'{-p,--player}'[stream extracted URL to the specified player]:player and options' - '(-c --cookies)'{-c,--cookies}'[load cookies.txt or cookies.sqlite]:cookies file:_files' - '(-x --http-proxy)'{-x,--http-proxy}'[use the specified HTTP proxy for downloading]:host\:port:' - '(-y --extractor-proxy)'{-y,--extractor-proxy}'[use the specified HTTP proxy for extraction only]:host\:port' - '(--no-proxy)--no-proxy[do not use a proxy]' - '(-t --timeout)'{-t,--timeout}'[set socket timeout]:seconds' - '(-d --debug)'{-d,--debug}'[show traceback and other debug info]' - '*: :_guard "^-*" url' -) -_arguments -S -s $args diff --git a/contrib/completion/you-get-completion.bash b/contrib/completion/you-get-completion.bash deleted file mode 100755 index 9c6480ec..00000000 --- a/contrib/completion/you-get-completion.bash +++ /dev/null @@ -1,31 +0,0 @@ -# Bash completion definition for you-get. - -_you-get () { - COMPREPLY=() - local IFS=$' \n' - local cur=$2 prev=$3 - local -a opts_without_arg opts_with_arg - opts_without_arg=( - -V --version -h --help -i --info -u --url --json -n --no-merge - --no-caption -f --force --no-proxy -d --debug - ) - opts_with_arg=( - -F --format -O --output-filename -o --output-dir -p --player - -c --cookies -x --http-proxy -y --extractor-proxy -t --timeout - ) - - # Do not complete non option names - [[ $cur == -* ]] || return 1 - - # Do not complete when the previous arg is an option expecting an argument - for opt in "${opts_with_arg[@]}"; do - [[ $opt == $prev ]] && return 1 - done - - # Complete option names - COMPREPLY=( $(compgen -W "${opts_without_arg[*]} ${opts_with_arg[*]}" \ - -- "$cur") ) - return 0 -} - -complete -F _you-get you-get diff --git a/setup.py b/setup.py index 24dc9fb2..91c95f80 100755 --- a/setup.py +++ b/setup.py @@ -43,6 +43,7 @@ setup( entry_points = {'console_scripts': proj_info['console_scripts']}, + install_requires=["shtab"], extras_require={ 'socks': ['PySocks'], } diff --git a/src/you_get/common.py b/src/you_get/common.py index c5c19d01..963c43b8 100755 --- a/src/you_get/common.py +++ b/src/you_get/common.py @@ -15,6 +15,7 @@ from http import cookiejar from importlib import import_module from urllib import request, parse, error +import shtab from .version import __version__ from .util import log, term from .util.git import get_version @@ -125,6 +126,23 @@ SITES = { 'zhibo' : 'zhibo', 'zhihu' : 'zhihu', } +URL = { + "zsh": "_urls", +} +HOST = { + "zsh": "_hosts", +} +HOST_USER = { + "zsh": "_hosts_users", +} +# https://github.com/zsh-users/zsh/blob/master/Etc/completion-style-guide#L320-L323 +PREAMBLE = { + "zsh": """\ +_hosts_users() { + _alternative 'hosts: :_hosts' 'users: :_users' +} +""", +} dry_run = False json_output = False @@ -1525,6 +1543,7 @@ def script_main(download, download_playlist, **kwargs): description='A tiny downloader that scrapes the web', add_help=False, ) + shtab.add_argument_to(parser, preamble=PREAMBLE) parser.add_argument( '-V', '--version', action='store_true', help='Print version and exit' @@ -1544,7 +1563,7 @@ def script_main(download, download_playlist, **kwargs): dry_run_grp.add_argument( '-u', '--url', action='store_true', help='Print extracted information with URLs' - ) + ).complete = URL dry_run_grp.add_argument( '--json', action='store_true', help='Print extracted URLs in JSON format' @@ -1577,11 +1596,11 @@ def script_main(download, download_playlist, **kwargs): ) download_grp.add_argument( '-O', '--output-filename', metavar='FILE', help='Set output filename' - ) + ).complete = shtab.FILE download_grp.add_argument( '-o', '--output-dir', metavar='DIR', default='.', help='Set output directory' - ) + ).complete = shtab.DIR download_grp.add_argument( '-p', '--player', metavar='PLAYER', help='Stream extracted URL to a PLAYER' @@ -1589,7 +1608,7 @@ def script_main(download, download_playlist, **kwargs): download_grp.add_argument( '-c', '--cookies', metavar='COOKIES_FILE', help='Load cookies.txt or cookies.sqlite' - ) + ).complete = shtab.FILE download_grp.add_argument( '-t', '--timeout', metavar='SECONDS', type=int, default=600, help='Set socket timeout' @@ -1601,7 +1620,7 @@ def script_main(download, download_playlist, **kwargs): download_grp.add_argument( '-I', '--input-file', metavar='FILE', type=argparse.FileType('r'), help='Read non-playlist URLs from FILE' - ) + ).complete = shtab.FILE download_grp.add_argument( '-P', '--password', help='Set video visit password to PASSWORD' ) @@ -1639,18 +1658,18 @@ def script_main(download, download_playlist, **kwargs): proxy_grp.add_argument( '-x', '--http-proxy', metavar='HOST:PORT', help='Use an HTTP proxy for downloading' - ) + ).complete = HOST proxy_grp.add_argument( '-y', '--extractor-proxy', metavar='HOST:PORT', help='Use an HTTP proxy for extracting only' - ) + ).complete = HOST proxy_grp.add_argument( '--no-proxy', action='store_true', help='Never use a proxy' ) proxy_grp.add_argument( '-s', '--socks-proxy', metavar='HOST:PORT or USERNAME:PASSWORD@HOST:PORT', help='Use an SOCKS5 proxy for downloading' - ) + ).complete = HOST_USER download_grp.add_argument('--stream', help=argparse.SUPPRESS) download_grp.add_argument('--itag', help=argparse.SUPPRESS) @@ -1659,7 +1678,7 @@ def script_main(download, download_playlist, **kwargs): help = 'download video using an m3u8 url') - parser.add_argument('URL', nargs='*', help=argparse.SUPPRESS) + parser.add_argument('URL', nargs='*').complete = URL args = parser.parse_args()