0

I have tried two separate scripts for scrapping all comments of a Youtube video. Everything works fine, but there was one problem:Youtube video ID's starting with a hiphen, like -FIHqoTcZog does not work. I was wondering is there a way to escape every single character of that ID from shell interpretation, for instance using as an ID: \-\F\I\H\q\o\T\c\Z\o\g, but this did not work in my case.

The scripts i used was : youtube-comment-downloader and youtube-comment-scraper. Both require video ID. Even if that is surrounded by single or double quotes the ID works, but neither works if the video ID starts with a hyphen.

Youtube-dl had similar issue before, but now it accepts ID starting with hyphen: this is done by using the option --id , still it does not work in our case unless the hyphen is preceded by --, making the video name into --id -- -FIHqoTcZog when it is ok to be --id xxxxxxxxxxx in another case where the ID does not start with a hyphen.

Is there any way arround for my scripts to work with ID starting with a hyphen, like the way how it did in the Youtube-dl's case, or using another work arround?

  • Does --id=-SoMeID work? – Kusalananda Mar 5 '18 at 14:34
  • @Kusalananda, that one is only a work around for Youtube-dl , and it is then for a hyphen starting ID: --id -- -xxxxxxxx, the two other scripts do not accept that form at all. – pigeon Mar 5 '18 at 14:44
  • Since this is getting sent to an HTTP server, what about replacing the hyphen with "%2D"? – ErikF Mar 5 '18 at 16:11
  • The --id option of youtube-dl doesn't do what you think: "Use only video ID in file name". That's why you still need to use --. – nxnev Mar 5 '18 at 20:21
2

Related question: What does “--” (double-dash) mean? (also known as “bare double dash”)


The hyphen character is not interpreted by your shell but by the program/script (its parser, more precisely) you are using. That's why escaping it (at the shell level) doesn't work.

Programs often recognize arguments with leading hyphen(s) as options, not as operands. To interpret arguments like -foo as operands, programs usually follow one or more of these ways:

  • Recognize the first -- argument as the end of options marker: program -- -foo
  • Let you pass operands as option-arguments: program --option -foo
  • Recognize operands in alternative ways: program prefix-foo

In your specific scenario:

  • youtube-dl accepts:
    • -- -FIHqoTcZog
    • https://www.youtube.com/watch?v=-FIHqoTcZog
  • youtube-comment-downloader seems to accept:
    • --youtubeid -FIHqoTcZog
  • youtube-comment-scraper seems to accept:
    • -- -FIHqoTcZog
    • https://www.youtube.com/watch?v=-FIHqoTcZog
0

Finally, i found one solution to the script youtube-comment-scraper after installing it again, suddenly , adding -- in front of a video ID starting with - worked. This hint is still not available in any of their documentation. Now this works: youtube-comment-scraper --output OtherFile -f csv -- -FIHqoTcZog

In the other script it still does not work yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.