[HOWTO] download tweak when only using yt-CODE that starts with a "-"

Post tutorials, HOWTO's and other useful resources here.
User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

[HOWTO] download tweak when only using yt-CODE that starts with a "-"

Post#1 by Rava » 19 Oct 2022, 20:17

Maybe you are like me and prefer using only the youtøøbe code instead of the URL+CODE.

But on the rare occasion that Code starts with a "-" yt-dlp malfunctions.
As example I use the yt-code / video-code "-aQPecXRcdw"

Code: Select all

guest@porteus:/myvideo/gesundheit/LiebscherBracht$ yt-dlp -f 397+250 -aQPecXRcdw
ERROR: batch file QPecXRcdw could not be read
guest@porteus:/myvideo/gesundheit/LiebscherBracht$ yt-dlp -f 397+250 "-aQPecXRcdw"
ERROR: batch file QPecXRcdw could not be read
You have to use the "--" trick that signals "end of options, next are file names or URLs" like so:

Code: Select all

yt-dlp -f 397+250 -- "-aQPecXRcdw"
:)
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

[HOWTO] download tweak when only using yt-CODE that starts with a "-"

Post#2 by Rava » 05 Nov 2022, 06:24

Of course a more simple

Code: Select all

yt-dlp -f 397+250 -- -aQPecXRcdw
also works. :)


FYI, many core terminal utilities know of the special "--" parameter as well, not only yt-dlp.

E.g. you have files called "-silly-filename" and "--silly-filename2"

Code: Select all

guest@porteus:~$ cd /tmp
guest@porteus:/tmp$ touch -- -silly-filename --silly-filename2
Now trying to use ls to look at details fails:

Code: Select all

guest@porteus:/tmp$ ls -o -silly-filename --silly-filename2
/bin/ls: invalid option -- 'y'
Try '/bin/ls --help' for more information.
but adding -- at the right place succeeds:

Code: Select all

guest@porteus:/tmp$ ls -o -- -silly-filename --silly-filename2
-rw-r--r-- 1 guest 0 2022-11-05 07:26 --silly-filename2
-rw-r--r-- 1 guest 0 2022-11-05 07:26 -silly-filename
I looked into man ls and found no mention on option "--"

In short, option "--" means "end of options, rest is other parameters or filenames given to the program, but no program specific options"

Therefore

Code: Select all

ls -o -- -silly-filename
reads option "-o" filename "-silly-filename"
while

Code: Select all

ls -- -o  -silly-filename
reads "no options", filenames "-o" and "-silly-filename" which will fail for filename "-o":

Code: Select all

guest@porteus:/tmp$ ls -- -o  -silly-filename
/bin/ls: cannot access '-o': No such file or directory
-silly-filename
HTH.
Cheers!
Yours Rava

Post Reply