Streamlink: Parsing issue in --player-args

Created on 31 May 2017  路  3Comments  路  Source: streamlink/streamlink

Checklist

  • [x] This is a bug report.
  • [ ] This is a feature request.
  • [ ] This is a plugin (improvement) request.
  • [ ] I have read the contribution guidelines.

Description

Original bug report by @404NetworkError here:
streamlink/streamlink-twitch-gui#464

Streamlink is exiting with an error if the first argument of the --player-args param is a single hyphen parameter. Defining the same player parameters in the --player param is working fine.

Environment details

Operating system and version: tested on Linux, MacOS and Windows
Streamlink and Python version: latest

Comments, logs, screenshots, etc.

# just some example commands that don't necessarily make sense

# single hyphen params at the beginning of --player-args are not working
$ streamlink -p vlc -a "-v {filename}" twitch.tv/CHANNEL best
usage: streamlink [OPTIONS] <URL> [STREAM]
streamlink: error: argument -a/--player-args: expected one argument

# no hyphen params at the beginning of --player-args are working fine
$ streamlink -p vlc -a "v {filename}" twitch.tv/CHANNEL best
[cli][info] Found matching plugin twitch for URL twitch.tv/CHANNEL
^CInterrupted! Exiting...

# double hyphen params at the beginning of --player-args are working fine
$ streamlink -p vlc -a "--v {filename}" twitch.tv/CHANNEL best
[cli][info] Found matching plugin twitch for URL twitch.tv/CHANNEL
^CInterrupted! Exiting...

# Windows style params at the beginning of --player-args are working fine
$ streamlink -p vlc -a "/v {filename}" twitch.tv/CHANNEL best
[cli][info] Found matching plugin twitch for URL twitch.tv/CHANNEL
^CInterrupted! Exiting...
bug dependency issue

Most helpful comment

This is a limitation of argparse. It can be worked around by using a = to set the value.
eg. -a="-v {filename}" or --player-args="-v {filename}".

Here is a small snippet to recreate the issue:

import argparse
args = argparse.ArgumentParser()
args.add_argument("-t", "--test")
print(args.parse_args())

There was a bug report raised around 10 years ago for this issue :)

All 3 comments

This is a limitation of argparse. It can be worked around by using a = to set the value.
eg. -a="-v {filename}" or --player-args="-v {filename}".

Here is a small snippet to recreate the issue:

import argparse
args = argparse.ArgumentParser()
args.add_argument("-t", "--test")
print(args.parse_args())

There was a bug report raised around 10 years ago for this issue :)

the last message on the bug report has a workaround https://bugs.python.org/issue9334

not sure if there is any downside of it.

$ streamlink -p vlc -a "-v {filename}" twitch.tv/CHANNEL best -l info
[cli][info] Found matching plugin twitch for URL twitch.tv/CHANNEL

diff between master 3.7 and patch
https://gist.github.com/back-to/d940a2273a7e58152f4fb9fca79cf454/revisions#diff-df389dc0f92c4a0567555d1f96ff2bf9

master 3.7
https://github.com/python/cpython/blob/3.7/Lib/argparse.py#L2065-L2084

patch
https://bugs.python.org/file47404/argparse_opt.py

@back-to that might work for us.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ahtcx picture ahtcx  路  3Comments

JohnDoh666 picture JohnDoh666  路  3Comments

hpmueller1971 picture hpmueller1971  路  3Comments

Tikounet picture Tikounet  路  3Comments

gravyboat picture gravyboat  路  3Comments