Skip to content

Commit

Permalink
Fix extra argument parsing
Browse files Browse the repository at this point in the history
Extra arguments for the downloader can be passed both as positional and
non-positional arguments.
This might seem a bit redundant however.
  • Loading branch information
glubsy committed Apr 9, 2023
1 parent f0d93f4 commit e636e07
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions save_livestream.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,33 +122,46 @@ def parse_args():
description=(
"Monitor a Twitch channel for any active live stream and record them"
),
epilog=(
"Extra arguments can be passed to streamlink. "
"This is useful to pass login token as to avoid mid-roll ads "
"which may corrupt the final output due to stream discontinuities. "
"Example: \"--twitch-api-header 'Authorization=OAuth <auth-token>'\""
)
epilog="Any extra positional argument will also be passed to the downloader."
)
parser.add_argument(
"--author-name", type=str,
help="The name of the channel's author for the output filename",
required=True
)
parser.add_argument(
"--downloader-args", action="append", type=str,
help=(
"Extra arguments can be passed to streamlink. "
"This is useful to pass login token as to avoid mid-roll ads "
"which may corrupt the final output due to stream discontinuities. "
"Example: \"--twitch-api-header 'Authorization=OAuth <auth-token>'\""
)
)
parser.add_argument(
"URI", metavar="URI",
help="The URI to the channel to monitor OR video to download",
)
args, extra = parser.parse_known_args()

args, unknown = parser.parse_known_args()

# Pre-parse and sanitize extra positional arguments to pass to downloader
if extra:
pextras = []
for extra_arg in extra:
pextras = []

def parse(arg_list):
for extra_arg in arg_list:
pextra = shlex(extra_arg)
pextra.whitespace_split = True
for _arg in list(pextra):
pextras.append(_arg.strip("'"))

if args.downloader_args:
parse(args.downloader_args)

# This is now a bit redundant with "--downloader-args"
if unknown:
parse(unknown)

return args, pextras


Expand Down

0 comments on commit e636e07

Please sign in to comment.