Log in

View Full Version : Issues calling youtube-dl in batch when video hash starts with '-'


LigH
28th March 2018, 19:16
Using youtube-dl to download music videos is quite reliable and flexible. A while ago I discovered how to select a combination of favorite A/V/C formats, so I thought of storing the call in a batch file and pasting the URL on it. That works ... usually. Except when the video hash in the URL starts with a '-' (dash/minus). And I have to blame half youtube-dl.exe and half cmd.exe in Windows 7 for now, until I know why...

Batch: youtube-best-mp4.bat
youtube-dl.exe -v -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4" "%1"


Examples:

>youtube-best-mp4 https://www.youtube.com/watch?v=KWZrgmVDnsc
works just as good as
>youtube-best-mp4 KWZrgmVDnsc

but

>youtube-best-mp4 -eL1y7wk5XU
youtube-dl.exe -v -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4" "-eL1y7wk5XU"
Usage: youtube-dl.exe [OPTIONS] URL [URL...]

youtube-dl.exe: error: no such option: -L

And when I enter it directly?

>youtube-dl.exe -v -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4" "-eL1y7wk5XU"
Usage: youtube-dl.exe [OPTIONS] URL [URL...]

youtube-dl.exe: error: no such option: -L

Not either.

Quoting the URL doesn't help, youtube-dl seems to try to interpret it as parameter anyway. Let's use the whole URL as this starts with a "h":

>youtube-best-mp4.bat https://www.youtube.com/watch?v=-eL1y7wk5XU
youtube-dl.exe -v -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4" "https://www.youtube.com/watch?v"


Eh, wait, there is the rest of the URL missing from the equal sign on.

Let's try it directly on the console without batch:

>youtube-dl.exe -v -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4" "https://www.youtube.com/watch?v=-eL1y7wk5XU"

Yep, that works.

I also tried to remove the double-quote from the %1 parameter in the batch and wrap it around the URL parameter in the call instead. That works as well – but makes the usage less convenient.

Can you imagine any syntax which allows me to pass only the hash even when it starts with a '-' (I suspect there is a quirk specifically for CPython), and possibly can even explain why the URL was split at the '='?

sneaker_ger
28th March 2018, 19:24
Doesn't work because = is a separator, like space. So second part is probably in %2.

Workaround:
https://youtu.be/-eL1y7wk5XU

LigH
28th March 2018, 19:32
Smart solution. Occasionally shows a "youtu.be html5 player bug", but calling it again works.

lvqcl
28th March 2018, 19:57
You can add -- before %1, like this:

youtube-dl.exe -v -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4" -- "%1"

sneaker_ger
28th March 2018, 19:58
The FAQ lists an alternative way if you still have problems.
How do I download a video starting with a -?
Either prepend https://www.youtube.com/watch?v= or separate the ID from the options with --:

youtube-dl -- -wNyEUrxzFU
youtube-dl "https://www.youtube.com/watch?v=-wNyEUrxzFU"
https://github.com/rg3/youtube-dl#how-do-i-download-a-video-starting-with-a--

Though I have no idea why the URL format should matter. Maybe it is just a coincidence.

/edit:
Ah, lvqcl was faster ..