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 '='?
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 '='?