chat-downloader icon indicating copy to clipboard operation
chat-downloader copied to clipboard

[BUG] Filename string after --output cannot begin with dash(-) due to mis-interpretated as option

Open teadrinker2015 opened this issue 1 year ago • 5 comments

Basic information

  • Program version: 0.2.8
  • Python version: Python 3.10.8
  • Operating system: Windows 10 22H2

Describe the bug

Filename string after --output cannot begin with dash(-) due to mis-interpretated as option.

Command/Code used

If running from the command line, provide the following:

  1. The command used (including the verbose tag, -v):
chat_downloader https://www.youtube.com/watch?v=-ZLltnPt5WM -o '-ZLltnPt5WM.json' -q
  1. Output from the above command:
usage: chat_downloader [-h] [--version] [--start_time START_TIME] [--end_time END_TIME]
                       [--message_types MESSAGE_TYPES | --message_groups MESSAGE_GROUPS] [--max_attempts MAX_ATTEMPTS]
                       [--retry_timeout RETRY_TIMEOUT] [--interruptible_retry [INTERRUPTIBLE_RETRY]]
                       [--max_messages MAX_MESSAGES] [--inactivity_timeout INACTIVITY_TIMEOUT] [--timeout TIMEOUT]
                       [--format FORMAT] [--format_file FORMAT_FILE] [--chat_type {live,top}] [--ignore IGNORE]
                       [--message_receive_timeout MESSAGE_RECEIVE_TIMEOUT] [--buffer_size BUFFER_SIZE]
                       [--output OUTPUT] [--overwrite [OVERWRITE]] [--sort_keys [SORT_KEYS]] [--indent INDENT]
                       [--pause_on_debug | --exit_on_debug]
                       [--logging {none,debug,info,warning,error,critical} | --testing | --verbose | --quiet]
                       [--cookies COOKIES] [--proxy PROXY]
                       url
chat_downloader: error: argument --output/-o: expected one argument

Expected behavior

silently exits (success)

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context/information

Add any other context or information about the problem here.

teadrinker2015 avatar Jan 19 '24 09:01 teadrinker2015

Can you try surrounding the arguments with double quotes? e.g.,

chat_downloader "https://www.youtube.com/watch?v=-ZLltnPt5WM" -o "-ZLltnPt5WM.json" -q

xenova avatar Jan 19 '24 10:01 xenova

Forgot to mention, I'm using powershell. Neither single nor double quotes work. Only single quotes on windows command-line shell worked as expected.

PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.10
PSEdition                      Core
GitCommitId                    7.3.10
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

teadrinker2015 avatar Jan 19 '24 10:01 teadrinker2015

In that case, can you try:

  1. appending a space to the beginning of the video id: ' -ZLltnPt5WM.json'
  2. escape the dash (I'm not sure how, perhaps \?

xenova avatar Jan 19 '24 10:01 xenova

In that case, can you try:

  1. appending a space to the beginning of the video id: ' -ZLltnPt5WM.json'

Adding space will result in a space in actual filename, but bypass this problem successfully. My version of Windows dosen't trim leading space in filenames perhaps.

  1. escape the dash (I'm not sure how, perhaps \?

After test, '`-ZLltnPt5WM.json' will also result in a leading `, And other pattern "`-ZLltnPt5WM.json" will fail.

teadrinker2015 avatar Jan 19 '24 16:01 teadrinker2015

I think we're hitting a limitation in argparse... The best approach is probably to use one of the following alternatives instead:

  • --output=-ZLltnPt5WM.json
  • -o=-ZLltnPt5WM-2.json

9001 avatar Feb 13 '24 21:02 9001