0

I'm trying to create a batch program (here called pldl) to make downloading a playlist of songs with youtube-dl easier, the program is

youtube-dl -o "%(playlist_index)s. %(title)s.%(ext)s" -x --audio-format "mp3" %1

which is supposed to just take the first argument (%1) and add it to this long command, so running command_name "playlist_url" would download it in the location I ran it. Unfortunately, it throws an error instead (echo is on for debugging)

E:\Path\To\Music>pldl "https://www.youtube.com/playlist?list=PLSdoVPM5WnndV_AXWGXpzUsIw6fN1RQVN"

E:\Path\To\Music>youtube-dl -o "(title)s.1
Usage: youtube-dl [OPTIONS] URL [URL...]

youtube-dl: error: You must provide at least one URL.
Type youtube-dl --help to see a list of all options.

E:\Path\To\Music>

What's going on here? Why is the command not run properly as seen in the echo? Also is there possible a better way of doing this (tying a long command with argument to a short name) sorry for the low quality post just need this fast.

sagiksp
  • 143
  • 1
  • 7
  • Needing something fast is not an excuse for a low quality post! – YowE3K Aug 28 '17 at 20:55
  • I know, I really am sorry. I'm just new to batch and trying to get something up and running. Also english is not my first language so most of my effort went twoards making sure the grammar is correct and not the post quality, sorry. @YowE3K – sagiksp Aug 29 '17 at 09:14

1 Answers1

1

The script-parser tries to expand the variables:

%(playlist_index)s. %
%(ext)s" -x --audio-format "mp3" %

Which are likely undefined. Because there is nothing to expand, part of the command-line parameter is stripped before being passed to the youtube-dl program. Use double percent signs instead:

youtube-dl -o "%%(playlist_index)s. %%(title)s.%%(ext)s" -x --audio-format "mp3" "%~1"

Quoting and escaping

The percent sign (%) is a special case. On the command line, it does not need quoting or escaping unless two of them are used to indicate a variable, such as %OS%. But in a batch file, you have to use a double percent sign (%%) to yield a single percent sign (%). Enclosing the percent sign in quotation marks or preceding it with caret does not work.

303
  • 2,417
  • 1
  • 11
  • 25
  • Oh, Thanks. At first I thought escaping the precentages is done with a backslash (`\%`), and when that didn't work I was confused. – sagiksp Aug 28 '17 at 13:46