so for the last couple days I've been trying to extract the value of a youtube dl command unfortunately with no success, I might be doing something wrong here's my code:
youtube-dl --get-filename -o "Download/%%(title)s.mp3" https://www.youtube.com/watch?v=dQw4w9WgXcQ
this code returns Download\Rick Astley - Never Gonna Give You Up (Video).mp3
I need to get this output into a variable, I have already tried with for /f
with no success, it gives this error:
WARNING: Falling back on generic information extractor. ERROR: Unsupported URL: https://www.youtube.com/
Edit: here's what I tried
for /f "delims=" %%a in ('youtube-dl --get-filename -o "Download/%%(title)s.mp3" https://www.youtube.com/watch?v=dQw4w9WgXcQ') do set "myvar=%%a"
echo %myvar%
You're fortunate, that the PC, I'm currently repairing has a copy of the youtube executable on it!
I therefore tested what I put in the comments, here's the results!
Your example, with an unquoted URL and no escape characters:
@For /F Delims^=^ EOL^= %%G In ('youtube-dl --get-filename -o "Download/%%(title)s.mp3" https://www.youtube.com/watch?v=dQw4w9WgXcQ') Do @Echo "%%~G"
Returns:
WARNING: Falling back on generic information extractor. ERROR: Unsupported URL: https://www.youtube.com/
I said, "Please try either doublequoting your URL":
@For /F Delims^=^ EOL^= %%G In ('youtube-dl --get-filename -o "Download/%%(title)s.mp3" "https://www.youtube.com/watch?v=dQw4w9WgXcQ"') Do @Echo "%%~G"
This returns:
"Download\Rick Astley - Never Gonna Give You Up (Video).mp3"
and, "or escaping the =
character with a caret, ^
"
@For /F Delims^=^ EOL^= %%G In ('youtube-dl --get-filename -o "Download\%%(title)s.mp3" https://www.youtube.com/watch?v^=dQw4w9WgXcQ') Do @Echo "%%~G"
Returns:
"Download\Rick Astley - Never Gonna Give You Up (Video).mp3"
It seems that my advice was absolutely correct for the issue you raised.
BTW, on the last example, because the path separator on Windows is \ not /, I changed Download/
to Download\